-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New joomla user search API #66
Open
samadhansalunkhe
wants to merge
5
commits into
techjoomla:master
Choose a base branch
from
samadhansalunkhe:joomla-user-search-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
06e344b
New joomla user search API
samadhansalunkhe d7d82ed
New joomla user search API - Changed copyright info
samadhansalunkhe 425a764
New joomla user search API - Changed copyright info
samadhansalunkhe 84b223b
New joomla user search API - Changed copyright info
samadhansalunkhe 6dcf6a6
New joomla user search API - Changed copyright info
samadhansalunkhe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,46 @@ | ||
<?php | ||
/** | ||
* @package API plugins | ||
* @copyright Copyright (C) 2009 2014 Techjoomla, Tekdi Technologies Pvt. Ltd. All rights reserved. | ||
* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html> | ||
* @link http://www.techjoomla.com | ||
*/ | ||
* @version SVN: <svn_id> | ||
* @package com_api.plugins | ||
* @author Techjoomla <[email protected]> | ||
* @copyright Copyright (c) 2009-2017 TechJoomla. All rights reserved. | ||
* @license GNU General Public License version 2 or later. | ||
*/ | ||
|
||
defined('_JEXEC') or die( 'Restricted access' ); | ||
|
||
jimport('joomla.plugin.plugin'); | ||
|
||
class plgAPIUsers extends ApiPlugin | ||
/** | ||
* Base Class for api plugin | ||
* | ||
* @package com_api.plugins | ||
* @subpackage plugins | ||
* @since 1.0 | ||
*/ | ||
|
||
class PlgAPIUsers extends ApiPlugin | ||
{ | ||
/** | ||
* Users api plugin to load com_api classes | ||
* | ||
* @param string &$subject originalamount | ||
* @param array $config coupon_code | ||
* | ||
* @since 1.0 | ||
*/ | ||
public function __construct(&$subject, $config = array()) | ||
{ | ||
parent::__construct($subject, $config = array()); | ||
|
||
ApiResource::addIncludePath(dirname(__FILE__).'/users'); | ||
/*load language file for plugin frontend*/ | ||
$lang = JFactory::getLanguage(); | ||
$lang->load('plg_api_users', JPATH_ADMINISTRATOR,'',true); | ||
ApiResource::addIncludePath(dirname(__FILE__) . '/users'); | ||
|
||
/*load language file for plugin frontend*/ | ||
$lang = JFactory::getLanguage(); | ||
$lang->load('plg_api_users', JPATH_ADMINISTRATOR, '', true); | ||
|
||
// Set the login resource to be public | ||
$this->setResourceAccess('login', 'public','get'); | ||
$this->setResourceAccess('login', 'public', 'get'); | ||
$this->setResourceAccess('users', 'public', 'post'); | ||
$this->setResourceAccess('config', 'public', 'get'); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* @version SVN: <svn_id> | ||
* @package com_api.plugins | ||
* @author Techjoomla <[email protected]> | ||
* @copyright Copyright (c) 2009-2017 TechJoomla. All rights reserved. | ||
* @license GNU General Public License version 2 or later. | ||
*/ | ||
// No direct access. | ||
defined('_JEXEC') or die; | ||
|
||
require JPATH_SITE . '/plugins/api/users/users/userService.php'; | ||
|
||
/** | ||
* User Api. | ||
* | ||
* @package com_api.plugins | ||
* @subpackage plugins | ||
* | ||
* @since 1.0 | ||
*/ | ||
|
||
class UsersApiResourceUser extends ApiResource | ||
{ | ||
/** | ||
* Function post for create user record. | ||
* | ||
* @return void | ||
*/ | ||
public function post() | ||
{ | ||
// Get request body | ||
$requestBody = file_get_contents('php://input'); | ||
|
||
$app = JFactory::getApplication(); | ||
$app->set('reqBody', $requestBody); | ||
|
||
$model = JModelLegacy::getInstance('UsersSearch', 'UsersModel'); | ||
|
||
$data = $model->getItems(); | ||
|
||
$this->plugin->setResponse($data); | ||
|
||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
/** | ||
* @version SVN: <svn_id> | ||
* @package com_api.plugins | ||
* @author Techjoomla <[email protected]> | ||
* @copyright Copyright (c) 2009-2017 TechJoomla. All rights reserved. | ||
* @license GNU General Public License version 2 or later. | ||
*/ | ||
// No direct access. | ||
defined('_JEXEC') or die; | ||
|
||
require_once JPATH_ROOT . '/administrator/components/com_users/models/users.php'; | ||
|
||
/** | ||
* User Api. | ||
* | ||
* @package com_api.plugins | ||
* @subpackage plugins | ||
* | ||
* @since 1.0 | ||
*/ | ||
class UsersModelUsersSearch extends UsersModelUsers | ||
{ | ||
/** | ||
* Build an SQL query to load the list data. | ||
* | ||
* @return JDatabaseQuery | ||
* | ||
* @since 1.6 | ||
*/ | ||
public function getListQuery() | ||
{ | ||
$app = JFactory::getApplication(); | ||
$getReqBody = json_decode($app->get('reqBody')); | ||
|
||
$db = JFactory::getDbo(); | ||
|
||
$query = $db->getQuery(true); | ||
|
||
// Select the required fields from the table. | ||
$query->select( | ||
$this->getState( | ||
'list.select', | ||
'a.id, a.name, a.username, a.email, a.registerDate' | ||
) | ||
); | ||
|
||
$query->from($db->quoteName('#__users') . ' AS a'); | ||
|
||
// Check user search filter | ||
$search = isset($getReqBody->request->search) ? $getReqBody->request->search : false; | ||
|
||
if (!empty($search)) | ||
{ | ||
$search = ('%' . str_replace(' ', '%', trim($search) . '%')); | ||
|
||
$query->where($db->quoteName('a.name') . ' LIKE ' . $db->quote($search)); | ||
} | ||
|
||
// Check user block filter | ||
$block = isset($getReqBody->request->filters->block) ? (array) $getReqBody->request->filters->block : array(); | ||
|
||
if (!empty($block)) | ||
{ | ||
foreach ($block as &$blockValue) | ||
{ | ||
$blockValue = 'a.block = ' . (int) $blockValue; | ||
} | ||
|
||
$query->where('(' . implode(' OR ', $block) . ')'); | ||
} | ||
|
||
// Check user id filter | ||
$userIds = isset($getReqBody->request->filters->id) ? (array) $getReqBody->request->filters->id : array(); | ||
|
||
if (!empty($userIds)) | ||
{ | ||
foreach ($userIds as &$userId) | ||
{ | ||
$userId = 'a.id = ' . (int) $userId; | ||
} | ||
|
||
$query->where('(' . implode(' OR ', $userIds) . ')'); | ||
} | ||
|
||
// Check user email filter | ||
$userEmails = isset($getReqBody->request->filters->email) ? (array) $getReqBody->request->filters->email : array(); | ||
|
||
if (!empty($userEmails)) | ||
{ | ||
foreach ($userEmails as &$userEmail) | ||
{ | ||
$userEmail = 'a.email = ' . $db->quote($userEmail); | ||
} | ||
|
||
$query->where('(' . implode(' OR ', $userEmails) . ')'); | ||
} | ||
|
||
// Check user username filter | ||
$usernames = isset($getReqBody->request->filters->username) ? (array) $getReqBody->request->filters->username : array(); | ||
|
||
if (!empty($usernames)) | ||
{ | ||
foreach ($usernames as &$username) | ||
{ | ||
$username = 'a.username = ' . $db->quote($username); | ||
} | ||
|
||
$query->where('(' . implode(' OR ', $usernames) . ')'); | ||
} | ||
|
||
// Check list ordering filter | ||
if (isset($getReqBody->request->sort_by->name)) | ||
{ | ||
$orderColumn = 'name'; | ||
$ordering = $getReqBody->request->sort_by->name; | ||
} | ||
elseif (isset($getReqBody->request->sort_by->id)) | ||
{ | ||
$orderColumn = 'id'; | ||
$ordering = $getReqBody->request->sort_by->id; | ||
} | ||
elseif (isset($getReqBody->request->sort_by->email)) | ||
{ | ||
$orderColumn = 'email'; | ||
$ordering = $getReqBody->request->sort_by->email; | ||
} | ||
elseif (isset($getReqBody->request->sort_by->username)) | ||
{ | ||
$orderColumn = 'username'; | ||
$ordering = $getReqBody->request->sort_by->username; | ||
} | ||
else | ||
{ | ||
$ordering = array(); | ||
} | ||
|
||
if (!empty($ordering)) | ||
{ | ||
$query->order('a.' . $orderColumn . ' ' . $ordering); | ||
} | ||
|
||
// Check offset & limit filter | ||
$offset = isset($getReqBody->request->offset) ? $getReqBody->request->offset : array(); | ||
$limit = isset($getReqBody->request->limit) ? $getReqBody->request->limit : array(); | ||
|
||
$query->setLimit((int) $limit, (int) $offset); | ||
|
||
return $query; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_trading | ||
* | ||
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
* @version SVN: <svn_id> | ||
* @package com_api.plugins | ||
* @author Techjoomla <[email protected]> | ||
* @copyright Copyright (c) 2009-2017 TechJoomla. All rights reserved. | ||
* @license GNU General Public License version 2 or later. | ||
*/ | ||
// No direct access. | ||
defined('_JEXEC') or die; | ||
|
@@ -27,8 +27,8 @@ | |
/** | ||
* User Api. | ||
* | ||
* @package Joomla.Administrator | ||
* @subpackage com_api | ||
* @package com_api.plugins | ||
* @subpackage plugins | ||
* | ||
* @since 1.0 | ||
*/ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coolbung should resource name be search?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think search API is nothing but the list view with the additional filters. Can we merge this code with users post API? cc @coolbung
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Please go ahead as discussed.
Once merged, moved out the plugins in the respective repos. Any plugin that does not have a specific repo can stay here.