API16:JAccess/getUsersByGroup
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
Description
Method to return a list of user Ids contained in a Group
Description:JAccess/getUsersByGroup
Syntax
getUsersByGroup($groupId, $recursive=false)
| Parameter Name | Default Value | Description |
|---|---|---|
| $groupId | The group Id | |
| $recursive | false | Recursively include all child groups (optional) |
Returns
array
Defined in
libraries/joomla/access/access.php
Importing
jimport( 'joomla.access.access' );
Source Body
public function getUsersByGroup($groupId, $recursive = false) { // Get a database object. $db = JFactory::getDbo(); $test = $recursive ? '>=' : '='; // First find the users contained in the group $query = $db->getQuery(true); $query->select('DISTINCT(user_id)'); $query->from('#__usergroups as ug1'); $query->join('INNER','#__usergroups AS ug2 ON ug2.lft'.$test.'ug1.lft AND ug1.rgt'.$test.'ug2.rgt'); $query->join('INNER','#__user_usergroup_map AS m ON ug2.id=m.group_id'); $query->where('ug1.id='.$db->Quote($groupId)); $db->setQuery($query); $result = $db->loadResultArray(); // Clean up any NULL values, just in case JArrayHelper::toInteger($result); return $result; }
[Edit See Also] SeeAlso:JAccess/getUsersByGroup
Examples
<CodeExamplesForm />
