Access
Class that handles all access authorisation routines.
| since |
1.7.0 |
|---|---|
| package |
Joomla CMS |
Methods
check
Method to check if a user is authorised to perform an action, optionally on an asset.
check(int userId, string action, int|string assetKey = null, bool preload = true) : bool|null
| since |
1.7.0 |
|---|
Arguments
- userId
intId of the user for which to check authorisation.- action
stringThe name of the action to authorise.- assetKey
int|stringThe asset key (asset id or asset name). null fallback to root asset.- preload
boolIndicates whether preloading should be used.
Response
bool|nullTrue if allowed, false for an explicit deny, null for an implicit deny.
checkGroup
Method to check if a group is authorised to perform an action, optionally on an asset.
checkGroup(int groupId, string action, int|string assetKey = null, bool preload = true) : bool
| since |
1.7.0 |
|---|
Arguments
- groupId
intThe path to the group for which to check authorisation.- action
stringThe name of the action to authorise.- assetKey
int|stringThe asset key (asset id or asset name). null fallback to root asset.- preload
boolIndicates whether preloading should be used.
Response
boolTrue if authorised.
cleanAssetKey
Method to clean the asset key to make sure we always have something.
cleanAssetKey(int|string assetKey = null) : int|string
| since |
3.7.0 |
|---|
Arguments
- assetKey
int|stringThe asset key (asset id or asset name). null fallback to root asset.
Response
int|stringAsset id or asset name.
clearStatics
Method for clearing static caches.
clearStatics() : void
| since |
1.7.3 |
|---|
getActions
Method to return a list of actions for which permissions can be set given a component and section.
getActions(string component, string section = 'component') : array
| since |
1.7.0 |
|---|---|
| deprecated |
4.0 Use Access::getActionsFromFile or Access::getActionsFromData instead. |
Arguments
- component
stringThe component from which to retrieve the actions.- section
stringThe name of the section within the component from which to retrieve the actions.
Response
arrayList of actions available for the given component and section.
getActionsFromData
Method to return a list of actions from a string or from an xml for which permissions can be set.
getActionsFromData(string|\SimpleXMLElement data, string xpath = "/access/section[@name='component']/") : bool|array
| since |
3.0.0 |
|---|
Arguments
- data
string|\SimpleXMLElementThe XML string or an XML element.- xpath
stringAn optional xpath to search for the fields.
Response
bool|arrayFalse if case of error or the list of actions available.
getActionsFromFile
Method to return a list of actions from a file for which permissions can be set.
getActionsFromFile(string file, string xpath = "/access/section[@name='component']/") : bool|array
| since |
3.0.0 |
|---|
Arguments
- file
stringThe path to the XML file.- xpath
stringAn optional xpath to search for the fields.
Response
bool|arrayFalse if case of error or the list of actions available.
getAssetAncestors
Method to recursively retrieve the list of parent Asset IDs for a particular Asset.
getAssetAncestors(string assetType, int assetId) : array
| since |
1.6 |
|---|
Arguments
- assetType
stringThe asset type, or the asset name, or the extension of the asset (e.g. 'com_content.article', 'com_menus.menu.2', 'com_contact').- assetId
intThe numeric asset id.
Response
arrayList of ancestor ids (includes original $assetId).
getAssetId
Method to get the asset id from the asset key.
getAssetId(int|string assetKey) : int
| since |
3.7.0 |
|---|
Arguments
- assetKey
int|stringThe asset key (asset id or asset name).
Response
intThe asset id.
getAssetName
Method to get the asset name from the asset key.
getAssetName(int|string assetKey) : string
| since |
3.7.0 |
|---|
Arguments
- assetKey
int|stringThe asset key (asset id or asset name).
Response
stringThe asset name (ex: com_content.article.8).
getAssetRules
Method to return the Rules 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.
getAssetRules(int|string assetKey, bool recursive = false, bool recursiveParentAsset = true, bool preload = true) : \Joomla\CMS\Access\Rules
| since |
1.7.0 |
|---|---|
| note |
The non preloading code will be removed in 4.0. All asset rules should use asset preloading. |
Arguments
- assetKey
int|stringThe asset key (asset id or asset name). null fallback to root asset.- recursive
boolTrue to return the rules object with inherited rules.- recursiveParentAsset
boolTrue to calculate the rule also based on inherited component/extension rules.- preload
boolIndicates whether preloading should be used.
Response
\Joomla\CMS\Access\RulesRules object for the asset.
getAssetType
Method to get the asset type from the asset name.
getAssetType(int|string assetKey) : string
For top level components this returns "components": 'com_content' returns 'components'
For other types: 'com_content.article.1' returns 'com_content.article' 'com_content.category.1' returns 'com_content.category'
| since |
1.6 |
|---|
Arguments
- assetKey
int|stringThe asset key (asset id or asset name).
Response
stringThe asset type (ex: com_content.article).
getAuthorisedViewLevels
Method to return a list of view levels for which the user is authorised.
getAuthorisedViewLevels(int userId) : array
| since |
1.7.0 |
|---|
Arguments
- userId
intId of the user for which to get the list of authorised view levels.
Response
arrayList of view levels for which the user is authorised.
getExtensionNameFromAsset
Method to get the extension name from the asset name.
getExtensionNameFromAsset(int|string assetKey) : string
| since |
1.6 |
|---|
Arguments
- assetKey
int|stringThe asset key (asset id or asset name).
Response
stringThe extension name (ex: com_content).
getGroupPath
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).
getGroupPath(mixed groupId) : mixed
| since |
1.7.0 |
|---|
Arguments
- groupId
mixedAn integer or array of integers representing the identities to check.
Response
mixedTrue if allowed, false for an explicit deny, null for an implicit deny.
getGroupsByUser
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.
getGroupsByUser(int userId, bool recursive = true) : array
| since |
1.7.0 |
|---|
Arguments
- userId
intId of the user for which to get the list of groups.- recursive
boolTrue to include inherited user groups.
Response
arrayList of user group ids to which the user is mapped.
getGroupTitle
Method to return the title of a user group
getGroupTitle(int groupId) : string
| since |
3.5 |
|---|
Arguments
- groupId
intId of the group for which to get the title of.
Response
stringThe title of the group
getUsersByGroup
Method to return a list of user Ids contained in a Group
getUsersByGroup(int groupId, bool recursive = false) : array
| since |
1.7.0 |
|---|---|
| todo |
This method should move somewhere else |
Arguments
- groupId
intThe group Id- recursive
boolRecursively include all child groups (optional)
Response
array
preload
Method to preload the Rules object for the given asset type.
preload(int|string|array assetTypes = 'components', bool reload = false) : bool
| since |
1.6 |
|---|---|
| note |
This method will return void in 4.0. |
Arguments
- assetTypes
int|string|arrayThe type or name of the asset (e.g. 'com_content.article', 'com_menus.menu.2'). Also accepts the asset id. An array of asset type or a special 'components' string to load all component assets.- reload
boolSet to true to reload from database.
Response
boolTrue on success.
preloadComponents
Method to preload the Rules objects for all components.
preloadComponents() : array
Note: This will only get the base permissions for the component. e.g. it will get 'com_content', but not 'com_content.article.1' or any more specific asset type rules.
| since |
1.6 |
|---|
Response
arrayArray of component names that were preloaded.
preloadPermissions
Method to retrieve the Asset Rule strings for this particular Asset Type and stores them for later usage in getAssetRules().
preloadPermissions(string assetType, bool reload = false) : bool
Stores 2 arrays: one where the list has the Asset ID as the key and a second one where the Asset Name is the key.
| since |
1.6 |
|---|---|
| note |
This function will return void in 4.0. |
Arguments
- assetType
stringThe asset type, or the asset name, or the extension of the asset (e.g. 'com_content.article', 'com_menus.menu.2', 'com_contact').- reload
boolReload the preloaded assets.
Response
boolTrue
preloadPermissionsParentIdMapping
Method to retrieve the list of Asset IDs and their Parent Asset IDs and store them for later usage in getAssetRules().
preloadPermissionsParentIdMapping(string assetType) : array
| since |
1.6 |
|---|---|
| deprecated |
3.7.0 No replacement. Will be removed in 4.0. |
Arguments
- assetType
stringThe asset type, or the asset name, or the extension of the asset (e.g. 'com_content.article', 'com_menus.menu.2', 'com_contact').
Response
arrayList of asset ids (includes parent asset id information).
Properties
viewLevels
Array of view levels
| since |
1.7.0 |
|---|
Type(s)
array
assetRules
Array of rules for the asset
| since |
1.7.0 |
|---|
Type(s)
array
assetRulesIdentities
Array of identities for asset rules
| since |
1.7.0 |
|---|
Type(s)
array
assetPermissionsById
Array of permissions for an asset type (Array Key = Asset ID) Also includes the rules string for the asset
| since |
1.7.0 |
|---|---|
| deprecated |
3.7.0 No replacement. Will be removed in 4.0. |
Type(s)
array
assetPermissionsByName
Array of permissions for an asset type (Array Key = Asset Name)
| since |
1.7.0 |
|---|---|
| deprecated |
3.7.0 No replacement. Will be removed in 4.0. |
Type(s)
array
assetPermissionsParentIdMapping
Array of the permission parent ID mappings
| since |
1.7.0 |
|---|
Type(s)
array
preloadedAssetTypes
Array of asset types that have been preloaded
| since |
1.7.0 |
|---|
Type(s)
array
identities
Array of loaded user identities
| since |
1.7.0 |
|---|
Type(s)
array
userGroups
Array of user groups.
| since |
1.7.0 |
|---|
Type(s)
array
userGroupPaths
Array of user group paths.
| since |
1.7.0 |
|---|
Type(s)
array
groupsByUser
Array of cached groups by user.
| since |
1.7.0 |
|---|
Type(s)
array
preloadedAssets
Array of preloaded asset names and ids (key is the asset id).
| since |
3.7.0 |
|---|
Type(s)
array
rootAssetId
The root asset id.
| since |
3.7.0 |
|---|
Type(s)
int