From 06e344b1cad7687361f334d168c23a365f017378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CSamadhan?= Date: Sat, 4 Nov 2017 19:16:12 +0530 Subject: [PATCH 1/5] New joomla user search API --- users/users.php | 43 ++++++---- users/users/user.php | 46 +++++++++++ users/users/userService.php | 151 ++++++++++++++++++++++++++++++++++++ 3 files changed, 227 insertions(+), 13 deletions(-) create mode 100644 users/users/user.php create mode 100644 users/users/userService.php diff --git a/users/users.php b/users/users.php index a46af06..ef7c761 100644 --- a/users/users.php +++ b/users/users.php @@ -1,29 +1,46 @@ - * @link http://www.techjoomla.com -*/ + * @version SVN: + * @package Users + * @author Techjoomla + * @copyright Copyright (c) 2009-2016 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 Users + * @subpackage component + * @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'); } diff --git a/users/users/user.php b/users/users/user.php new file mode 100644 index 0000000..8bd00ce --- /dev/null +++ b/users/users/user.php @@ -0,0 +1,46 @@ +set('reqBody', $requestBody); + + $model = JModelLegacy::getInstance('UsersSearch', 'UsersModel'); + + $data = $model->getItems(); + + $this->plugin->setResponse($data); + + return; + } +} diff --git a/users/users/userService.php b/users/users/userService.php new file mode 100644 index 0000000..35a80ae --- /dev/null +++ b/users/users/userService.php @@ -0,0 +1,151 @@ +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; + } +} From d7d82eda2be5b5c03384912740d556ca426e3cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CSamadhan?= Date: Mon, 6 Nov 2017 11:30:46 +0530 Subject: [PATCH 2/5] New joomla user search API - Changed copyright info --- users/users.php | 2 +- users/users/user.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/users/users.php b/users/users.php index ef7c761..626b68a 100644 --- a/users/users.php +++ b/users/users.php @@ -3,7 +3,7 @@ * @version SVN: * @package Users * @author Techjoomla - * @copyright Copyright (c) 2009-2016 TechJoomla. All rights reserved. + * @copyright Copyright (c) 2009-2017 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. */ diff --git a/users/users/user.php b/users/users/user.php index 8bd00ce..05b7a48 100644 --- a/users/users/user.php +++ b/users/users/user.php @@ -1,10 +1,10 @@ + * @package Users + * @author Techjoomla + * @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; From 425a764ef07adb4de47a0662e67090b2cba77f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CSamadhan?= Date: Mon, 6 Nov 2017 11:35:50 +0530 Subject: [PATCH 3/5] New joomla user search API - Changed copyright info --- users/users/config.php | 2 +- users/users/login.php | 2 +- users/users/userService.php | 10 +++++----- users/users/users.php | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/users/users/config.php b/users/users/config.php index 4614c7f..863d2f1 100644 --- a/users/users/config.php +++ b/users/users/config.php @@ -1,7 +1,7 @@ * @link http://www.techjoomla.com */ diff --git a/users/users/login.php b/users/users/login.php index 568f36f..5ab44b0 100644 --- a/users/users/login.php +++ b/users/users/login.php @@ -1,7 +1,7 @@ * @link http://www.techjoomla.com */ diff --git a/users/users/userService.php b/users/users/userService.php index 35a80ae..143266e 100644 --- a/users/users/userService.php +++ b/users/users/userService.php @@ -1,10 +1,10 @@ + * @package Users + * @author Techjoomla + * @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; diff --git a/users/users/users.php b/users/users/users.php index 9ed8a02..fa72c98 100644 --- a/users/users/users.php +++ b/users/users/users.php @@ -1,10 +1,10 @@ + * @package Users + * @author Techjoomla + * @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; From 84b223b3b40116e27288bbbee156b6ef417ddd92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CSamadhan?= Date: Mon, 6 Nov 2017 11:37:58 +0530 Subject: [PATCH 4/5] New joomla user search API - Changed copyright info --- users/users/config.php | 2 +- users/users/login.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/users/users/config.php b/users/users/config.php index 863d2f1..afe9643 100644 --- a/users/users/config.php +++ b/users/users/config.php @@ -1,7 +1,7 @@ * @link http://www.techjoomla.com */ diff --git a/users/users/login.php b/users/users/login.php index 5ab44b0..015ff1b 100644 --- a/users/users/login.php +++ b/users/users/login.php @@ -1,7 +1,7 @@ * @link http://www.techjoomla.com */ From 6dcf6a6290fd6f75dd7e64d2e881b789e4237766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CSamadhan?= Date: Mon, 6 Nov 2017 14:16:10 +0530 Subject: [PATCH 5/5] New joomla user search API - Changed copyright info --- users/users.php | 6 +++--- users/users/config.php | 2 +- users/users/login.php | 2 +- users/users/user.php | 6 +++--- users/users/userService.php | 6 +++--- users/users/users.php | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/users/users.php b/users/users.php index 626b68a..2d775d0 100644 --- a/users/users.php +++ b/users/users.php @@ -1,7 +1,7 @@ - * @package Users + * @package com_api.plugins * @author Techjoomla * @copyright Copyright (c) 2009-2017 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. @@ -14,8 +14,8 @@ /** * Base Class for api plugin * - * @package Users - * @subpackage component + * @package com_api.plugins + * @subpackage plugins * @since 1.0 */ diff --git a/users/users/config.php b/users/users/config.php index afe9643..e520fc7 100644 --- a/users/users/config.php +++ b/users/users/config.php @@ -1,6 +1,6 @@ * @link http://www.techjoomla.com diff --git a/users/users/login.php b/users/users/login.php index 015ff1b..0471183 100644 --- a/users/users/login.php +++ b/users/users/login.php @@ -1,6 +1,6 @@ * @link http://www.techjoomla.com diff --git a/users/users/user.php b/users/users/user.php index 05b7a48..8c3ebee 100644 --- a/users/users/user.php +++ b/users/users/user.php @@ -1,7 +1,7 @@ - * @package Users + * @package com_api.plugins * @author Techjoomla * @copyright Copyright (c) 2009-2017 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. @@ -14,8 +14,8 @@ /** * User Api. * - * @package Joomla.Administrator - * @subpackage com_api + * @package com_api.plugins + * @subpackage plugins * * @since 1.0 */ diff --git a/users/users/userService.php b/users/users/userService.php index 143266e..7142c2c 100644 --- a/users/users/userService.php +++ b/users/users/userService.php @@ -1,7 +1,7 @@ - * @package Users + * @package com_api.plugins * @author Techjoomla * @copyright Copyright (c) 2009-2017 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. @@ -14,8 +14,8 @@ /** * User Api. * - * @package Joomla.Administrator - * @subpackage com_api + * @package com_api.plugins + * @subpackage plugins * * @since 1.0 */ diff --git a/users/users/users.php b/users/users/users.php index fa72c98..8e75947 100644 --- a/users/users/users.php +++ b/users/users/users.php @@ -1,7 +1,7 @@ - * @package Users + * @package com_api.plugins * @author Techjoomla * @copyright Copyright (c) 2009-2017 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. @@ -27,8 +27,8 @@ /** * User Api. * - * @package Joomla.Administrator - * @subpackage com_api + * @package com_api.plugins + * @subpackage plugins * * @since 1.0 */