diff options
author | Simon Rettberg | 2018-02-12 18:18:18 +0100 |
---|---|---|
committer | Simon Rettberg | 2018-02-12 18:18:18 +0100 |
commit | dfc4a765667e65373c3ed448b931b85836bcaa2a (patch) | |
tree | a00a38be4460cd2077d304ba2cae6fbe63ecc30e /modules-available/permissionmanager/inc/getpermissiondata.inc.php | |
parent | [permissionmanager] getPermissions(): Only consider permissions for active mo... (diff) | |
download | slx-admin-dfc4a765667e65373c3ed448b931b85836bcaa2a.tar.gz slx-admin-dfc4a765667e65373c3ed448b931b85836bcaa2a.tar.xz slx-admin-dfc4a765667e65373c3ed448b931b85836bcaa2a.zip |
[permissionmanager] GetPermissionData: Fix code style, simplify getRoles()
Diffstat (limited to 'modules-available/permissionmanager/inc/getpermissiondata.inc.php')
-rw-r--r-- | modules-available/permissionmanager/inc/getpermissiondata.inc.php | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/modules-available/permissionmanager/inc/getpermissiondata.inc.php b/modules-available/permissionmanager/inc/getpermissiondata.inc.php index 982fa0b7..dd100d42 100644 --- a/modules-available/permissionmanager/inc/getpermissiondata.inc.php +++ b/modules-available/permissionmanager/inc/getpermissiondata.inc.php @@ -1,27 +1,29 @@ <?php -class GetPermissionData { +class GetPermissionData +{ /** * Get data for all users. * * @return array array of users (each with userid, username and roles (each with roleid and rolename)) */ - public static function getUserData() { + public static function getUserData() + { $res = Database::simpleQuery("SELECT user.userid AS userid, user.login AS login, role.rolename AS rolename, role.roleid AS roleid FROM user LEFT JOIN user_x_role ON user.userid = user_x_role.userid LEFT JOIN role ON user_x_role.roleid = role.roleid "); - $userdata= array(); + $userdata = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $userdata[$row['userid'].' '.$row['login']][] = array( + $userdata[$row['userid'] . ' ' . $row['login']][] = array( 'roleid' => $row['roleid'], 'rolename' => $row['rolename'] ); } $data = array(); - foreach($userdata AS $user => $roles) { + foreach ($userdata AS $user => $roles) { $user = explode(" ", $user, 2); $data[] = array( 'userid' => $user[0], @@ -37,8 +39,9 @@ class GetPermissionData { * * @return array array of locations (each including the roles that have permissions for them) */ - public static function getLocationData() { - $res = Database::simpleQuery("SELECT role.roleid as roleid, rolename, GROUP_CONCAT(COALESCE(locationid, 0)) AS locationids FROM role + public static function getLocationData() + { + $res = Database::simpleQuery("SELECT role.roleid AS roleid, rolename, GROUP_CONCAT(COALESCE(locationid, 0)) AS locationids FROM role INNER JOIN role_x_location ON role.roleid = role_x_location.roleid GROUP BY roleid ORDER BY rolename ASC"); $locations = Location::getLocations(0, 0, false, true); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { @@ -63,16 +66,9 @@ class GetPermissionData { * * @return array array roles (each with roleid and rolename) */ - public static function getRoles() { - $res = Database::simpleQuery("SELECT roleid, rolename FROM role ORDER BY rolename ASC"); - $data = array(); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $data[] = array( - 'roleid' => $row['roleid'], - 'rolename' => $row['rolename'] - ); - } - return $data; + public static function getRoles() + { + return Database::queryAll("SELECT roleid, rolename FROM role ORDER BY rolename ASC"); } /** @@ -81,7 +77,8 @@ class GetPermissionData { * @param string $roleid id of the role * @return array array containing an array of permissions and an array of locations */ - public static function getRoleData($roleid) { + public static function getRoleData($roleid) + { $query = "SELECT roleid, rolename FROM role WHERE roleid = :roleid"; $data = Database::queryFirst($query, array("roleid" => $roleid)); $query = "SELECT roleid, locationid FROM role_x_location WHERE roleid = :roleid"; |