PHP Class RoleModel, vanilla

This file is part of Garden. Garden is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Garden is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Garden. If not, see . Contact Vanilla Forums Inc. at support [at] vanillaforums [dot] com
Inheritance: extends Gdn_Model
Exibir arquivo Open project: vanilla/vanilla Class Usage Examples

Public Properties

Property Type Description
$RankPermissions A list of permissions that define an increasing ranking of permissions.
$Roles All roles.

Public Methods

Method Description
__construct ( ) Class constructor. Defines the related database table name.
cleanUserRoles ( ) Enforce integrity between users and roles.
clearCache ( ) Clear the roles cache.
define ( $Values ) Define a role.
delete ( $where = [], $options = [] )
deleteAndReplace ( integer $roleID, integer $newRoleID ) : boolean Delete a role.
deleteID ( integer $roleID, array $options = [] ) : boolean Delete a role.
filterPersonalInfo ( $Role ) : boolean Use with array_filter to remove PersonalInfo roles.
get ( $OrderFields = '', $OrderDirection = 'asc', $Limit = false, $PageNumber = false ) Returns a resultset of all roles.
getAllDefaultRoles ( ) : array Get the default role IDs for all types of roles.
getApplicantCount ( boolean $Force = false ) : integer Get the current number of applicants waiting to be approved.
getArray ( ) : array Returns an array of RoleID => RoleName pairs.
getAssignable ( ) : array Get the roles that the current user is allowed to assign to another user.
getByName ( array | string $Names, &$Missing = null ) Get a role by name.
getByNotRoleID ( $RoleID ) Returns a resultset of role data NOT related to the specified RoleID.
getByPermission ( $Permission ) Retrieves all roles with the specified permission(s).
getByRoleID ( $RoleID ) Returns a resultset of role data related to the specified RoleID.
getByType ( string $type ) : Gdn_DataSet Return all roles matching a specific type.
getByUserID ( integer $userID ) : Gdn_DataSet Get the roles for a user.
getCategoryPermissions ( integer $roleID ) : array Get the category specific permissions for a role.
getDefaultRoles ( string $type ) : array Get the default role IDs for a type of role.
getDefaultTypes ( boolean $translate = true ) : array Get an array of default role types.
getPermissions ( integer | array $RoleID ) : array Get the permissions for one or more roles.
getPublicUserRoles ( $userID, string $field = "Name" ) : array | null | void Get a list of a user's roles that are permitted to be seen.
getUserCount ( $RoleID, $UsersOnlyWithThisRole = false ) Returns the number of users assigned to the provided RoleID. If $UsersOnlyWithThisRole is TRUE, it will return the number of users who are assigned to this RoleID and NO OTHER.
getWithRankPermissions ( ) : Gdn_DataSet Get all of the roles including their ranking permissions.
roles ( null $RoleID = null, boolean $Force = false ) : array | mixed | null | type
save ( array $FormPostValues, array | false $Settings = false ) : boolean | mixed Save role data.
setUserRoles ( &$Users, string $UserIDColumn = 'UserID', string $RolesColumn = 'Roles' )

Method Details

__construct() public method

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

cleanUserRoles() public static method

Enforce integrity between users and roles.
public static cleanUserRoles ( )

clearCache() public method

Clear the roles cache.
public clearCache ( )

define() public method

Define a role.
public define ( $Values )
$Values

delete() public method

public delete ( $where = [], $options = [] )

deleteAndReplace() public method

Delete a role.
public deleteAndReplace ( integer $roleID, integer $newRoleID ) : boolean
$roleID integer The ID of the role to delete.
$newRoleID integer Assign users of the deleted role to this new role.
return boolean Returns **true** on success or **false** on failure.

deleteID() public method

Delete a role.
public deleteID ( integer $roleID, array $options = [] ) : boolean
$roleID integer The ID of the role to delete.
$options array An array of options to affect the behavior of the delete. - **newRoleID**: The new role to point users to.
return boolean Returns **true** on success or **false** otherwise.

filterPersonalInfo() public static method

