ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjMainMenuAccess.php
Go to the documentation of this file.
1<?php
2
24{
25
29 private $http;
33 private $user;
37 private $rbacsystem;
41 private $rbacreview;
42
46 public function __construct()
47 {
48 global $DIC;
49 $this->rbacreview = $DIC->rbac()->review();
50 $this->rbacsystem = $DIC->rbac()->system();
51 $this->user = $DIC->user();
52 $this->http = $DIC->http();
53 }
54
59 public function checkAccessAndThrowException(string $permission) : void
60 {
61 if (!$this->hasUserPermissionTo($permission)) {
62 throw new ilException('Permission denied');
63 }
64 }
65
70 public function hasUserPermissionTo(string $permission) : bool
71 {
72 return (bool) $this->rbacsystem->checkAccess($permission, $this->http->request()->getQueryParams()['ref_id']);
73 }
74
75
79 public function getGlobalRoles() : array
80 {
81 $global_roles = $this->rbacreview->getRolesForIDs(
82 $this->rbacreview->getGlobalRoles(),
83 false
84 );
85
86 $roles = [];
87 foreach ($global_roles as $global_role) {
88 $roles[$global_role['rol_id']] = $global_role['title'];
89 }
90
91 return $roles;
92 }
93
94 public function isCurrentUserAllowedToSeeCustomItem(ilMMCustomItemStorage $item, Closure $current) : Closure
95 {
96 return function () use ($item, $current) : bool {
97 $roles_of_current_user = $this->rbacreview->assignedGlobalRoles($this->user->getId());
98 if (!$item->hasRoleBasedVisibility()) {
99 return $current();
100 }
101 if ($item->hasRoleBasedVisibility() && !empty($item->getGlobalRoleIDs())) {
102 foreach ($roles_of_current_user as $role_of_current_user) {
103 if (in_array((int) $role_of_current_user, $item->getGlobalRoleIDs(), true)) {
104 return $current();
105 }
106 }
107 }
108 return false;
109 };
110 }
111}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkAccessAndThrowException(string $permission)
isCurrentUserAllowedToSeeCustomItem(ilMMCustomItemStorage $item, Closure $current)
hasUserPermissionTo(string $permission)
__construct()
ilObjMainMenuAccess constructor.
Class ilObjectAccess.
global $DIC
Definition: goto.php:24
static http()
Fetches the global http state from ILIAS.