UsersRolesDb
extends BaseModel
in package
Users roles DB model.
Tags
Table of Contents
Properties
- $allowedSort : array<string|int, mixed>
- $debugUpdate : array<string|int, mixed>
Methods
- add() : bool
- Add user to roles.
- delete() : bool
- Delete role IDs from users_roles table.
- isEditingHigherRole() : bool
- Check that is current user is editing selected user(s) that has higher role.
- isInRole() : bool
- Check if current user is in selected role or may be higher priority (depend on options).
- listItems() : array<string|int, mixed>
- List user's roles items.
- update() : bool
- Update roles.
Properties
$allowedSort
protected
array<string|int, mixed>
$allowedSort
= ['userrole_id', 'userrole_name', 'userrole_description', 'userrole_priority', 'userrole_create', 'userrole_lastupdate']
Allowed sort columns in db.
$debugUpdate
protected
array<string|int, mixed>
$debugUpdate
= []
Debug update for internal use in update()
method. This added to prevent "creation of dynamic property is deprecated" error.
Methods
add()
Add user to roles.
public
add(int $user_id, array<string|int, mixed> $roleIds) : bool
Also verify that user ID exists, role ID(s) are exists before add.
This is not verify that roles will be duplicate or not.
Parameters
- $user_id : int
-
The user ID.
- $roleIds : array<string|int, mixed>
-
Role IDs.
Return values
bool —Return true
on success, false
on failure.
delete()
Delete role IDs from users_roles table.
public
delete([int $user_id = null ][, array<string|int, mixed> $roleIds = [] ]) : bool
Also delete permission cache (not delete user ID in user_permissions table).
Parameters
- $user_id : int = null
-
User ID.
- $roleIds : array<string|int, mixed> = []
-
The role IDs.
Return values
bool —Return true
on success, false
for otherwise.
isEditingHigherRole()
Check that is current user is editing selected user(s) that has higher role.
public
isEditingHigherRole(int $currentUserId, int|array<string|int, mixed> $selectedUserIds) : bool
Parameters
- $currentUserId : int
-
The user ID of current user.
- $selectedUserIds : int|array<string|int, mixed>
-
The user ID (int) or (array) of user IDs of selected user(s).
Return values
bool —Return false
if current user is not editing user who has higher role. Return true
for otherwise.
isInRole()
Check if current user is in selected role or may be higher priority (depend on options).
public
isInRole(int $currentUserId[, array<string|int, mixed> $options = [] ]) : bool
If option userrole_priority
and userrole_id
both are set, the userrole_priority
will be use for checking.
If option userrole_id
is set but without isHigherOrEquals
option to true
, it will be checking for the same role ID number only.
If with isHigherOrEquals
option to true
, it will be checking with priority that must equals or higher (lower number).
Parameters
- $currentUserId : int
-
The current user ID.
- $options : array<string|int, mixed> = []
-
Associative array:
userrole_id
(int) The user role ID. Theuserrole_id
oruserrole_priority
is required. If both are set, theuserrole_priority
will be use.
userrole_priority
(int) The user role priority number. Theuserrole_id
oruserrole_priority
is required. If both are set, theuserrole_priority
will be use.
isHigherOrEquals
(bool) Set totrue
to check for higher or equal priority with destination role option. Default isfalse
.
Tags
Return values
bool —Return true
if current user is in selected role (or may be higher). Return false
for otherwise.
listItems()
List user's roles items.
public
listItems([array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Parameters
- $options : array<string|int, mixed> = []
-
The associative array options. Available options keys:
roleIdsIn
(array) the role IDs to use in the sql commandWHERE IN (...)
where
(array) the where conditions where key is column name and value is its value,
sortOrders
(array) the sort order wheresort
key is column name,order
key is mysql order (ASC, DESC),
unlimited
(bool) set totrue
to show unlimited items, unset or set tofalse
to show limited items,
limit
(int) limit items per page. maximum is 100,
offset
(int) offset or start at record. 0 is first record,
Return values
array<string|int, mixed> —Return associative array with total
and items
in keys.
update()
Update roles.
public
update(int $user_id, array<string|int, mixed> $roleIds) : bool
Parameters
- $user_id : int
-
The user ID.
- $roleIds : array<string|int, mixed>
-
2D array of role IDs.
Return values
bool —Return true
on success, false
on failure.