Source for file groups.php
Documentation is available at groups.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 group records.
* @package Joomla.Administrator
* @param array An optional associative array of configuration settings.
if (empty($config['filter_fields']))
$config['filter_fields'] =
array(
'parent_id', 'a.parent_id',
* Method to auto-populate the model state.
* Note. Calling getState in this method will result in recursion.
protected function populateState($ordering =
null, $direction =
null)
// Load the filter state.
$this->setState('filter.search', $search);
// 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.search');
* Gets the list of groups 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]))
// Bail out on an error or empty list.
$this->cache[$store] =
$items;
// First pass: get list of the group id's and reset the counts.
foreach ($items as $item)
$groupIds[] = (int)
$item->id;
// Get the counts from the database only for the users in the list.
$query =
$db->getQuery(true);
// Count the objects in the user group.
$query->select('map.group_id, COUNT(DISTINCT map.user_id) AS user_count')
->from($db->quoteName('#__user_usergroup_map') .
' AS map')
->where('map.group_id IN (' .
implode(',', $groupIds) .
')')
// Load the counts into an array indexed on the user id field.
$users =
$db->loadObjectList('group_id');
catch
(RuntimeException $e)
// Second pass: collect the group counts into the master items array.
foreach ($items as &$item)
if (isset
($users[$item->id]))
$item->user_count =
$users[$item->id]->user_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('#__usergroups') .
' AS a');
// Add the level in the tree.
$query->select('COUNT(DISTINCT c2.id) AS level')
->join('LEFT OUTER', $db->quoteName('#__usergroups') .
' AS c2 ON a.lft > c2.lft AND a.rgt < c2.rgt')
->group('a.id, a.lft, a.rgt, a.parent_id, a.title');
// Filter the comments over the search string if set.
$search =
$this->getState('filter.search');
$query->where('a.id = ' . (int)
substr($search, 3));
$search =
$db->quote('%' .
$db->escape($search, true) .
'%');
$query->where('a.title LIKE ' .
$search);
// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering', 'a.lft')) .
' ' .
$db->escape($this->getState('list.direction', 'ASC')));
//echo nl2br(str_replace('#__','jos_',$query));
Documentation generated on Tue, 19 Nov 2013 15:04:11 +0100 by phpDocumentor 1.4.3