-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4.0] Feature: Adding User(s) Model + View to front-end #25030
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
72c02c2
Adding User(s) models + views to front-end
pe7er 8915bec
fixed language string
pe7er 60fa75d
fixed language string COM_USERS_USERS_GROUP_VIEW_DEFAULT_DESC
pe7er 313dcdc
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into a…
pe7er ac4d027
code cleanup
pe7er 582263f
changed class chzn-color to custom-select-color
pe7er 7103b3b
changed all __deploy_version__ tags to uppercase
pe7er eac4d47
Merge branch '4.0-dev' into adding-user-model-to-front-end
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 hidden or 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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -43,8 +43,10 @@ COM_USERS_RESET_VIEW_DEFAULT_DESC="Displays a request to reset password." | |||||
| COM_USERS_RESET_VIEW_DEFAULT_OPTION="Default" | ||||||
| COM_USERS_RESET_VIEW_DEFAULT_TITLE="Password Reset" | ||||||
| COM_USERS_TAGS_CATEGORY="User Note Category" | ||||||
| COM_USERS_USERS_VIEW_DEFAULT_DESC="Shows a List of Users" | ||||||
| COM_USERS_USERS_VIEW_DEFAULT_TITLE="Users" | ||||||
| COM_USERS_USER_VIEW_EDIT_DESC="Shows a form to create a new User Account" | ||||||
| COM_USERS_USER_VIEW_EDIT_TITLE="Create User" | ||||||
| COM_USERS_USERS_VIEW_DEFAULT_DESC="Shows a List of Users" | ||||||
| COM_USERS_USERS_VIEW_DEFAULT_TITLE="Users" | ||||||
| COM_USERS_USERS_GROUP_VIEW_DEFAULT="List Users" | ||||||
| COM_USERS_USERS_GROUP_VIEW_DEFAULT_DESC="Displays a list of Users of a Group." | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| COM_USERS_XML_DESCRIPTION="Component for managing users." | ||||||
This file contains hidden or 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 hidden or 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,63 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Site | ||
| * @subpackage com_users | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\Component\Users\Site\Model; | ||
|
|
||
| defined('_JEXEC') or die; | ||
|
|
||
| use Exception; | ||
| use Joomla\CMS\MVC\Model\ItemModel; | ||
| use Joomla\Database\ParameterType; | ||
|
|
||
| /** | ||
| * This models retrieves some data of a User. | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| class UserModel extends ItemModel | ||
| { | ||
| /** | ||
| * Load the User data. | ||
| * | ||
| * @param integer $id ID of User | ||
| * | ||
| * @return object The product information. | ||
| * @throws Exception | ||
pe7er marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function getItem($id = null) | ||
| { | ||
| $db = $this->getDbo(); | ||
| $query = $db->getQuery(true) | ||
| ->select( | ||
| $db->quoteName( | ||
| array( | ||
| 'users.id', | ||
| 'users.name', | ||
| 'users.username', | ||
| 'users.email', | ||
| 'users.registerDate', | ||
| 'users.lastvisitDate' | ||
| ) | ||
| ) | ||
| ) | ||
| ->from($db->quoteName('#__users', 'users')) | ||
| ->where($db->quoteName('users.block') . ' = 0') | ||
| ->where($db->quoteName('users.id') . ' = :user_id') | ||
| ->leftJoin( | ||
| $db->quoteName('#__session', 'session') | ||
| . ' ON ' . $db->quoteName('session.userid') . ' = ' . $db->quoteName('users.id') | ||
| ) | ||
| ->bind(':user_id', $id, ParameterType::INTEGER); | ||
| $db->setQuery($query); | ||
| $item = $db->loadObject(); | ||
|
|
||
| return $item; | ||
| } | ||
| } | ||
This file contains hidden or 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,196 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Site | ||
| * @subpackage com_users | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\Component\Users\Site\Model; | ||
|
|
||
| defined('_JEXEC') or die; | ||
|
|
||
| use Exception; | ||
| use Joomla\CMS\Component\ComponentHelper; | ||
| use Joomla\CMS\Factory; | ||
| use Joomla\CMS\MVC\Model\ListModel; | ||
| use Joomla\Database\ParameterType; | ||
| use Joomla\Utilities\ArrayHelper; | ||
|
|
||
| /** | ||
| * This models supports retrieving a list of users. | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| class UsersModel extends ListModel | ||
| { | ||
| /** | ||
| * User items data | ||
| * | ||
| * @var array | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected $item = null; | ||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
| * @param array $config An optional associative array of configuration settings. | ||
| * | ||
| * @throws Exception | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function __construct($config = array()) | ||
| { | ||
| if (empty($config['filter_fields'])) | ||
| { | ||
| $config['filter_fields'] = array( | ||
| 'id', 'users.id', | ||
| 'name', 'users.name', | ||
| 'username', 'users.username', | ||
| 'email', 'users.email', | ||
| 'registerDate', 'users.registerDate', | ||
| 'lastvisitDate', 'users.lastvisitDate', | ||
| 'session.time' | ||
| ); | ||
| } | ||
|
|
||
| parent::__construct($config); | ||
| } | ||
|
|
||
| /** | ||
| * Method to get a list of items. | ||
| * | ||
| * @return mixed An array of objects on success, false on failure. | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function getItems() | ||
| { | ||
| // Invoke the parent getItems method to get the main list | ||
| $items = parent::getItems(); | ||
|
|
||
| return $items; | ||
| } | ||
|
|
||
| /** | ||
| * Method to build an SQL query to load the list data. | ||
| * | ||
| * @return string An SQL query | ||
| * @throws Exception | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected function getListQuery() | ||
| { | ||
| $app = Factory::getApplication(); | ||
| $menu = $app->getMenu(); | ||
| $active = $menu->getActive(); | ||
| $itemId = $active->id; | ||
| $menuParams = $menu->getParams($itemId); | ||
| $groupIds = $menuParams->get('groups', 0, 'array'); | ||
|
|
||
| $db = $this->getDbo(); | ||
| $query = $db->getQuery(true); | ||
|
|
||
| // Select the required fields from the table. | ||
| $query->select( | ||
| $this->getState( | ||
| 'list.select', | ||
| $db->quoteName( | ||
| array( | ||
| 'users.id', | ||
| 'users.name', | ||
| 'users.username', | ||
| 'users.email', | ||
| 'users.registerDate', | ||
| 'users.lastvisitDate' | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ->from($db->quoteName('#__users', 'users')) | ||
| ->leftJoin( | ||
| $db->quoteName('#__user_usergroup_map', 'usergroupmap') | ||
| . ' ON ' . $db->quoteName('usergroupmap.user_id') . ' = ' . $db->quoteName('users.id') | ||
| ) | ||
| ->leftJoin( | ||
| $db->quoteName('#__session', 'session') | ||
| . ' ON ' . $db->quoteName('session.userid') . ' = ' . $db->quoteName('users.id') | ||
| ) | ||
| ->select($db->quoteName('session.time')) | ||
| ->where($db->quoteName('users.block') . ' = 0') | ||
| ->group($db->quoteName('users.id')) | ||
| ->order( | ||
| $this->getState('list.ordering', 'users.name') . ' ' . | ||
| $this->getState('list.direction', 'ASC') | ||
| ); | ||
|
|
||
| if (is_numeric($groupIds)) | ||
| { | ||
| $query->where($db->quoteName('usergroupmap.group_id') . ' = :group_id') | ||
| ->bind(':group_id', $groupIds, ParameterType::INTEGER); | ||
| } | ||
| elseif (is_array($groupIds) && (count($groupIds) > 0)) | ||
| { | ||
| $groupIds = ArrayHelper::toInteger($groupIds); | ||
|
|
||
| $query->whereIn( | ||
| $db->quoteName('usergroupmap.group_id'), $groupIds | ||
| ); | ||
| } | ||
|
|
||
| // Add the list ordering clause | ||
| $query->order( | ||
| $this->getState('list.ordering', 'users.name') . ' ' | ||
| . $this->getState('list.direction', 'ASC') | ||
| ); | ||
|
|
||
| return $query; | ||
| } | ||
|
|
||
| /** | ||
| * Method to auto-populate the model state. | ||
| * | ||
| * Note. Calling getState in this method will result in recursion. | ||
| * | ||
| * @param string $ordering An optional ordering field. | ||
| * @param string $direction An optional direction (asc|desc). | ||
| * | ||
| * @return void | ||
| * @throws Exception | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected function populateState($ordering = null, $direction = null) | ||
| { | ||
| $app = Factory::getApplication(); | ||
| $params = ComponentHelper::getParams('com_users'); | ||
|
|
||
| // List state information | ||
| $value = $app->input->get('limit', $app->get('list_limit', 0), 'uint'); | ||
| $this->setState('list.limit', $value); | ||
|
|
||
| $value = $app->input->get('limitstart', 0, 'uint'); | ||
| $this->setState('list.start', $value); | ||
|
|
||
| $orderCol = $app->input->get('filter_order', 'users.name'); | ||
|
|
||
| if (!in_array($orderCol, $this->filter_fields)) | ||
| { | ||
| $orderCol = 'users.id'; | ||
| } | ||
|
|
||
| $this->setState('list.ordering', $orderCol); | ||
|
|
||
| $listOrder = $app->input->get('filter_order_Dir', 'ASC'); | ||
|
|
||
| if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) | ||
| { | ||
| $listOrder = 'ASC'; | ||
| } | ||
|
|
||
| $this->setState('list.direction', $listOrder); | ||
|
|
||
| // Load the parameters. | ||
| $this->setState('params', $params); | ||
| } | ||
| } |
This file contains hidden or 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,68 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Site | ||
| * @subpackage com_users | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\Component\Users\Site\View\User; | ||
|
|
||
| defined('_JEXEC') or die; | ||
|
|
||
| use Exception; | ||
| use Joomla\CMS\Factory; | ||
| use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; | ||
| use Joomla\Component\Users\Site\Model\UserModel; | ||
|
|
||
| /** | ||
| * View class for Single User | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| class HtmlView extends BaseHtmlView | ||
| { | ||
| /** | ||
| * The User data | ||
| * | ||
| * @var object | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected $item; | ||
|
|
||
| /** | ||
| * The model state | ||
| * | ||
| * @var Joomla\Registry\Registry | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected $state; | ||
|
|
||
| /** | ||
| * Method to display the view. | ||
| * | ||
| * @param string $tpl The template file to include | ||
| * | ||
| * @return void | ||
| * @throws Exception | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function display($tpl = null) | ||
| { | ||
| $authorId = Factory::getApplication()->input->getInt('id'); | ||
|
|
||
| /** @var UserModel $model */ | ||
| $model = $this->getModel(); | ||
| $this->state = $model->getState(); | ||
| $this->item = $model->getItem($authorId); | ||
|
|
||
| // Check for errors. | ||
| if (count($errors = $this->get('Errors'))) | ||
| { | ||
| throw new Exception(implode("\n", $errors), 500); | ||
| } | ||
|
|
||
| parent::display($tpl); | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.