Actions

API16

Difference between revisions of "JAccess/getAuthorisedViewLevels"

From Joomla! Documentation

< API16:JAccess
(New page: ===Description=== Method to return a list of view levels for which the user is authorised. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JAccess/ge...)
 
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/getAuthorisedViewLevels|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JAccess/getAuthorisedViewLevels}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 80: Line 80:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JAccess/getAuthorisedViewLevels|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JAccess/getAuthorisedViewLevels}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 95: Line 95:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Latest revision as of 20: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 view levels for which the user is authorised.

[<! removed edit link to red link >]

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

Syntax

static getAuthorisedViewLevels($userId)
Parameter Name Default Value Description
$userId Id of the user for which to get the list of authorised view levels.

Returns

array List of view levels for which the user is authorised.

Defined in

libraries/joomla/access/access.php

Importing

jimport( 'joomla.access.access' );

Source Body

public static function getAuthorisedViewLevels($userId)
{
        // Get all groups that the user is mapped to recursively.
        $groups = self::getGroupsByUser($userId);
 
        // Only load the view levels once.
        if (empty(self::$viewLevels)) {
                // Get a database object.
                $db     = JFactory::getDBO();
 
                // Build the base query.
                $query  = $db->getQuery(true);
                $query->select('id, rules');
                $query->from('`#__viewlevels`');
 
                // Set the query for execution.
                $db->setQuery((string) $query);
 
                // Build the view levels array.
                foreach ($db->loadAssocList() as $level) {
                        self::$viewLevels[$level['id']] = (array) json_decode($level['rules']);
                }
        }
 
        // Initialise the authorised array.
        $authorised = array(1);
 
        // Find the authorized levels.
        foreach (self::$viewLevels as $level => $rule) {
                foreach ($rule as $id) {
                        if (($id < 0) && (($id * -1) == $userId)) {
                                $authorised[] = $level;
                                break;
                        }
                        // Check to see if the group is mapped to the level.
                        elseif (($id >= 0) && in_array($id, $groups))
                        {
                                $authorised[] = $level;
                                break;
                        }
                }
        }
 
        return $authorised;
}

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

Examples

<CodeExamplesForm />