ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilObjMainMenuAccess.php
Go to the documentation of this file.
1<?php
2
8{
9
13 private $http;
17 private $user;
21 private $rbacsystem;
25 private $rbacreview;
26
30 public function __construct()
31 {
32 global $DIC;
33 $this->rbacreview = $DIC->rbac()->review();
34 $this->rbacsystem = $DIC->rbac()->system();
35 $this->user = $DIC->user();
36 $this->http = $DIC->http();
37 }
38
43 public function checkAccessAndThrowException(string $permission) : void
44 {
45 if (!$this->hasUserPermissionTo($permission)) {
46 throw new ilException('Permission denied');
47 }
48 }
49
54 public function hasUserPermissionTo(string $permission) : bool
55 {
56 return (bool) $this->rbacsystem->checkAccess($permission, $this->http->request()->getQueryParams()['ref_id']);
57 }
58
59
63 public function getGlobalRoles(): array {
64 $global_roles = $this->rbacreview->getRolesForIDs(
65 $this->rbacreview->getGlobalRoles(),false
66 );
67
68 $roles = [];
69 foreach ($global_roles as $global_role) {
70 $roles[$global_role['rol_id']] = $global_role['title'];
71 }
72
73 return $roles;
74 }
75
81 {
82 return function () use ($item): bool {
83 $roles_of_current_user = $this->rbacreview->assignedGlobalRoles($this->user->getId());
84 if (!$item->hasRoleBasedVisibility()) {
85 return true;
86 }
87 if ($item->hasRoleBasedVisibility() && !empty($item->getGlobalRoleIDs())) {
88 foreach ($roles_of_current_user as $role_of_current_user) {
89 if (in_array($role_of_current_user, $item->getGlobalRoleIDs())) {
90 return true;
91 }
92 }
93 }
94 return false;
95 };
96 }
97}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Base class for ILIAS Exception handling.
Class ilMMCustomItemStorage.
Class ilObjMainMenuAccess.
isCurrentUserAllowedToSeeCustomItem(ilMMCustomItemStorage $item)
checkAccessAndThrowException(string $permission)
hasUserPermissionTo(string $permission)
__construct()
ilObjMainMenuAccess constructor.
Class ilObjectAccess.
static http()
Fetches the global http state from ILIAS.
$DIC
Definition: xapitoken.php:46