API16:JAccess/getAssetRules
From Joomla! Documentation
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.
<! removed transcluded page call, red link never existed >
Syntax
static 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 = $db->getQuery(true);
$query->select($recursive ? 'b.rules' : 'a.rules');
$query->from('#__assets AS a');
$query->group($recursive ? 'b.id' : 'a.id');
// If the asset identifier is numeric assume it is a primary key, else lookup by name.
if (is_numeric($asset)) {
// Get the root even if the asset is not found
$query->where('(a.id = '.(int) $asset.($recursive ? ' OR a.parent_id=0':'').')');
} else {
// Get the root even if the asset is not found
$query->where('(a.name = '.$db->quote($asset).($recursive ? ' OR a.parent_id=0':'').')');
}
// 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;
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples