API16

JAccess/getUsersByGroup

< API16:JAccess

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description

Method to return a list of user Ids contained in a Group


<! removed transcluded page call, red link never existed >

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;
}


<! removed transcluded page call, red link never existed >

Examples

Code Examples


Advertisement