PHP Class PermissionModel, vanilla

Inheritance: extends Model
Exibir arquivo Open project: vanilla/vanilla Class Usage Examples

Protected Properties

Property Type Description
$DefaultPermissions Default role permissions.
$RowDefaults Default row permission values.
$_PermissionColumns Permission columns.

Public Methods

Method Description
__construct ( ) Class constructor. Defines the related database table name.
addDefault ( string $Type, array $Permissions, null | string $Junction = null, null | integer $JunctionId = null ) Add an entry into the list of default permissions.
addPermissions ( array $perms1, array $perms2 ) : array Add the permissions from one permission array to another.
assignDefaults ( boolean $ResetDefaults = false ) Populate a list of default permissions, per type.
cachePermissions ( null $UserID = null, null $RoleID = null ) : array | null
clearPermissions ( ) Remove the cached permissions for all users.
define ( array $PermissionNames, string $Type = 'tinyint', string? $JunctionTable = null, string? $JunctionColumn = null ) Define one or more permissions with default values.
delete ( null $RoleID = null, null $JunctionTable = null, null $JunctionColumn = null, null $JunctionID = null )
getAllowedPermissionNamespaces ( ) : array Returns a complete list of all enabled applications & plugins. This list can act as a namespace list for permissions.
getDefaults ( ) : array Grab the list of default permissions by role type
getGlobalPermissions ( integer | array $RoleID, string $LimitToSuffix = '' ) : Returns Get all of the global permissions for one or more roles.
getJunctionPermissions ( $Where, null $JunctionTable = null, string $LimitToSuffix = '', array $Options = [] ) : array
getPermissions ( integer | array $RoleID, string $LimitToSuffix = '', boolean $includeJunction = true ) : array Returns all defined permissions not related to junction tables. Excludes permissions related to applications & plugins that are disabled.
getPermissionsByRole ( integer $roleID ) : array Get the permissions for one or more roles.
getPermissionsEdit ( $RoleID, string $LimitToSuffix = '', boolean $includeJunction = true ) : array
getRolePermissions ( integer $RoleID, string $LimitToSuffix = '', string $JunctionTable = false, string $JunctionColumn = false, string $ForeignKey = false, integer $ForeignID = false ) : array Get the permissions of a role.
getRowDefaults ( ) : array Grab default permission column values.
getUserPermissions ( integer $UserID, string $LimitToSuffix = '', string $JunctionTable = false, string $JunctionColumn = false, string $ForeignKey = false, integer $ForeignID = false ) : array Get the permissions of a user.
permissionColumns ( boolean $JunctionTable = false, boolean $JunctionColumn = false ) : mixed Get all of the permission columns in the system.
permissionNamespace ( $PermissionName ) : string
pivotPermissions ( $Data, null $Overrides = null ) : array
resetAllRoles ( string $Type = null ) Reset permissions for all roles, based on the value in their Type column.
resetRole ( integer $RoleId ) Reset permissions for a role, based on the value in its Type column.
sQLPermission ( Gdn_SQLDriver $SQL, mixed $Permissions, string $ForeignAlias, string $ForeignColumn, string $JunctionTable = '', string $JunctionColumn = '' ) Joins the query to a permission junction table and limits the results accordingly.
save ( array $Values, boolean $SaveGlobal = false ) Save a permission row.
saveAll ( $Permissions, null $AllWhere = null )
splitPermission ( string $PermissionName ) : array Split a permission name into its constituant parts.
stripPermissions ( $Row, $DefaultRow, string $LimitToSuffix = '' ) : mixed Take a permission row and strip the global/local permissions from it.
undefine ( $Names )
unpivotPermissions ( $Permissions, boolean $IncludeRole = false ) : array

Protected Methods

Method Description
_Backtick ( $Values ) : array
_MergeDisabledPermissions ( array &$GlobalPermissions ) : void Merge junction permissions with global permissions if they are disabled.
_UnpivotPermissionsRow ( $Row, &$Result, boolean $IncludeRole = false )
isGlobalPermission ( $Value, $PermissionName, $LimitToSuffix, $Namespaces ) : boolean Returns whether or not a permission is a global permission.

Method Details

_Backtick() protected method

protected _Backtick ( $Values ) : array
$Values
return array

