Actions

API16

Difference between revisions of "JAccess/getGroupsByUser"

From Joomla! Documentation

< API16:JAccess
(New page: ===Description=== Method to return a list of user groups mapped to a user. The returned list can optionally hold only the groups explicitly mapped to the user or all groups both explicitl...)
 
m (removing red link to edit, no existant pages)
 
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JAccess/getGroupsByUser|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JAccess/getGroupsByUser}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 70: Line 70:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JAccess/getGroupsByUser|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JAccess/getGroupsByUser}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 85: Line 85:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Latest revision as of 19:56, 12 May 2013

Replacement filing cabinet.png
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 groups mapped to a user. The returned list can optionally hold only the groups explicitly mapped to the user or all groups both explicitly mapped and inherited by the user.

[<! removed edit link to red link >]

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

Syntax

static getGroupsByUser($userId, $recursive=true)
Parameter Name Default Value Description
$userId Id of the user for which to get the list of groups.
$recursive true True to include inherited user groups.

Returns

array List of user group ids to which the user is mapped.

Defined in

libraries/joomla/access/access.php

Importing

jimport( 'joomla.access.access' );

Source Body

public static function getGroupsByUser($userId, $recursive = true)
{
        // Get the database connection object.
        $db = JFactory::getDbo();
 
        // Build the database query to get the rules for the asset.
        $query  = $db->getQuery(true);
        $query->select($recursive ? 'b.id' : 'a.id');
        $query->from('#__user_usergroup_map AS map');
        $query->where('map.user_id = '.(int) $userId);
        $query->leftJoin('#__usergroups AS a ON a.id = map.group_id');
 
        // If we want the rules cascading up to the global asset node we need a self-join.
        if ($recursive) {
                $query->leftJoin('#__usergroups AS b ON b.lft <= a.lft AND b.rgt >= a.rgt');
        }
 
        // Execute the query and load the rules from the result.
        $db->setQuery($query);
        $result = $db->loadResultArray();
 
        // Clean up any NULL or duplicate values, just in case
        JArrayHelper::toInteger($result);
        if (empty($result)) {
                $result = array('1');
        } else {
                $result = array_unique($result);
        }
 
        return $result;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />