PHP Класс PermissionModel, vanilla

Наследование: extends Model
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$DefaultPermissions Default role permissions.
$RowDefaults Default row permission values.
$_PermissionColumns Permission columns.

Открытые методы

Метод Описание
__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

Защищенные методы

Метод Описание
_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.

Описание методов

_Backtick() защищенный Метод

protected _Backtick ( $Values ) : array
$Values
Результат array

_MergeDisabledPermissions() защищенный Метод

Merge junction permissions with global permissions if they are disabled.
protected _MergeDisabledPermissions ( array &$GlobalPermissions ) : void
$GlobalPermissions array
Результат void

_UnpivotPermissionsRow() защищенный Метод

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

__construct() публичный Метод

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

addDefault() публичный Метод

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() публичный статический Метод

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.
Результат array Returns an array with all of the permissions in both permissions arrays.

assignDefaults() публичный Метод

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 cachePermissions ( null $UserID = null, null $RoleID = null ) : array | null
$UserID null
$RoleID null
Результат array | null

clearPermissions() публичный Метод

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

define() публичный Метод

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 delete ( null $RoleID = null, null $JunctionTable = null, null $JunctionColumn = null, null $JunctionID = null )
$RoleID null
$JunctionTable null
$JunctionColumn null
$JunctionID null

getAllowedPermissionNamespaces() публичный Метод

Returns a complete list of all enabled applications & plugins. This list can act as a namespace list for permissions.
public getAllowedPermissionNamespaces ( ) : array
Результат array

getDefaults() публичный Метод

Grab the list of default permissions by role type
public getDefaults ( ) : array
Результат array List of permissions, grouped by role type

getGlobalPermissions() публичный Метод

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.
Результат Returns an

getJunctionPermissions() публичный Метод

public getJunctionPermissions ( $Where, null $JunctionTable = null, string $LimitToSuffix = '', array $Options = [] ) : array
$Where
$JunctionTable null
$LimitToSuffix string
$Options array
Результат array

getPermissions() публичный Метод

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
Результат array

getPermissionsByRole() публичный Метод

Get the permissions for one or more roles.
public getPermissionsByRole ( integer $roleID ) : array
$roleID integer The role to get the permissions for.
Результат array Returns a permission array suitable for use in a session.

getPermissionsEdit() публичный Метод

public getPermissionsEdit ( $RoleID, string $LimitToSuffix = '', boolean $includeJunction = true ) : array
$RoleID
$LimitToSuffix string
$includeJunction boolean
Результат array

getRolePermissions() публичный Метод

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.
Результат array Permission records.

getRowDefaults() публичный Метод

Grab default permission column values.
public getRowDefaults ( ) : array
Результат array A list of default permission values.

getUserPermissions() публичный Метод

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.
Результат array Permission records.

isGlobalPermission() защищенный Метод

Returns whether or not a permission is a global permission.
protected isGlobalPermission ( $Value, $PermissionName, $LimitToSuffix, $Namespaces ) : boolean
$Value
$PermissionName
$LimitToSuffix
$Namespaces
Результат boolean

permissionColumns() публичный Метод

Get all of the permission columns in the system.
public permissionColumns ( boolean $JunctionTable = false, boolean $JunctionColumn = false ) : mixed
$JunctionTable boolean
$JunctionColumn boolean
Результат mixed

permissionNamespace() публичный статический Метод

public static permissionNamespace ( $PermissionName ) : string
$PermissionName
Результат string

pivotPermissions() публичный Метод

public pivotPermissions ( $Data, null $Overrides = null ) : array
$Data
$Overrides null
Результат array

resetAllRoles() публичный статический Метод

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() публичный Метод

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() публичный Метод

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() публичный Метод

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 saveAll ( $Permissions, null $AllWhere = null )
$Permissions
$AllWhere null

splitPermission() публичный статический Метод

Split a permission name into its constituant parts.
public static splitPermission ( string $PermissionName ) : array
$PermissionName string The name of the permission.
Результат array The split permission in the form array(Namespace, Permission,Suffix).

stripPermissions() публичный Метод

Take a permission row and strip the global/local permissions from it.
public stripPermissions ( $Row, $DefaultRow, string $LimitToSuffix = '' ) : mixed
$Row
$DefaultRow
$LimitToSuffix string
Результат mixed

undefine() публичный Метод

public undefine ( $Names )
$Names

unpivotPermissions() публичный Метод

public unpivotPermissions ( $Permissions, boolean $IncludeRole = false ) : array
$Permissions
$IncludeRole boolean
Результат array

Описание свойств

$DefaultPermissions защищенное свойство

Default role permissions.
protected $DefaultPermissions

$RowDefaults защищенное свойство

Default row permission values.
protected $RowDefaults

$_PermissionColumns защищенное свойство

Permission columns.
protected $_PermissionColumns