_MergeDisabledPermissions() protected method

Merge junction permissions with global permissions if they are disabled.
protected _MergeDisabledPermissions ( array &$GlobalPermissions ) : void
$GlobalPermissions array
return void

_UnpivotPermissionsRow() protected method

protected _UnpivotPermissionsRow ( $Row, &$Result, boolean $IncludeRole = false )
$Row
$Result
$IncludeRole boolean

__construct() public method

Class constructor. Defines the related database table name.
public __construct ( )

addDefault() public method

Add an entry into the list of default permissions.
public addDefault ( string $Type, array $Permissions, null | string $Junction = null, null | integer $JunctionId = null )
$Type string Type of role the permissions should be added for.
$Permissions array The list of permissions to include.
$Junction null | string Type of junction to base the permission on.
$JunctionId null | integer Identifier for the specific junction record to base the permission on.

addPermissions() public static method

Add the permissions from one permission array to another.
public static addPermissions ( array $perms1, array $perms2 ) : array
$perms1 array The permissions to be added to.
$perms2 array The permissions to add.
return array Returns an array with all of the permissions in both permissions arrays.

assignDefaults() public method

Populate a list of default permissions, per type.
public assignDefaults ( boolean $ResetDefaults = false )
$ResetDefaults boolean If we already have defaults, should they be discarded?

cachePermissions() public method

public cachePermissions ( null $UserID = null, null $RoleID = null ) : array | null
$UserID null
$RoleID null
return array | null

clearPermissions() public method

Remove the cached permissions for all users.
public clearPermissions ( )

define() public method

Define one or more permissions with default values.
public define ( array $PermissionNames, string $Type = 'tinyint', string? $JunctionTable = null, string? $JunctionColumn = null )
$PermissionNames array
$Type string
$JunctionTable string?
$JunctionColumn string?

delete() public method

public delete ( null $RoleID = null, null $JunctionTable = null, null $JunctionColumn = null, null $JunctionID = null )
$RoleID null
$JunctionTable null
$JunctionColumn null
$JunctionID null

getAllowedPermissionNamespaces() public method

Returns a complete list of all enabled applications & plugins. This list can act as a namespace list for permissions.

getDefaults() public method

Grab the list of default permissions by role type
public getDefaults ( ) : array
return array List of permissions, grouped by role type

getGlobalPermissions() public method

Get all of the global permissions for one or more roles.
public getGlobalPermissions ( integer | array $RoleID, string $LimitToSuffix = '' ) : Returns
$RoleID integer | array The role(s) to get the permissions for.
$LimitToSuffix string Whether or not to limit the permissions to a suffix.
return Returns an

getJunctionPermissions() public method

public getJunctionPermissions ( $Where, null $JunctionTable = null, string $LimitToSuffix = '', array $Options = [] ) : array
$Where
$JunctionTable null
$LimitToSuffix string
$Options array
return array

getPermissions() public method

Returns all defined permissions not related to junction tables. Excludes permissions related to applications & plugins that are disabled.
public getPermissions ( integer | array $RoleID, string $LimitToSuffix = '', boolean $includeJunction = true ) : array
$RoleID integer | array The role(s) to get the permissions for.
$LimitToSuffix string An optional suffix to limit the permission names to.
$includeJunction boolean
return array

getPermissionsByRole() public method

Get the permissions for one or more roles.
public getPermissionsByRole ( integer $roleID ) : array
$roleID integer The role to get the permissions for.
return array Returns a permission array suitable for use in a session.

getPermissionsEdit() public method

public getPermissionsEdit ( $RoleID, string $LimitToSuffix = '', boolean $includeJunction = true ) : array
$RoleID
$LimitToSuffix string
$includeJunction boolean
return array

getRolePermissions() public method

If no junction table is specified, will return ONLY non-junction permissions. If you need every permission regardless of junction & suffix, see CachePermissions.
public getRolePermissions ( integer $RoleID, string $LimitToSuffix = '', string $JunctionTable = false, string $JunctionColumn = false, string $ForeignKey = false, integer $ForeignID = false ) : array
$RoleID integer Unique identifier for role.
$LimitToSuffix string String permission name must match, starting on right (ex: 'View' would match *.*.View)
$JunctionTable string Optionally limit returned permissions to 1 junction (ex: 'Category').
$JunctionColumn string Column to join junction table on (ex: 'CategoryID'). Required if using $JunctionTable.
$ForeignKey string Foreign table column to join on.
$ForeignID integer Foreign ID to limit join to.
return array Permission records.

