Stud.IP  5.4
RolePersistence Class Reference

Static Public Member Functions

static getAllRoles (bool $grouped=false)
 
static getRoleIdByName ($name)
 
static saveRole ($role)
 
static deleteRole ($role)
 
static deleteRoleByName (string $role_name)
 
static assignRole (User $user, $role, $institut_id='')
 
static assignRoleToPerm (string $perm, Role $role)
 
static getAssignedRoles ($user_id, $implicit=false)
 
static getAssignedRoleInstitutes ($user_id, $role_id)
 
static isAssignedRole ($userid, $assignedrole, $institut_id='')
 
static deleteRoleAssignment (User $user, $role, $institut_id=null)
 
static deleteRoleAssignmentFromPerm (string $perm, Role $role)
 
static getAllRoleAssignments ($user=null)
 
static assignPluginRoles ($plugin_id, $role_ids)
 
static deleteAssignedPluginRoles ($plugin_id, $role_ids)
 
static getAssignedPluginRoles ($plugin_id)
 
static getUsersWithRoleByName (string $role_name, bool $only_explicit=true)
 
static getUsersWithRoleById (int $role_id, bool $only_explicit=true)
 
static getStatistics ()
 
static countImplicitUsers ($role_id)
 
static expireRolesCache ()
 
static expireUserCache ($user_id=null)
 
static expirePluginCache ($plugin_id=null)
 
static expireCaches ()
 

Data Fields

const ROLES_CACHE_KEY = 'roles'
 
const USER_ROLES_CACHE_KEY = 'roles/user'
 
const PLUGIN_ROLES_CACHE_KEY = 'roles/plugin'
 

Static Protected Attributes

static $all_roles = null
 

Member Function Documentation

◆ assignPluginRoles()

static assignPluginRoles (   $plugin_id,
  $role_ids 
)
static

Enter description here...

Parameters
int$pluginid
array$roleids

◆ assignRole()

static assignRole ( User  $user,
  $role,
  $institut_id = '' 
)
static

Saves a role assignment to the database

Parameters
User$user
Role$role
string$institut_id

◆ assignRoleToPerm()

static assignRoleToPerm ( string  $perm,
Role  $role 
)
static

Assigns a role to a stud.ip permission. System roles cannot be assigned to permissions.

Parameters
string$perm
Role$role
Returns
bool
Exceptions
Exception

◆ countImplicitUsers()

static countImplicitUsers (   $role_id)
static

Counts the implicitely assigned users for a role.

Parameters
mixed$role_idRole id or array of role ids
Returns
mixed number of implictit for the role (if one role id is given) or associative array [role id => number of implicit users] when given a list of role ids

◆ deleteAssignedPluginRoles()

static deleteAssignedPluginRoles (   $plugin_id,
  $role_ids 
)
static

Removes the given roles' assignments from the given plugin.

Parameters
int$pluginid
array$roleids

◆ deleteRole()

static deleteRole (   $role)
static

Delete role if not a permanent role. System roles cannot be deleted.

Parameters
Role$role

◆ deleteRoleAssignment()

static deleteRoleAssignment ( User  $user,
  $role,
  $institut_id = null 
)
static

Deletes a role assignment from the database

Parameters
User$user
Role$role
String$institut_id

◆ deleteRoleAssignmentFromPerm()

static deleteRoleAssignmentFromPerm ( string  $perm,
Role  $role 
)
static

Removes a role from a stud.ip permission. System roles cannot be removed from permissions.

Parameters
string$perm
Role$role
Returns
bool
Exceptions
Exception

◆ deleteRoleByName()

static deleteRoleByName ( string  $role_name)
static

Delete role by name if not a permanent role. System roles cannot be deleted.

Parameters
string$role_name
Returns
bool

◆ expireCaches()

static expireCaches ( )
static

Expires all caches

◆ expirePluginCache()

static expirePluginCache (   $plugin_id = null)
static

Expires all cached plugin role assignments.

Parameters
string | int | null$plugin_idOptional plugin id to expire the cache for. If none is given, the whole cache is cleared.

◆ expireRolesCache()

static expireRolesCache ( )
static

Expires all cached roles.

◆ expireUserCache()

static expireUserCache (   $user_id = null)
static

Expires all cached user role assignments.

Parameters
string | null$user_idOptional user id to expire the cache for. If none is given, the whole cache is cleared.

◆ getAllRoleAssignments()

static getAllRoleAssignments (   $user = null)
static

Get's all Role-Assignments for a certain user. If no user is set, all role assignments are returned.

Parameters
User$user
Returns
array with roleids and the assigned userids

◆ getAllRoles()

static getAllRoles ( bool  $grouped = false)
static

Returns all available roles.

Parameters
bool$groupedReturn the roles grouped by system type or other
Returns
Role[]|array{system: Role[], other: Role[]}

◆ getAssignedPluginRoles()

static getAssignedPluginRoles (   $plugin_id)
static

Return all roles assigned to a plugin.

Parameters
int$pluginid
Returns
array

◆ getAssignedRoleInstitutes()

static getAssignedRoleInstitutes (   $user_id,
  $role_id 
)
static

Returns institutes for which the given user has the given role.

Parameters
string$user_idUser id
int$role_idRole id
Returns
array of institute ids

◆ getAssignedRoles()

static getAssignedRoles (   $user_id,
  $implicit = false 
)
static

Gets all assigned roles from the database for a user

Parameters
int$userid
boolean$implicit
Returns
array

◆ getRoleIdByName()

static getRoleIdByName (   $name)
static

◆ getStatistics()

static getStatistics ( )
static

Returns statistic values for each role:

  • number of explicitely assigned users
  • number of implicitely assigned users
  • number of assigned plugins
Returns
array

◆ getUsersWithRoleById()

static getUsersWithRoleById ( int  $role_id,
bool  $only_explicit = true 
)
static

Returns all users that have a specific role - given by it's id.

Parameters
int$role_idId of the role
bool$only_explicitOnly select explicit assignments from table roles_user if true, otherwise also select by perm defined in table roles_studipperms
Returns
User[]

◆ getUsersWithRoleByName()

static getUsersWithRoleByName ( string  $role_name,
bool  $only_explicit = true 
)
static

Returns all users that have a specific role - given by it's name.

Parameters
string$role_nameName of the role
bool$only_explicitOnly select explicit assignments from table roles_user if true, otherwise also select by perm defined in table roles_studipperms
Returns
User[]

◆ isAssignedRole()

static isAssignedRole (   $userid,
  $assignedrole,
  $institut_id = '' 
)
static

Checks a role assignment for an user optionally check for institute

Parameters
string$userid
string$assignedrole
string$institut_id
Returns
boolean

◆ saveRole()

static saveRole (   $role)
static

Inserts the role into the database or does an update, if it's already there

Parameters
Role$role
Returns
int the role id

Field Documentation

◆ $all_roles

$all_roles = null
staticprotected

◆ PLUGIN_ROLES_CACHE_KEY

const PLUGIN_ROLES_CACHE_KEY = 'roles/plugin'

◆ ROLES_CACHE_KEY

const ROLES_CACHE_KEY = 'roles'

◆ USER_ROLES_CACHE_KEY

const USER_ROLES_CACHE_KEY = 'roles/user'

The documentation for this class was generated from the following file: