ILIAS  release_8 Revision v8.24
class.ilObjSurveyAccess.php
Go to the documentation of this file.
1<?php
2
26{
27 protected ilObjUser $user;
28 protected ilLanguage $lng;
31
32 public function __construct()
33 {
34 global $DIC;
35
36 $this->user = $DIC->user();
37 $this->lng = $DIC->language();
38 $this->rbacsystem = $DIC->rbac()->system();
39 $this->access = $DIC->access();
40 }
41
42
43 public static function getConditionOperators(): array
44 {
45 return array(
47 );
48 }
49
50 public static function checkCondition(int $a_trigger_obj_id, string $a_operator, string $a_value, int $a_usr_id): bool
51 {
52 switch ($a_operator) {
54 if (self::_lookupFinished($a_trigger_obj_id, $a_usr_id)) {
55 return true;
56 } else {
57 return false;
58 }
59
60 // no break
61 default:
62 return true;
63 }
64 }
65
66 public function _checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id = null): bool
67 {
71 $ilAccess = $this->access;
72
73 if (is_null($user_id)) {
74 $user_id = $ilUser->getId();
75 }
76
77 $is_admin = $rbacsystem->checkAccessOfUser($user_id, 'write', $ref_id);
78
79 switch ($permission) {
80 case "visible":
81 case "read":
82 if (!self::_lookupCreationComplete($obj_id) &&
83 !$is_admin) {
84 $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("warning_survey_not_complete"));
85 return false;
86 }
87 break;
88 }
89
90 switch ($cmd) {
91 case "run":
92 if (!self::_lookupCreationComplete($obj_id)) {
93 $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("warning_survey_not_complete"));
94 return false;
95 }
96 break;
97
98 case "evaluation":
99 if (!self::_lookupCreationComplete($obj_id)) {
100 $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("warning_survey_not_complete"));
101 return false;
102 }
103 if ($rbacsystem->checkAccess("write", $ref_id) || self::_hasEvaluationAccess($obj_id, $user_id)) {
104 return true;
105 } else {
106 $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("status_no_permission"));
107 return false;
108 }
109 }
110
111 return true;
112 }
113
114
115 public static function _getCommands(): array
116 {
117 $commands = array(
118 array("permission" => "read", "cmd" => "infoScreen", "lang_var" => "svy_run", "default" => true),
119 array("permission" => "write", "cmd" => "questions", "lang_var" => "edit_questions"),
120 array("permission" => "write", "cmd" => "properties", "lang_var" => "settings"),
121 array("permission" => "read", "cmd" => "evaluation", "lang_var" => "svy_results")
122 );
123
124 return $commands;
125 }
126
127 //
128 // object specific access related methods
129 //
130
134 public static function _lookupCreationComplete(int $a_obj_id): bool
135 {
136 global $DIC;
137
138 $ilDB = $DIC->database();
139
140 $result = $ilDB->queryF(
141 "SELECT * FROM svy_svy WHERE obj_fi=%s",
142 array('integer'),
143 array($a_obj_id)
144 );
145
146 $row = null;
147 if ($result->numRows() === 1) {
148 $row = $ilDB->fetchAssoc($result);
149 }
150 if (is_null($row) || !$row["complete"]) {
151 return false;
152 }
153 return true;
154 }
155
159 public static function _lookupEvaluationAccess(int $a_obj_id): int
160 {
161 global $DIC;
162
163 $ilDB = $DIC->database();
164
165 $result = $ilDB->queryF(
166 "SELECT * FROM svy_svy WHERE obj_fi=%s",
167 array('integer'),
168 array($a_obj_id)
169 );
170 if ($result->numRows() === 1) {
171 $row = $ilDB->fetchAssoc($result);
172 return (int) $row["evaluation_access"];
173 }
174 return 0;
175 }
176
177 public static function _isSurveyParticipant(
178 int $user_id,
179 int $survey_id
180 ): bool {
181 global $DIC;
182
183 $ilDB = $DIC->database();
184
185 $result = $ilDB->queryF(
186 "SELECT finished_id FROM svy_finished WHERE user_fi = %s AND survey_fi = %s",
187 array('integer','integer'),
188 array($user_id, $survey_id)
189 );
190 return $result->numRows() === 1;
191 }
192
193 public static function _lookupAnonymize(
194 int $a_obj_id
195 ): bool {
196 global $DIC;
197
198 $ilDB = $DIC->database();
199
200 $result = $ilDB->queryF(
201 "SELECT anonymize FROM svy_svy WHERE obj_fi = %s",
202 array('integer'),
203 array($a_obj_id)
204 );
205 if ($result->numRows() === 1) {
206 $row = $ilDB->fetchAssoc($result);
207 return (bool) $row["anonymize"];
208 } else {
209 return false;
210 }
211 }
212
213 public static function _hasEvaluationAccess(
214 int $a_obj_id,
215 int $user_id
216 ): bool {
217 $evaluation_access = self::_lookupEvaluationAccess($a_obj_id);
218 $svy_mode = self::_lookupMode($a_obj_id);
219
220 if ($svy_mode === ilObjSurvey::MODE_IND_FEEDB) {
221 $svy = new ilObjSurvey($a_obj_id, false);
222 $svy->read();
223 switch ($svy->get360Results()) {
226 return false;
227
229 return true;
230
231 // not applicable
232 }
233 }
234
235 switch ($evaluation_access) {
236 case 0:
237 // no evaluation access
238 return false;
239 case 1:
240 // evaluation access for all registered users
241 return ($user_id > 0) && ($user_id !== ANONYMOUS_USER_ID);
242 case 2:
243 switch ($svy_mode) {
245 $svy = new ilObjSurvey($a_obj_id, false);
246 $svy->read();
247 switch ($svy->get360Results()) {
249 return false;
250
252 return $svy->isAppraiseeClosed($user_id);
253
255 return $svy->isAppraisee($user_id);
256 }
257 break;
258
260 $svy = new ilObjSurvey($a_obj_id, false);
261 $svy->read();
262 switch ($svy->get360Results()) {
264 return false;
265
267 return true;
268
270 return $svy->isAppraisee($user_id);
271 }
272 break;
273
275 $svy = new ilObjSurvey($a_obj_id, false);
276 $svy->read();
277 switch ($svy->getSelfEvaluationResults()) {
279 return false;
280 default:
281 return true;
282 }
283
284 // no break
285 default:
286 // evaluation access for participants
287 // check if the user with the given id is a survey participant
288
289 // show the evaluation button for anonymized surveys for all users
290 // access is only granted with the survey access code
291 if (self::_lookupAnonymize($a_obj_id)) {
292 return true;
293 }
294
295 global $DIC;
296
297 $ilDB = $DIC->database();
298 $result = $ilDB->queryF(
299 "SELECT survey_id FROM svy_svy WHERE obj_fi = %s",
300 array('integer'),
301 array($a_obj_id)
302 );
303 if ($result->numRows() === 1) {
304 $row = $ilDB->fetchAssoc($result);
305
306 if (self::_isSurveyParticipant($user_id, $row["survey_id"])) {
307 return true;
308 }
309 }
310 return false;
311 }
312 }
313 return false;
314 }
315
316
322 public static function _lookupFinished(
323 int $a_obj_id,
324 int $a_user_id = 0
325 ): int {
326 global $DIC;
327
328 $ilDB = $DIC->database();
329 $ilUser = $DIC->user();
330
331 $finished = 0;
332 if ($a_user_id === 0) {
333 $a_user_id = $ilUser->getId();
334 }
335
336 $result = $ilDB->queryF(
337 "SELECT * FROM svy_svy WHERE obj_fi = %s",
338 array('integer'),
339 array($a_obj_id)
340 );
341 if ($result->numRows() === 1) {
342 $row = $ilDB->fetchObject($result);
343 if ((int) $row->anonymize === 1) {
344 $result = $ilDB->queryF(
345 "SELECT * FROM svy_finished, svy_anonymous WHERE svy_finished.survey_fi = %s " .
346 "AND svy_finished.survey_fi = svy_anonymous.survey_fi AND svy_anonymous.user_key = %s " .
347 "AND svy_anonymous.survey_key = svy_finished.anonymous_id",
348 array('integer','text'),
349 array($row->survey_id, md5($a_user_id))
350 );
351 } else {
352 $result = $ilDB->queryF(
353 "SELECT * FROM svy_finished WHERE survey_fi = %s AND user_fi = %s",
354 array('integer','integer'),
355 array($row->survey_id, $a_user_id)
356 );
357 }
358 if ($result->numRows() === 1) {
359 $foundrow = $ilDB->fetchAssoc($result);
360 $finished = (int) $foundrow["state"];
361 }
362 }
363
364 return $finished;
365 }
366
370 public static function _lookupMode(
371 int $a_obj_id
372 ): int {
373 global $DIC;
374 $ilDB = $DIC->database();
375
376 $result = $ilDB->queryF(
377 "SELECT mode FROM svy_svy" .
378 " WHERE obj_fi = %s",
379 array('integer'),
380 array($a_obj_id)
381 );
382
383 if ($result->numRows() === 1) {
384 $row = $ilDB->fetchAssoc($result);
385 return (int) $row["mode"];
386 }
387
388 return 0;
389 }
390
391 public static function _lookup360Mode(
392 int $a_obj_id
393 ): bool {
394 global $DIC;
395
396 $ilDB = $DIC->database();
397
398 $result = $ilDB->queryF(
399 "SELECT mode FROM svy_svy" .
400 " WHERE obj_fi = %s AND mode = %s",
401 array('integer','integer'),
402 array($a_obj_id, ilObjSurvey::MODE_360)
403 );
404 return (bool) $ilDB->numRows($result);
405 }
406
410 public static function _checkGoto(string $target): bool
411 {
412 global $DIC;
413
414 $request = $DIC->survey()
415 ->internal()
416 ->gui()
417 ->execution()
418 ->request();
419
420 $ilAccess = $DIC->access();
421
422 $t_arr = explode("_", $target);
423 if ($t_arr[0] !== "svy" || ((int) $t_arr[1]) <= 0) {
424 return false;
425 }
426
427 // 360° external raters
428 $access_code = ($request->getAccessCode() !== "")
429 ? $request->getAccessCode()
430 : ($t_arr[2] ?? "");
431 if ($access_code !== "") {
432 $survey = new ilObjSurvey((int) $t_arr[1]);
433 $run_manager = $DIC->survey()->internal()->domain()->execution()->run($survey, $DIC->user()->getId());
434 try {
435 $run_manager->initSession($access_code);
436 } catch (Exception $e) {
437 return false;
438 }
439 if (ilObjSurvey::validateExternalRaterCode((int) $t_arr[1], $access_code)) {
440 return true;
441 }
442 }
443
444 if ($ilAccess->checkAccess("visible", "", $t_arr[1]) ||
445 $ilAccess->checkAccess("read", "", $t_arr[1])) {
446 return true;
447 }
448 return false;
449 }
450}
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
_checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id=null)
Checks whether a user may invoke a command or not (this method is called by ilAccessHandler::checkAcc...
static _lookupAnonymize(int $a_obj_id)
static _checkGoto(string $target)
check whether goto script will succeed
static _lookupMode(int $a_obj_id)
Get survey mode (see ilObjSurvey::MODE_... constants)
static _lookupFinished(int $a_obj_id, int $a_user_id=0)
get finished status
static _lookup360Mode(int $a_obj_id)
static getConditionOperators()
Returns an array with valid operators for the specific object type.
static _getCommands()
get commands
static _lookupEvaluationAccess(int $a_obj_id)
get evaluation access
static _isSurveyParticipant(int $user_id, int $survey_id)
static _lookupCreationComplete(int $a_obj_id)
checks whether all necessary parts of the survey are given
static _hasEvaluationAccess(int $a_obj_id, int $user_id)
static checkCondition(int $a_trigger_obj_id, string $a_operator, string $a_value, int $a_usr_id)
check condition for a specific user and object
const RESULTS_SELF_EVAL_NONE
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
checkAccess(string $a_operations, int $a_ref_id, string $a_type="")
checkAccess represents the main method of the RBAC-system in ILIAS3 developers want to use With this ...
checkAccessOfUser(int $a_user_id, string $a_operations, int $a_ref_id, string $a_type="")
const ANONYMOUS_USER_ID
Definition: constants.php:27
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface for condition handling.
$ref_id
Definition: ltiauth.php:67