JAccess/getAssetRules

From Joomla! Documentation

Jump to: navigation, search

Contents

Description

Method to return the JRules object for an asset. The returned object can optionally hold only the rules explicitly set for the asset or the summation of all inherited rules from parent assets and explicit rules.

Syntax

static JAccess::getAssetRules($asset, $recursive=false)
Parameter Name Default Value Description
$asset Integer asset id or the name of the asset as a string.
$recursive false True to return the rules object with inherited rules.

Returns

object object for the asset.

Defined in

libraries/joomla/access/access.php

Importing

jimport( 'joomla.access.access' );

Source Body

        public static function getAssetRules($asset, $recursive = false)
        {
                // Get the database connection object.
                $db = JFactory::getDbo();
 
                // Build the database query to get the rules for the asset.
                $query  = new JQuery;
                $query->select($recursive ? 'b.rules' : 'a.rules');
                $query->from('#__assets AS a');
 
                // If the asset identifier is numeric assume it is a primary key, else lookup by name.
                if (is_numeric($asset)) {
                        $query->where('a.id = '.(int) $asset);
                }
                else {
                        $query->where('a.name = '.$db->quote($asset));
                }
 
                // If we want the rules cascading up to the global asset node we need a self-join.
                if ($recursive)
                {
                        $query->leftJoin('#__assets AS b ON b.lft <= a.lft AND b.rgt >= a.rgt');
                        $query->order('b.lft');
                }
 
                // Execute the query and load the rules from the result.
                $db->setQuery($query);
                $result = $db->loadResultArray();
 
                // Instantiate and return the JRules object for the asset rules.
                $rules  = new JRules;
                $rules->mergeCollection($result);
 
                return $rules;
        }
Personal tools