diff options
author | Simon Rettberg | 2018-02-23 18:41:49 +0100 |
---|---|---|
committer | Simon Rettberg | 2018-02-23 18:41:49 +0100 |
commit | 00851bd25e57938a79356d2efb36c2bea1697760 (patch) | |
tree | 11a759430f5a9ddc3b7977bb6c4451aa71287622 /modules-available/permissionmanager/inc/permissionutil.inc.php | |
parent | [adduser] Extend module to simple user manager (add/edit/remove) (diff) | |
download | slx-admin-00851bd25e57938a79356d2efb36c2bea1697760.tar.gz slx-admin-00851bd25e57938a79356d2efb36c2bea1697760.tar.xz slx-admin-00851bd25e57938a79356d2efb36c2bea1697760.zip |
[adduser] Support setting user's roles on add/edit
Diffstat (limited to 'modules-available/permissionmanager/inc/permissionutil.inc.php')
-rw-r--r-- | modules-available/permissionmanager/inc/permissionutil.inc.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/modules-available/permissionmanager/inc/permissionutil.inc.php b/modules-available/permissionmanager/inc/permissionutil.inc.php index 29663ed9..a3a2b610 100644 --- a/modules-available/permissionmanager/inc/permissionutil.inc.php +++ b/modules-available/permissionmanager/inc/permissionutil.inc.php @@ -232,6 +232,28 @@ class PermissionUtil } /** + * Get all existing roles. + * + * @param int|false $userid Which user to consider, false = none + * @param bool $onlyMatching true = filter roles the user doesn't have + * @return array list of roles + */ + public static function getRoles($userid = false, $onlyMatching = true) + { + if ($userid === false) { + return Database::queryAll('SELECT roleid, rolename FROM role ORDER BY rolename ASC'); + } + $ret = Database::queryAll('SELECT r.roleid, r.rolename, u.userid AS hasRole FROM role r + LEFT JOIN role_x_user u ON (r.roleid = u.roleid AND u.userid = :userid) + GROUP BY r.roleid + ORDER BY rolename ASC', ['userid' => $userid]); + foreach ($ret as &$role) { + settype($role['hasRole'], 'bool'); + } + return $ret; + } + + /** * Place a permission into the given permission tree. * * @param string $permission the permission to place in the tree @@ -252,4 +274,5 @@ class PermissionUtil } $tree = array('description' => $description, 'location-aware' => $locationAware, 'isLeaf' => true); } + }
\ No newline at end of file |