You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB
PHTML

14 years ago
<?php
use Engelsystem\Database\Db;
/**
* @param int $user_id
* @return array
*/
8 years ago
function privileges_for_user($user_id)
{
$privileges = [];
$user_privileges = DB::select('
8 years ago
SELECT `Privileges`.`name`
FROM `users`
JOIN `UserGroups` ON (`users`.`id` = `UserGroups`.`uid`)
8 years ago
JOIN `GroupPrivileges` ON (`UserGroups`.`group_id` = `GroupPrivileges`.`group_id`)
JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`)
WHERE `users`.`id`=?
', [$user_id]);
foreach ($user_privileges as $user_privilege) {
$privileges[] = $user_privilege['name'];
8 years ago
}
return $privileges;
}
/**
* @param int $group_id
* @return array
*/
8 years ago
function privileges_for_group($group_id)
{
$privileges = [];
$groups_privileges = DB::select('
SELECT `name`
8 years ago
FROM `GroupPrivileges`
JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`)
WHERE `group_id`=?
', [$group_id]);
foreach ($groups_privileges as $guest_privilege) {
$privileges[] = $guest_privilege['name'];
8 years ago
}
return $privileges;
}