ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjMainMenuAccess.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
30 private ?int $ref_id;
31 private ?array $global_roles = null;
32
36 public function __construct()
37 {
38 global $DIC;
39 $this->rbacreview = $DIC->rbac()->review();
40 $this->rbacsystem = $DIC->rbac()->system();
41 $this->user = $DIC->user();
42 $this->ref_id = $DIC->http()->wrapper()->query()->has('ref_id')
43 ? $DIC->http()->wrapper()->query()->retrieve('ref_id', $DIC->refinery()->kindlyTo()->int())
44 : null;
45 }
46
51 public function checkAccessAndThrowException(string $permission): void
52 {
53 if (!$this->hasUserPermissionTo($permission)) {
54 throw new ilException('Permission denied');
55 }
56 }
57
62 public function hasUserPermissionTo(string $permission): bool
63 {
64 if ($this->ref_id === null) {
65 return false;
66 }
67 return $this->rbacsystem->checkAccess($permission, $this->ref_id);
68 }
69
73 public function getGlobalRoles(): array
74 {
75 $global_roles = $this->rbacreview->getRolesForIDs(
76 $this->rbacreview->getGlobalRoles(),
77 false
78 );
79
80 $roles = [];
81 foreach ($global_roles as $global_role) {
82 $roles[$global_role['rol_id']] = $global_role['title'];
83 }
84
85 return $roles;
86 }
87
88 public function isCurrentUserAllowedToSeeCustomItem(ilMMCustomItemStorage $item, Closure $current): Closure
89 {
90 return function () use ($item, $current): bool {
91 if (!$item->hasRoleBasedVisibility()) {
92 return $current();
93 }
94 if (!empty($item->getGlobalRoleIDs())) {
95 foreach ($this->resolveUsersGlobalRoles() as $role_of_current_user) {
96 if (in_array((int) $role_of_current_user, $item->getGlobalRoleIDs(), true)) {
97 return $current();
98 }
99 }
100 }
101 return false;
102 };
103 }
104
105 private function resolveUsersGlobalRoles(): array
106 {
107 return $this->global_roles
108 ?? $this->global_roles = $this->rbacreview->assignedGlobalRoles($this->user->getId());
109 }
110}
Base class for ILIAS Exception handling.
Class ilMMCustomItemStorage.
Class ilObjMainMenuAccess.
checkAccessAndThrowException(string $permission)
isCurrentUserAllowedToSeeCustomItem(ilMMCustomItemStorage $item, Closure $current)
hasUserPermissionTo(string $permission)
__construct()
ilObjMainMenuAccess constructor.
User class.
Class ilObjectAccess.
class ilRbacReview Contains Review functions of core Rbac.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26