getRowDefaults() public method

Grab default permission column values.
public getRowDefaults ( ) : array
return array A list of default permission values.

getUserPermissions() public method

If no junction table is specified, will return ONLY non-junction permissions. If you need every permission regardless of junction & suffix, see CachePermissions.
public getUserPermissions ( integer $UserID, string $LimitToSuffix = '', string $JunctionTable = false, string $JunctionColumn = false, string $ForeignKey = false, integer $ForeignID = false ) : array
$UserID integer Unique identifier for user.
$LimitToSuffix string String permission name must match, starting on right (ex: 'View' would match *.*.View)
$JunctionTable string Optionally limit returned permissions to 1 junction (ex: 'Category').
$JunctionColumn string Column to join junction table on (ex: 'CategoryID'). Required if using $JunctionTable.
$ForeignKey string Foreign table column to join on.
$ForeignID integer Foreign ID to limit join to.
return array Permission records.

isGlobalPermission() protected method

Returns whether or not a permission is a global permission.
protected isGlobalPermission ( $Value, $PermissionName, $LimitToSuffix, $Namespaces ) : boolean
$Value
$PermissionName
$LimitToSuffix
$Namespaces
return boolean

permissionColumns() public method

Get all of the permission columns in the system.
public permissionColumns ( boolean $JunctionTable = false, boolean $JunctionColumn = false ) : mixed
$JunctionTable boolean
$JunctionColumn boolean
return mixed

permissionNamespace() public static method

public static permissionNamespace ( $PermissionName ) : string
$PermissionName
return string

pivotPermissions() public method

public pivotPermissions ( $Data, null $Overrides = null ) : array
$Data
$Overrides null
return array

resetAllRoles() public static method

Reset permissions for all roles, based on the value in their Type column.
public static resetAllRoles ( string $Type = null )
$Type string Role type to limit the updates to.

resetRole() public method

Reset permissions for a role, based on the value in its Type column.
public resetRole ( integer $RoleId )
$RoleId integer ID of the role to reset permissions for.

sQLPermission() public method

Joins the query to a permission junction table and limits the results accordingly.
public sQLPermission ( Gdn_SQLDriver $SQL, mixed $Permissions, string $ForeignAlias, string $ForeignColumn, string $JunctionTable = '', string $JunctionColumn = '' )
$SQL Gdn_SQLDriver The SQL driver to add the permission to.
$Permissions mixed The permission name (or array of names) to use when limiting the query.
$ForeignAlias string The alias of the table to join to (ie. Category).
$ForeignColumn string The primary key column name of $JunctionTable (ie. CategoryID).
$JunctionTable string
$JunctionColumn string

save() public method

Save a permission row.
public save ( array $Values, boolean $SaveGlobal = false )
$Values array The values you want to save. See the Permission table for possible columns.
$SaveGlobal boolean Also save a junction permission to the global permissions.

saveAll() public method

public saveAll ( $Permissions, null $AllWhere = null )
$Permissions
$AllWhere null

splitPermission() public static method

Split a permission name into its constituant parts.
public static splitPermission ( string $PermissionName ) : array
$PermissionName string The name of the permission.
return array The split permission in the form array(Namespace, Permission,Suffix).

stripPermissions() public method

Take a permission row and strip the global/local permissions from it.
public stripPermissions ( $Row, $DefaultRow, string $LimitToSuffix = '' ) : mixed
$Row
$DefaultRow
$LimitToSuffix string
return mixed

undefine() public method

public undefine ( $Names )
$Names

unpivotPermissions() public method

public unpivotPermissions ( $Permissions, boolean $IncludeRole = false ) : array
$Permissions
$IncludeRole boolean
return array

Property Details

$DefaultPermissions protected_oe property

Default role permissions.
protected $DefaultPermissions

$RowDefaults protected_oe property

Default row permission values.
protected $RowDefaults

$_PermissionColumns protected_oe property

Permission columns.
protected $_PermissionColumns