Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
Référence de la classe JAccess

Liste de tous les membres

Fonctions membres publiques statiques

static clearStatics ()
static check ($userId, $action, $asset=null)
static checkGroup ($groupId, $action, $asset=null)
static getAssetRules ($asset, $recursive=false)
static getGroupsByUser ($userId, $recursive=true)
static getUsersByGroup ($groupId, $recursive=false)
static getAuthorisedViewLevels ($userId)
static getActions ($component, $section= 'component')
static getActionsFromFile ($file, $xpath="/access/section[@name='component']/")
static getActionsFromData ($data, $xpath="/access/section[@name='component']/")

Fonctions membres protégées statiques

static getGroupPath ($groupId)

Attributs protégés statiques

static $viewLevels = array()
static $assetRules = array()
static $userGroups = array()
static $userGroupPaths = array()
static $groupsByUser = array()

Description détaillée

Définition à la ligne 21 du fichier access.php.


Documentation des fonctions membres

static JAccess::check (   $userId,
  $action,
  $asset = null 
)
static

Method to check if a user is authorised to perform an action, optionally on an asset.

Paramètres:
integer$userIdId of the user for which to check authorisation.
string$actionThe name of the action to authorise.
mixed$assetInteger asset id or the name of the asset as a string. Defaults to the global asset node.
Renvoie:
boolean True if authorised.
Depuis:
11.1

Définition à la ligne 90 du fichier access.php.

Références JFactory\getDbo(), et JTable\getInstance().

Référencé par JUser\authorise(), et JUser\save().

{
// Sanitise inputs.
$userId = (int) $userId;
$action = strtolower(preg_replace('#[\s\-]+#', '.', trim($action)));
$asset = strtolower(preg_replace('#[\s\-]+#', '.', trim($asset)));
// Default to the root asset node.
if (empty($asset))
{
$assets = JTable::getInstance('Asset', 'JTable', array('dbo' => $db));
$rootId = $assets->getRootId();
$asset = $rootId;
}
// Get the rules for the asset recursively to root if not already retrieved.
if (empty(self::$assetRules[$asset]))
{
self::$assetRules[$asset] = self::getAssetRules($asset, true);
}
// Get all groups against which the user is mapped.
$identities = self::getGroupsByUser($userId);
array_unshift($identities, $userId * -1);
return self::$assetRules[$asset]->allow($action, $identities);
}

+ Voici le graphe d'appel pour cette fonction :

+ Voici le graphe des appelants de cette fonction :

static JAccess::checkGroup (   $groupId,
  $action,
  $asset = null 
)
static

Method to check if a group is authorised to perform an action, optionally on an asset.

Paramètres:
integer$groupIdThe path to the group for which to check authorisation.
string$actionThe name of the action to authorise.
mixed$assetInteger asset id or the name of the asset as a string. Defaults to the global asset node.
Renvoie:
boolean True if authorised.
Depuis:
11.1

Définition à la ligne 131 du fichier access.php.

Références JFactory\getDbo(), et JTable\getInstance().

Référencé par JFormFieldRules\getInput(), et JUser\save().

{
// Sanitize inputs.
$groupId = (int) $groupId;
$action = strtolower(preg_replace('#[\s\-]+#', '.', trim($action)));
$asset = strtolower(preg_replace('#[\s\-]+#', '.', trim($asset)));
// Get group path for group
$groupPath = self::getGroupPath($groupId);
// Default to the root asset node.
if (empty($asset))
{
// TODO: $rootId doesn't seem to be used!
$assets = JTable::getInstance('Asset', 'JTable', array('dbo' => $db));
$rootId = $assets->getRootId();
}
// Get the rules for the asset recursively to root if not already retrieved.
if (empty(self::$assetRules[$asset]))
{
self::$assetRules[$asset] = self::getAssetRules($asset, true);
}
return self::$assetRules[$asset]->allow($action, $groupPath);
}

