mirror of
https://github.com/delight-im/PHP-Auth.git
synced 2025-08-06 16:16:29 +02:00
Implement method 'getRolesForUserById' in class 'Administration'
This commit is contained in:
@@ -286,6 +286,36 @@ final class Administration extends UserManager {
|
|||||||
return ($rolesBitmask & $role) === $role;
|
return ($rolesBitmask & $role) === $role;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the roles of the user with the given ID, mapping the numerical values to their descriptive names
|
||||||
|
*
|
||||||
|
* @param int $userId the ID of the user to return the roles for
|
||||||
|
* @return array
|
||||||
|
* @throws UnknownIdException if no user with the specified ID has been found
|
||||||
|
*
|
||||||
|
* @see Role
|
||||||
|
*/
|
||||||
|
public function getRolesForUserById($userId) {
|
||||||
|
$userId = (int) $userId;
|
||||||
|
|
||||||
|
$rolesBitmask = $this->db->selectValue(
|
||||||
|
'SELECT roles_mask FROM ' . $this->dbTablePrefix . 'users WHERE id = ?',
|
||||||
|
[ $userId ]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($rolesBitmask === null) {
|
||||||
|
throw new UnknownIdException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return \array_filter(
|
||||||
|
Role::getMap(),
|
||||||
|
function ($each) use ($rolesBitmask) {
|
||||||
|
return ($rolesBitmask & $each) === $each;
|
||||||
|
},
|
||||||
|
\ARRAY_FILTER_USE_KEY
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signs in as the user with the specified ID
|
* Signs in as the user with the specified ID
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user