diff options
author | Simon Rettberg | 2018-02-19 13:36:35 +0100 |
---|---|---|
committer | Simon Rettberg | 2018-02-19 13:36:35 +0100 |
commit | 7afe5a3ffee64ff5c1ee7692a2ac4c83d46d6a78 (patch) | |
tree | e1482e82af3b53422d0008669a05847079d660c6 /modules-available/permissionmanager/inc/getpermissiondata.inc.php | |
parent | [vmstore] lang_intern -> lang_internal (diff) | |
download | slx-admin-7afe5a3ffee64ff5c1ee7692a2ac4c83d46d6a78.tar.gz slx-admin-7afe5a3ffee64ff5c1ee7692a2ac4c83d46d6a78.tar.xz slx-admin-7afe5a3ffee64ff5c1ee7692a2ac4c83d46d6a78.zip |
[permissionmanager] Implement permissions:
Permissinmanager is now protected by permissions.
In order to prevent complete lockout, the user with
userid == 1 will always be able to edit and assign permissions.
(TODO: Communicate this somehow)
Diffstat (limited to 'modules-available/permissionmanager/inc/getpermissiondata.inc.php')
-rw-r--r-- | modules-available/permissionmanager/inc/getpermissiondata.inc.php | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/modules-available/permissionmanager/inc/getpermissiondata.inc.php b/modules-available/permissionmanager/inc/getpermissiondata.inc.php index dd100d42..496c8224 100644 --- a/modules-available/permissionmanager/inc/getpermissiondata.inc.php +++ b/modules-available/permissionmanager/inc/getpermissiondata.inc.php @@ -3,6 +3,9 @@ class GetPermissionData { + const WITH_USER_COUNT = 1; + const WITH_LOCATION_COUNT = 2; + /** * Get data for all users. * @@ -64,11 +67,26 @@ class GetPermissionData /** * Get all roles. * + * @param int $flags Bitmask specifying additional data to fetch (WITH_* constants of this class) * @return array array roles (each with roleid and rolename) */ - public static function getRoles() + public static function getRoles($flags = 0) { - return Database::queryAll("SELECT roleid, rolename FROM role ORDER BY rolename ASC"); + $cols = $joins = ''; + if ($flags & self::WITH_USER_COUNT) { + $cols .= ', Count(DISTINCT rxu.userid) AS users'; + $joins .= ' LEFT JOIN user_x_role rxu ON (r.roleid = rxu.roleid)'; + } + if ($flags & self::WITH_LOCATION_COUNT) { + $cols .= ', Count(DISTINCT rxl.locationid) AS locations'; + $joins .= ' LEFT JOIN role_x_location rxl ON (r.roleid = rxl.roleid)'; + } + if (!empty($joins)) { + $joins .= ' GROUP BY r.roleid'; + } + return Database::queryAll("SELECT r.roleid, r.rolename $cols FROM role r + $joins + ORDER BY rolename ASC"); } /** |