+ Voici le graphe d'appel pour cette fonction :

+ Voici le graphe des appelants de cette fonction :

static JAccess::clearStatics ( )
static

Method for clearing static caches.

Renvoie:
void
Depuis:
11.3

Définition à la ligne 70 du fichier access.php.

{
self::$viewLevels = array();
self::$assetRules = array();
self::$userGroups = array();
self::$userGroupPaths = array();
self::$groupsByUser = array();
}
static JAccess::getActions (   $component,
  $section = 'component' 
)
static

Method to return a list of actions for which permissions can be set given a component and section.

Paramètres:
string$componentThe component from which to retrieve the actions.
string$sectionThe name of the section within the component from which to retrieve the actions.
Renvoie:
array List of actions available for the given component and section.
Depuis:
11.1
Obsolète:
12.3 (Platform) & 4.0 (CMS) Use JAccess::getActionsFromFile or JAccess::getActionsFromData instead.

Définition à la ligne 465 du fichier access.php.

Références JLog\add(), et JLog\WARNING.

Référencé par JFormRuleRules\getFieldActions(), et JFormFieldRules\getInput().

{
JLog::add(__METHOD__ . ' is deprecated. Use JAccess::getActionsFromFile or JAccess::getActionsFromData instead.', JLog::WARNING, 'deprecated');
JPATH_ADMINISTRATOR . '/components/' . $component . '/access.xml',
"/access/section[@name='" . $section . "']/"
);
if (empty($actions))
{
return array();
}
else
{
return $actions;
}
}

+ Voici le graphe d'appel pour cette fonction :

+ Voici le graphe des appelants de cette fonction :

static JAccess::getActionsFromData (   $data,
  $xpath = "/access/section[@name='component']/" 
)
static

Method to return a list of actions from a string or from an xml for which permissions can be set.

Paramètres:
string | SimpleXMLElement$dataThe XML string or an XML element.
string$xpathAn optional xpath to search for the fields.
Renvoie:
boolean|array False if case of error or the list of actions available.
Depuis:
12.1

Définition à la ligne 520 du fichier access.php.

{
// If the data to load isn't already an XML element or string return false.
if ((!($data instanceof SimpleXMLElement)) && (!is_string($data)))
{
return false;
}
// Attempt to load the XML if a string.
if (is_string($data))
{
try
{
$data = new SimpleXMLElement($data);
}
catch (Exception $e)
{
return false;
}
// Make sure the XML loaded correctly.
if (!$data)
{
return false;
}
}
// Initialise the actions array
$actions = array();
// Get the elements from the xpath
$elements = $data->xpath($xpath . 'action[@name][@title][@description]');
// If there some elements, analyse them
if (!empty($elements))
{
foreach ($elements as $action)
{
// Add the action to the actions array
$actions[] = (object) array(
'name' => (string) $action['name'],
'title' => (string) $action['title'],
'description' => (string) $action['description']
);
}
}
// Finally return the actions array
return $actions;
}
static JAccess::getActionsFromFile (   $file,
  $xpath = "/access/section[@name='component']/" 
)
static

Method to return a list of actions from a file for which permissions can be set.

Paramètres:
string$fileThe path to the XML file.
string$xpathAn optional xpath to search for the fields.
Renvoie:
boolean|array False if case of error or the list of actions available.
Depuis:
12.1

Définition à la ligne 494 du fichier access.php.

{
if (!is_file($file) || !is_readable($file))
{
// If unable to find the file return false.
return false;
}
else
{
// Else return the actions from the xml.
$xml = simplexml_load_file($file);
return self::getActionsFromData($xml, $xpath);
}
}
static JAccess::getAssetRules (   $asset,
  $recursive = false 
)
static

Method to return the JAccessRules 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.

Paramètres:
mixed$assetInteger asset id or the name of the asset as a string.
boolean$recursiveTrue to return the rules object with inherited rules.
Renvoie:
JAccessRules JAccessRules object for the asset.
Depuis:
11.1

