Actions

API16

Difference between revisions of "JAccess/getAssetRules"

From Joomla! Documentation

< API16:JAccess
(New page: ===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 ru...)
 
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/getAssetRules|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JAccess/getAssetRules}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 75: Line 75:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JAccess/getAssetRules|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JAccess/getAssetRules}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 90: Line 90:
 
  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 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 edit link to red link >]

<! 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 edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />