From 8b46da3853636a313543b8d9154d93054ed1193f Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Thu, 21 Dec 2017 19:34:28 +0100 Subject: [permissionmanager] removed openRoleEdior function; changed searchFieldFunction() to use jQuery; fixed checkboxes in roleeditor not selecting on a click on the label; added selected row highlighting; disabled buttons if there are no users/roles selected; made role badges in user/location tables clickable; added phpdoc comments to most php functions; --- .../permissionmanager/inc/permissionutil.inc.php | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'modules-available/permissionmanager/inc/permissionutil.inc.php') diff --git a/modules-available/permissionmanager/inc/permissionutil.inc.php b/modules-available/permissionmanager/inc/permissionutil.inc.php index cd7fb09a..cb70c8bb 100644 --- a/modules-available/permissionmanager/inc/permissionutil.inc.php +++ b/modules-available/permissionmanager/inc/permissionutil.inc.php @@ -2,6 +2,14 @@ class PermissionUtil { + /** + * Check if the user has the given permission (for the given location). + * + * @param string $userid userid to check + * @param string $permissionid permissionid to check + * @param int|null $locationid locationid to check or null if the location should be disregarded + * @return bool true if user has permission, false if not + */ public static function userHasPermission($userid, $permissionid, $locationid) { $locations = array(); if (!is_null($locationid)) { @@ -27,6 +35,13 @@ class PermissionUtil return false; } + /** + * Get all locations where the user has the given permission. + * + * @param string $userid userid to check + * @param string $permissionid permissionid to check + * @return array array of locationids where the user has the given permission + */ public static function getAllowedLocations($userid, $permissionid) { $res = Database::simpleQuery("SELECT permissionid, COALESCE(locationid, 0) AS locationid FROM user_x_role @@ -51,6 +66,13 @@ class PermissionUtil return $allowedLocations; } + /** + * Extend an array of locations by adding all sublocations. + * + * @param array $tree tree of all locations (structured like Location::getTree()) + * @param array $locations the array of locationids to extend + * @return array extended array of locationids + */ public static function getSublocations($tree, $locations) { $result = array_flip($locations); foreach ($tree as $location) { @@ -65,6 +87,11 @@ class PermissionUtil return array_keys($result); } + /** + * Get all permissions of all active modules that have permissions in their permissions/permissions.json file. + * + * @return array permission tree as a multidimensional array + */ public static function getPermissions() { $permissions = array(); @@ -89,6 +116,13 @@ class PermissionUtil return $permissions; } + /** + * Place a permission into the given permission tree. + * + * @param string $permission the permission to place in the tree + * @param string $description the description of the permission + * @param array $tree the permission tree to modify + */ private static function putInPermissionTree($permission, $description, &$tree) { $subPermissions = explode('.', $permission); -- cgit v1.2.3-55-g7522