Définition à la ligne 218 du fichier access.php.

Références JFactory\getDbo(), JTable\getInstance(), et JAccessRules\mergeCollection().

Référencé par JUser\authorise(), et JFormFieldRules\getInput().

{
// Get the database connection object.
// Build the database query to get the rules for the asset.
$query = $db->getQuery(true)
->select($recursive ? 'b.rules' : 'a.rules')
->from('#__assets AS a');
// SQLsrv change
$query->group($recursive ? 'b.id, b.rules, b.lft' : 'a.id, a.rules, a.lft');
// 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->join('LEFT', '#__assets AS b ON b.lft <= a.lft AND b.rgt >= a.rgt')
->order('b.lft');
}
// Execute the query and load the rules from the result.
$db->setQuery($query);
$result = $db->loadColumn();
// Get the root even if the asset is not found and in recursive mode
if (empty($result))
{
$assets = JTable::getInstance('Asset', 'JTable', array('dbo' => $db));
$rootId = $assets->getRootId();
$query->clear()
->select('rules')
->from('#__assets')
->where('id = ' . $db->quote($rootId));
$db->setQuery($query);
$result = $db->loadResult();
$result = array($result);
}
// Instantiate and return the JAccessRules object for the asset rules.
$rules = new JAccessRules;
$rules->mergeCollection($result);
return $rules;
}

+ Voici le graphe d'appel pour cette fonction :

+ Voici le graphe des appelants de cette fonction :

static JAccess::getAuthorisedViewLevels (   $userId)
static

Method to return a list of view levels for which the user is authorised.

Paramètres:
integer$userIdId of the user for which to get the list of authorised view levels.
Renvoie:
array List of view levels for which the user is authorised.
Depuis:
11.1

Définition à la ligne 402 du fichier access.php.

Références JFactory\getDbo().

Référencé par JUser\getAuthorisedViewLevels().

