ILIAS  release_8 Revision v8.24
class.AccessManager.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
24
29{
30 protected \ilAccessHandler $access;
31 protected int $ref_id;
32 protected int $user_id;
34
35 public function __construct(
38 int $ref_id,
39 int $user_id
40 ) {
41 $this->domain_service = $domain_service;
42 $this->access = $access;
43 $this->user_id = $user_id;
44 $this->ref_id = $ref_id;
45 }
46
47 protected function getSurvey(): \ilObjSurvey
48 {
49 return new \ilObjSurvey($this->ref_id);
50 }
51
52 public function canRead(): bool
53 {
54 return $this->access->checkAccessOfUser(
55 $this->user_id,
56 "read",
57 "",
58 $this->ref_id
59 );
60 }
61
62 public function canManageCodes(): bool
63 {
64 return $this->access->checkAccessOfUser(
65 $this->user_id,
66 "write",
67 "",
68 $this->ref_id
69 ) ||
70 $this->access->checkAccessOfUser( // see #35369
71 $this->user_id,
72 "delete",
73 "",
74 $this->ref_id
75 );
76 }
77
82 public function canAccessInfoScreen(): bool
83 {
84 $participant_status = $this->domain_service
85 ->participants()
86 ->status($this->getSurvey(), $this->user_id);
87 if ($participant_status->isExternalRater() ||
88 $this->access->checkAccessOfUser($this->user_id, "read", "", $this->ref_id) ||
89 $this->access->checkAccessOfUser($this->user_id, "visible", "", $this->ref_id)) {
90 return true;
91 }
92 return false;
93 }
94
100 public function canStartSurvey(): bool
101 {
102 $survey = $this->getSurvey();
103 $participant_status = $this->domain_service
104 ->participants()
105 ->status($survey, $this->user_id);
106 if ($participant_status->isExternalRater() ||
107 $this->access->checkAccessOfUser($this->user_id, "read", "", $this->ref_id)) {
108 if (!$survey->getOfflineStatus() &&
109 $survey->hasStarted() &&
110 !$survey->hasEnded()) {
111 return true;
112 }
113 }
114 return false;
115 }
116
117 public function canEditSettings(): bool
118 {
119 return $this->access->checkAccessOfUser($this->user_id, "write", "", $this->ref_id);
120 }
121
125 public function canAccessEvaluation(): bool
126 {
127 $survey = $this->getSurvey();
128 if ($this->access->checkAccessOfUser($this->user_id, "write", "", $this->ref_id) ||
129 $this->checkRbacOrPositionPermission('read_results', 'access_results') ||
130 \ilObjSurveyAccess::_hasEvaluationAccess($survey->getId(), $this->user_id)) {
131 return true;
132 }
133 return false;
134 }
135
137 string $a_rbac_permission,
138 string $a_position_permission
139 ): bool {
140 $access = $this->access;
142 $a_rbac_permission,
143 $a_position_permission,
144 $this->ref_id
145 );
146 }
147
151 public function isCodeInputAllowed(): bool
152 {
153 $survey = $this->getSurvey();
154 $participant_status = $this->domain_service
155 ->participants()
156 ->status($this->getSurvey(), $this->user_id);
157 if ($participant_status->isExternalRater() ||
158 $survey->getAnonymize() || !$survey->isAccessibleWithoutCode()) {
159 return true;
160 }
161 return false;
162 }
163
169 ?array $a_finished_ids = null
170 ): array {
171 $all_participants = $this->getSurvey()->getSurveyParticipants($a_finished_ids);
172 $participant_ids = [];
173 foreach ($all_participants as $participant) {
174 if (isset($participant['usr_id'])) {
175 $participant_ids[] = $participant['usr_id'];
176 }
177 }
178
179 $filtered_participant_ids = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
180 'read_results',
181 'access_results',
182 $this->getSurvey()->getRefId(),
183 $participant_ids
184 );
185 $participants = [];
186 foreach ($all_participants as $username => $user_data) {
187 if (!isset($user_data['usr_id'])) {
188 $participants[$username] = $user_data;
189 }
190 if (in_array(($user_data['usr_id'] ?? null), $filtered_participant_ids)) {
191 $participants[$username] = $user_data;
192 }
193 }
194 return $participants;
195 }
196}
canStartSurvey()
Can start the survey This is possible for external raters, or users with read or visible permission N...
canAccessInfoScreen()
Can access info screen: This is possible for external raters, or users with read or visible permissio...
canReadResultOfParticipants(?array $a_finished_ids=null)
Gets all participants or a subset of participants (by run ids) where the current user can access the ...
canAccessEvaluation()
Can access evaluation.
checkRbacOrPositionPermission(string $a_rbac_permission, string $a_position_permission)
isCodeInputAllowed()
Is it possible to take the survey by providing an access code?
__construct(InternalDomainService $domain_service, \ilAccessHandler $access, int $ref_id, int $user_id)
static _hasEvaluationAccess(int $a_obj_id, int $user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkRbacOrPositionPermissionAccess(string $rbac_perm, string $pos_perm, int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...