Actions

API16

JAccess/getAuthorisedViewLevels

From Joomla! Documentation

< API16:JAccess
Revision as of 17:34, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.

[Edit Descripton]

Description:JAccess/getAuthorisedViewLevels

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

[Edit See Also] SeeAlso:JAccess/getAuthorisedViewLevels

Examples

<CodeExamplesForm />