{
// 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.
// Build the base query.
$query = $db->getQuery(true)
->select('id, rules')
->from($db->quoteName('#__viewlevels'));
// Set the query for execution.
$db->setQuery($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 authorised 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;
}

+ Voici le graphe d'appel pour cette fonction :

+ Voici le graphe des appelants de cette fonction :

static JAccess::getGroupPath (   $groupId)
staticprotected

Gets the parent groups that a leaf group belongs to in its branch back to the root of the tree (including the leaf group id).

Paramètres:
mixed$groupIdAn integer or array of integers representing the identities to check.
Renvoie:
mixed True if allowed, false for an explicit deny, null for an implicit deny.
Depuis:
11.1

Définition à la ligne 169 du fichier access.php.

Références JFactory\getDbo().

{
// Preload all groups
if (empty(self::$userGroups))
{
$query = $db->getQuery(true)
->select('parent.id, parent.lft, parent.rgt')
->from('#__usergroups AS parent')
->order('parent.lft');
$db->setQuery($query);
self::$userGroups = $db->loadObjectList('id');
}
// Make sure groupId is valid
if (!array_key_exists($groupId, self::$userGroups))
{
return array();
}
// Get parent groups and leaf group
if (!isset(self::$userGroupPaths[$groupId]))
{
self::$userGroupPaths[$groupId] = array();
foreach (self::$userGroups as $group)
{
if ($group->lft <= self::$userGroups[$groupId]->lft && $group->rgt >= self::$userGroups[$groupId]->rgt)
{
self::$userGroupPaths[$groupId][] = $group->id;
}
}
}
return self::$userGroupPaths[$groupId];
}

+ Voici le graphe d'appel pour cette fonction :

static JAccess::getGroupsByUser (   $userId,
  $recursive = true 
)
static

Method to return a list of user groups mapped to a user. The returned list can optionally hold only the groups explicitly mapped to the user or all groups both explicitly mapped and inherited by the user.

Paramètres:
integer$userIdId of the user for which to get the list of groups.
boolean$recursiveTrue to include inherited user groups.
Renvoie:
array List of user group ids to which the user is mapped.
Depuis:
11.1

Définition à la ligne 285 du fichier access.php.

Références JFactory\getDbo(), et JArrayHelper\toInteger().

Référencé par JUser\getAuthorisedGroups().

{
// Creates a simple unique string for each parameter combination:
$storeId = $userId . ':' . (int) $recursive;
if (!isset(self::$groupsByUser[$storeId]))
{
// TODO: Uncouple this from JComponentHelper and allow for a configuration setting or value injection.
if (class_exists('JComponentHelper'))
{
$guestUsergroup = JComponentHelper::getParams('com_users')->get('guest_usergroup', 1);
}
else
{
$guestUsergroup = 1;
}
// Guest user (if only the actually assigned group is requested)
if (empty($userId) && !$recursive)
{
$result = array($guestUsergroup);
}
// Registered user and guest if all groups are requested
else
{
// Build the database query to get the rules for the asset.
$query = $db->getQuery(true)
->select($recursive ? 'b.id' : 'a.id');
if (empty($userId))
{
$query->from('#__usergroups AS a')
->where('a.id = ' . (int) $guestUsergroup);
}
else
{
$query->from('#__user_usergroup_map AS map')
->where('map.user_id = ' . (int) $userId)
->join('LEFT', '#__usergroups AS a ON a.id = map.group_id');
}
// If we want the rules cascading up to the global asset node we need a self-join.
if ($recursive)
{
$query->join('LEFT', '#__usergroups AS b ON b.lft <= a.lft AND b.rgt >= a.rgt');
}
// Execute the query and load the rules from the result.
$db->setQuery($query);
$result = $db->loadColumn();
// Clean up any NULL or duplicate values, just in case
if (empty($result))
{
$result = array('1');
}
else
{
$result = array_unique($result);
}
}
self::$groupsByUser[$storeId] = $result;
}
return self::$groupsByUser[$storeId];
}

+ Voici le graphe d'appel pour cette fonction :

+ Voici le graphe des appelants de cette fonction :

static JAccess::getUsersByGroup (   $groupId,
  $recursive = false 
)
static

Method to return a list of user Ids contained in a Group

Paramètres:
integer$groupIdThe group Id
boolean$recursiveRecursively include all child groups (optional)
Renvoie:
array
Depuis:
11.1
A faire:
This method should move somewhere else

Définition à la ligne 368 du fichier access.php.

Références JFactory\getDbo(), et JArrayHelper\toInteger().

{
// Get a database object.
$test = $recursive ? '>=' : '=';
// First find the users contained in the group
$query = $db->getQuery(true)
->select('DISTINCT(user_id)')
->from('#__usergroups as ug1')
->join('INNER', '#__usergroups AS ug2 ON ug2.lft' . $test . 'ug1.lft AND ug1.rgt' . $test . 'ug2.rgt')
->join('INNER', '#__user_usergroup_map AS m ON ug2.id=m.group_id')
->where('ug1.id=' . $db->quote($groupId));
$db->setQuery($query);
$result = $db->loadColumn();
// Clean up any NULL values, just in case
return $result;
}

+ Voici le graphe d'appel pour cette fonction :


Documentation des données membres

JAccess::$assetRules = array()
staticprotected

Définition à la ligne 37 du fichier access.php.

JAccess::$groupsByUser = array()
staticprotected

Définition à la ligne 61 du fichier access.php.

JAccess::$userGroupPaths = array()
staticprotected

Définition à la ligne 53 du fichier access.php.

JAccess::$userGroups = array()
staticprotected

Définition à la ligne 45 du fichier access.php.

JAccess::$viewLevels = array()
staticprotected

Définition à la ligne 29 du fichier access.php.


La documentation de cette classe a été générée à partir du fichier suivant :