Use with array_filter to remove PersonalInfo roles.
public static filterPersonalInfo ( $Role ) : boolean
return boolean Whether role is NOT personal info (FALSE = remove it, it's personal).

get() public method

Returns a resultset of all roles.
public get ( $OrderFields = '', $OrderDirection = 'asc', $Limit = false, $PageNumber = false )

getAllDefaultRoles() public static method

Get the default role IDs for all types of roles.
public static getAllDefaultRoles ( ) : array
return array Returns an array of arrays indexed by role type.

getApplicantCount() public method

Get the current number of applicants waiting to be approved.
public getApplicantCount ( boolean $Force = false ) : integer
$Force boolean Whether or not to force a cache refresh.
return integer Returns the number of applicants or 0 if the registration method isn't set to approval.

getArray() public method

Returns an array of RoleID => RoleName pairs.
public getArray ( ) : array
return array

getAssignable() public method

Get the roles that the current user is allowed to assign to another user.
public getAssignable ( ) : array
return array Returns an array in the format `[RoleID => 'Role Name']`.

getByName() public static method

Get a role by name.
public static getByName ( array | string $Names, &$Missing = null )
$Names array | string

getByNotRoleID() public method

Returns a resultset of role data NOT related to the specified RoleID.
public getByNotRoleID ( $RoleID )

getByPermission() public method

Retrieves all roles with the specified permission(s).
public getByPermission ( $Permission )

getByRoleID() public method

Returns a resultset of role data related to the specified RoleID.
public getByRoleID ( $RoleID )

getByType() public method

Return all roles matching a specific type.
public getByType ( string $type ) : Gdn_DataSet
$type string Type slug to match role records against.
return Gdn_DataSet

getByUserID() public method

Get the roles for a user.
See also: UserModel::getRoles()
public getByUserID ( integer $userID ) : Gdn_DataSet
$userID integer The user to get the roles for.
return Gdn_DataSet Returns the roles as a dataset (with array values).

getCategoryPermissions() public method

Get the category specific permissions for a role.
public getCategoryPermissions ( integer $roleID ) : array
$roleID integer The ID of the role to get the permissions for.
return array Returns an array of permissions.

getDefaultRoles() public static method

Get the default role IDs for a type of role.
public static getDefaultRoles ( string $type ) : array
$type string One of the {@link RoleModel::TYPE_*} constants.
return array Returns an array of role IDs.

getDefaultTypes() public static method

Get an array of default role types.
public static getDefaultTypes ( boolean $translate = true ) : array
$translate boolean Whether or not to translate the type names.
return array Returns an array in the form `[type => name]`.

getPermissions() public method

Get the permissions for one or more roles.
public getPermissions ( integer | array $RoleID ) : array
$RoleID integer | array One or more role IDs to get the permissions for.
return array Returns an array of permissions.

getPublicUserRoles() public method

Optionally return all the role data or just one field name.
public getPublicUserRoles ( $userID, string $field = "Name" ) : array | null | void
$userID
$field string optionally the field name from the role table to return.
return array | null | void

getUserCount() public method

Returns the number of users assigned to the provided RoleID. If $UsersOnlyWithThisRole is TRUE, it will return the number of users who are assigned to this RoleID and NO OTHER.
public getUserCount ( $RoleID, $UsersOnlyWithThisRole = false )

getWithRankPermissions() public method

Get all of the roles including their ranking permissions.
public getWithRankPermissions ( ) : Gdn_DataSet
return Gdn_DataSet Returns all of the roles with the ranking permissions.

roles() public static method

public static roles ( null $RoleID = null, boolean $Force = false ) : array | mixed | null | type
$RoleID null
$Force boolean
return array | mixed | null | type

save() public method

Save role data.
public save ( array $FormPostValues, array | false $Settings = false ) : boolean | mixed
$FormPostValues array The role row to save.
$Settings array | false Not used.
return boolean | mixed Returns the role ID or false on error.

setUserRoles() public static method

public static setUserRoles ( &$Users, string $UserIDColumn = 'UserID', string $RolesColumn = 'Roles' )
$Users
$UserIDColumn string
$RolesColumn string

Property Details

$RankPermissions public_oe property

A list of permissions that define an increasing ranking of permissions.
public $RankPermissions

$Roles public_oe static_oe property

All roles.
public static $Roles