2011-06-02 00:48:29 +02:00
|
|
|
<?php
|
|
|
|
|
2021-11-30 23:29:51 +01:00
|
|
|
use Engelsystem\Database\Db;
|
2011-06-03 15:30:17 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param int $user_id
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function privileges_for_user($user_id)
|
|
|
|
{
|
|
|
|
$privileges = [];
|
2022-06-16 22:50:52 +02:00
|
|
|
$user_privileges = Db::select('
|
2017-01-02 15:43:36 +01:00
|
|
|
SELECT `Privileges`.`name`
|
2018-10-11 01:26:34 +02:00
|
|
|
FROM `users`
|
|
|
|
JOIN `UserGroups` ON (`users`.`id` = `UserGroups`.`uid`)
|
2017-01-02 15:43:36 +01:00
|
|
|
JOIN `GroupPrivileges` ON (`UserGroups`.`group_id` = `GroupPrivileges`.`group_id`)
|
|
|
|
JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`)
|
2018-10-11 01:26:34 +02:00
|
|
|
WHERE `users`.`id`=?
|
2017-01-21 13:58:53 +01:00
|
|
|
', [$user_id]);
|
|
|
|
foreach ($user_privileges as $user_privilege) {
|
|
|
|
$privileges[] = $user_privilege['name'];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
|
|
|
return $privileges;
|
2011-06-03 15:30:17 +02:00
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param int $group_id
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function privileges_for_group($group_id)
|
|
|
|
{
|
|
|
|
$privileges = [];
|
2022-06-16 22:50:52 +02:00
|
|
|
$groups_privileges = Db::select('
|
2017-01-21 13:58:53 +01:00
|
|
|
SELECT `name`
|
2017-01-02 15:43:36 +01:00
|
|
|
FROM `GroupPrivileges`
|
|
|
|
JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`)
|
2017-01-21 13:58:53 +01:00
|
|
|
WHERE `group_id`=?
|
|
|
|
', [$group_id]);
|
|
|
|
foreach ($groups_privileges as $guest_privilege) {
|
|
|
|
$privileges[] = $guest_privilege['name'];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
|
|
|
return $privileges;
|
2011-06-03 15:30:17 +02:00
|
|
|
}
|