diff --git a/users/users.php b/users/users.php index a46af06..2d775d0 100644 --- a/users/users.php +++ b/users/users.php @@ -1,29 +1,46 @@ - * @link http://www.techjoomla.com -*/ + * @version SVN: + * @package com_api.plugins + * @author Techjoomla + * @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'); } diff --git a/users/users/config.php b/users/users/config.php index 4614c7f..e520fc7 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..0471183 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/user.php b/users/users/user.php new file mode 100644 index 0000000..8c3ebee --- /dev/null +++ b/users/users/user.php @@ -0,0 +1,46 @@ + + * @package com_api.plugins + * @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; + +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; + } +} diff --git a/users/users/userService.php b/users/users/userService.php new file mode 100644 index 0000000..7142c2c --- /dev/null +++ b/users/users/userService.php @@ -0,0 +1,151 @@ + + * @package com_api.plugins + * @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; + +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; + } +} diff --git a/users/users/users.php b/users/users/users.php index 9ed8a02..8e75947 100644 --- a/users/users/users.php +++ b/users/users/users.php @@ -1,10 +1,10 @@ + * @package com_api.plugins + * @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; @@ -27,8 +27,8 @@ /** * User Api. * - * @package Joomla.Administrator - * @subpackage com_api + * @package com_api.plugins + * @subpackage plugins * * @since 1.0 */