Source for file users.php
Documentation is available at users.php
* @package Joomla.Administrator
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Methods supporting a list of user records.
* @package Joomla.Administrator
* @param array $config An optional associative array of configuration settings.
if (empty($config['filter_fields']))
$config['filter_fields'] =
array(
'username', 'a.username',
'sendEmail', 'a.sendEmail',
'registerDate', 'a.registerDate',
'lastvisitDate', 'a.lastvisitDate',
'activation', 'a.activation',
* 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).
protected function populateState($ordering =
null, $direction =
null)
// Adjust the context to support modal layouts.
if ($layout =
$app->input->get('layout', 'default', 'cmd'))
// Load the filter state.
$this->setState('filter.search', $search);
$this->setState('filter.active', $active);
$this->setState('filter.state', $state);
$this->setState('filter.group_id', $groupId);
$this->setState('filter.range', $range);
$this->setState('filter.groups', $groups);
$this->setState('filter.excluded', $excluded);
// List state information.
* Method to get a store id based on model configuration state.
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* @param string $id A prefix for the store id.
* @return string A store id.
$id .=
':' .
$this->getState('filter.search');
$id .=
':' .
$this->getState('filter.active');
$id .=
':' .
$this->getState('filter.state');
$id .=
':' .
$this->getState('filter.group_id');
$id .=
':' .
$this->getState('filter.range');
* Gets the list of users and adds expensive joins to the result set.
* @return mixed An array of data items on success, false on failure.
// Try to load the data from internal storage.
if (empty($this->cache[$store]))
$groups =
$this->getState('filter.groups');
$groupId =
$this->getState('filter.group_id');
if (isset
($groups) &&
(empty($groups) ||
$groupId &&
!in_array($groupId, $groups)))
// Bail out on an error or empty list.
$this->cache[$store] =
$items;
// Joining the groups with the main query is a performance hog.
// Find the information only on the result set.
// First pass: get list of the user id's and reset the counts.
foreach ($items as $item)
$userIds[] = (int)
$item->id;
// Get the counts from the database only for the users in the list.
$query =
$db->getQuery(true);
// Join over the group mapping table.
$query->select('map.user_id, COUNT(map.group_id) AS group_count')
->from('#__user_usergroup_map AS map')
->where('map.user_id IN (' .
implode(',', $userIds) .
')')
// Join over the user groups table.
->join('LEFT', '#__usergroups AS g2 ON g2.id = map.group_id');
// Load the counts into an array indexed on the user id field.
$userGroups =
$db->loadObjectList('user_id');
catch
(RuntimeException $e)
->select('n.user_id, COUNT(n.id) As note_count')
->from('#__user_notes AS n')
->where('n.user_id IN (' .
implode(',', $userIds) .
')')
// Load the counts into an array indexed on the aro.value field (the user id).
$userNotes =
$db->loadObjectList('user_id');
catch
(RuntimeException $e)
// Second pass: collect the group counts into the master items array.
foreach ($items as &$item)
if (isset
($userGroups[$item->id]))
$item->group_count =
$userGroups[$item->id]->group_count;
// Group_concat in other databases is not supported
if (isset
($userNotes[$item->id]))
$item->note_count =
$userNotes[$item->id]->note_count;
// Add the items to the internal cache.
$this->cache[$store] =
$items;
return $this->cache[$store];
* Build an SQL query to load the list data.
// Create a new query object.
$query =
$db->getQuery(true);
// Select the required fields from the table.
$query->from($db->quoteName('#__users') .
' AS a');
// If the model is set to check item state, add to the query.
$state =
$this->getState('filter.state');
$query->where('a.block = ' . (int)
$state);
// If the model is set to check the activated state, add to the query.
$active =
$this->getState('filter.active');
$query->where('a.activation = ' .
$db->quote(''));
$query->where($query->length('a.activation') .
' = 32');
// Filter the items over the group id if set.
$groupId =
$this->getState('filter.group_id');
$groups =
$this->getState('filter.groups');
if ($groupId || isset
($groups))
$query->join('LEFT', '#__user_usergroup_map AS map2 ON map2.user_id = a.id')
->group($db->quoteName(array('a.id', 'a.name', 'a.username', 'a.password', 'a.block', 'a.sendEmail', 'a.registerDate', 'a.lastvisitDate', 'a.activation', 'a.params', 'a.email')));
$query->where('map2.group_id = ' . (int)
$groupId);
$query->where('map2.group_id IN (' .
implode(',', $groups) .
')');
// Filter the items over the search string if set.
if ($this->getState('filter.search') !==
'' &&
$this->getState('filter.search') !==
null)
// Escape the search token.
$token =
$db->quote('%' .
$db->escape($this->getState('filter.search')) .
'%');
// Compile the different search clauses.
$searches[] =
'a.name LIKE ' .
$token;
$searches[] =
'a.username LIKE ' .
$token;
$searches[] =
'a.email LIKE ' .
$token;
// Add the clauses to the query.
$query->where('(' .
implode(' OR ', $searches) .
')');
// Add filter for registration ranges select list
$range =
$this->getState('filter.range');
// Apply the range filter.
$dStart->modify('-7 day');
$dStart->modify('-1 month');
$dStart->modify('-3 month');
$dStart->modify('-6 month');
$dStart->modify('-1 year');
// Ranges that need to align with local 'days' need special treatment.
$offset =
$app->getCfg('offset');
// Reset the start time to be the beginning of today, local time.
$dStart =
new JDate('now', $offset);
$dStart->setTime(0, 0, 0);
// Now change the timezone back to UTC.
$tz =
new DateTimeZone('GMT');
$dStart->setTimezone($tz);
if ($range ==
'post_year')
'a.registerDate < ' .
$db->quote($dStart->format('Y-m-d H:i:s'))
'a.registerDate >= ' .
$db->quote($dStart->format('Y-m-d H:i:s')) .
' AND a.registerDate <=' .
$db->quote($dNow->format('Y-m-d H:i:s'))
// Filter by excluded users
$excluded =
$this->getState('filter.excluded');
$query->where('id NOT IN (' .
implode(',', $excluded) .
')');
// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering', 'a.name')) .
' ' .
$db->escape($this->getState('list.direction', 'ASC')));
* @param integer $user_id User identifier
* @return string Groups titles imploded :$
$query =
"SELECT title FROM " .
$db->quoteName('#__usergroups') .
" ug left join " .
$db->quoteName('#__user_usergroup_map') .
" map on (ug.id = map.group_id)" .
" WHERE map.user_id=" . (int)
$user_id;
$result =
$db->loadColumn();
Documentation generated on Tue, 19 Nov 2013 15:16:39 +0100 by phpDocumentor 1.4.3