ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilObjTestAccess Class Reference

Class ilObjTestAccess. More...

+ Inheritance diagram for ilObjTestAccess:
+ Collaboration diagram for ilObjTestAccess:

Public Member Functions

 canBeDelivered (ilWACPath $ilWACPath)
 
 _checkAccess (string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id=null)
 Checks wether a user may invoke a command or not (this method is called by ilAccessHandler::checkAccess) More...
 
 showCertificateFor (int $user_id, int $obj_id)
 
 _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::checkAccess) More...
 
 canBeDelivered (ilWACPath $ilWACPath)
 
 canBeDelivered (ilWACPath $ilWACPath)
 

Static Public Member Functions

static getConditionOperators ()
 Get possible conditions operators. More...
 
static _getCommands ()
 get commands More...
 
static getBypassActivationCheckForPermissions ()
 
static _getTestIDFromObjectID (int $object_id)
 Returns the ILIAS test id for a given object id. More...
 
static _getRandomTestsForQuestionPool (int $qpl_id)
 Get all tests using a question pool for random selection. More...
 
static _getParticipantData (int $active_id)
 Retrieves a participant name from active id. More...
 
static _getParticipantId (int $active_id)
 Get user id for active id. More...
 
static _checkGoto (string $target)
 check whether goto script will succeed More...
 
static _isOffline (int $obj_id)
 returns the objects's OFFline status More...
 
static visibleUserResultExists (int $test_obj_id, int $user_id)
 
static _preloadData (array $obj_ids, array $ref_ids)
 Preload data. More...
 
static _getCommands ()
 get commands More...
 
static _checkGoto (string $target)
 check whether goto script will succeed More...
 
static _isOffline (int $obj_id)
 Type-specific implementation of general status, has to be overwritten if object type does not support centralized offline handling. More...
 
static _preloadData (array $obj_ids, array $ref_ids)
 Preload data. More...
 
- Static Public Member Functions inherited from ilConditionHandling
static getConditionOperators ()
 Returns an array with valid operators for the specific object type. More...
 
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 More...
 

Private Member Functions

 findMatch (string $path, array $array)
 

Static Private Member Functions

static lookupCreationComplete (int $a_obj_id)
 
static deserializePercentageThresholds (string $value)
 

Private Attributes

ilDBInterface $db
 
ilObjUser $user
 
ilLanguage $lng
 
ilRbacSystem $rbac_system
 
ilAccessHandler $access
 

Static Private Attributes

static ilCertificateObjectsForUserPreloader $certificate_preloader = null
 
static array $settings_result_summaries_by_obj_id = []
 

Detailed Description

Class ilObjTestAccess.

This class contains methods that check object specific conditions for accessing test objects.

Author
Helmut Schottmueller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

\

Definition at line 44 of file class.ilObjTestAccess.php.

Member Function Documentation

◆ _checkAccess()

ilObjTestAccess::_checkAccess ( string  $cmd,
string  $permission,
int  $ref_id,
int  $obj_id,
?int  $user_id = null 
)

Checks wether a user may invoke a command or not (this method is called by ilAccessHandler::checkAccess)

Please do not check any preconditions handled by ilConditionHandler here.

Reimplemented from ilObjectAccess.

Definition at line 93 of file class.ilObjTestAccess.php.

93 : bool
94 {
95 if (is_null($user_id)) {
96 $user_id = $this->user->getId();
97 }
98
99 $is_admin = $this->rbac_system->checkAccessOfUser($user_id, 'write', $ref_id)
100 || $this->rbac_system->checkAccessOfUser($user_id, 'score_anon', $ref_id);
101
102 $is_online = !ilObject::lookupOfflineStatus($obj_id);
103
104 if (!$is_admin && !$is_online) {
105 return false;
106 }
107
108 switch ($permission) {
109 case 'visible':
110 case 'read':
112 !$is_admin) {
113 $this->access->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $this->lng->txt('tst_warning_test_not_complete'));
114 return false;
115 }
116 break;
117 }
118
119 switch ($cmd) {
120 case 'eval_stat':
122 $this->access->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $this->lng->txt('tst_warning_test_not_complete'));
123 return false;
124 }
125 break;
126 }
127
128 return true;
129 }
static lookupCreationComplete(int $a_obj_id)
static lookupOfflineStatus(int $obj_id)
Lookup offline status using objectDataCache.

References $user_id, ILIAS\Repository\access(), ilAccessInfo\IL_NO_OBJECT_ACCESS, ILIAS\Repository\lng(), lookupCreationComplete(), ilObject\lookupOfflineStatus(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ _checkGoto()

static ilObjTestAccess::_checkGoto ( string  $target)
static

check whether goto script will succeed

Reimplemented from ilObjectAccess.

Definition at line 367 of file class.ilObjTestAccess.php.

367 : bool
368 {
369 global $DIC;
370 $ilAccess = $DIC['ilAccess'];
371
372 $t_arr = explode('_', $target);
373
374 if ($t_arr[0] != 'tst' || ((int) $t_arr[1]) <= 0) {
375 return false;
376 }
377
378 if ($ilAccess->checkAccess('read', '', (int) $t_arr[1]) ||
379 $ilAccess->checkAccess('visible', '', (int) $t_arr[1])) {
380 return true;
381 }
382 return false;
383 }
global $DIC
Definition: shib_login.php:26

References $DIC, and ILIAS\Scripts\PHPStan\$target.

◆ _getCommands()

static ilObjTestAccess::_getCommands ( )
static

get commands

this method returns an array of all possible commands/permission combinations

example: $commands = array ( array("permission" => "read", "cmd" => "view", "lang_var" => "show"), array("permission" => "write", "cmd" => "edit", "lang_var" => "edit"), );

Returns
array{permission?:string, cmd?:string, lang_var?:string, default?:bool}[]

Reimplemented from ilObjectAccess.

Definition at line 185 of file class.ilObjTestAccess.php.

185 : array
186 {
187 global $DIC;
188 $DIC->language()->loadLanguageModule('assessment');
189 $DIC->language()->loadLanguageModule('qsts');
190
191 return [
192 [
193 'permission' => 'write',
194 'cmd' => 'questionsTabGateway',
195 'lang_var' => 'tst_edit_questions'
196 ],
197 [
198 'permission' => 'write',
199 'cmd' => 'ILIAS\Test\Settings\MainSettings\SettingsMainGUI::showForm',
200 'lang_var' => 'settings'
201 ],
202 [
203 'permission' => 'read',
204 'cmd' => 'ILIAS\Test\Presentation\TestScreenGUI::testScreen',
205 'lang_var' => 'tst_run',
206 'default' => true
207 ],
208 [
209 'permission' => 'score_anon',
210 'cmd' => 'ILIAS\Test\Scoring\Manual\ConsecutiveScoringGUI::view',
211 'lang_var' => 'manscoring'
212 ],
213 ];
214 }

References $DIC.

Referenced by ilObjTestListGUI\init().

+ Here is the caller graph for this function:

◆ _getParticipantData()

static ilObjTestAccess::_getParticipantData ( int  $active_id)
static

Retrieves a participant name from active id.

Parameters
integer$active_idActive ID of the participant
Returns
string The output name of the user @access public

Definition at line 299 of file class.ilObjTestAccess.php.

299 : string
300 {
301 global $DIC;
302 $lng = $DIC['lng'];
303 $ilDB = $DIC['ilDB'];
304
305 $result_active = $ilDB->queryF(
306 'SELECT * FROM tst_active WHERE active_id = %s',
308 [$active_id]
309 );
310 $row_active = $ilDB->fetchAssoc($result_active);
311 $importname = $row_active['importname'];
312
313 if ($importname !== null
314 && $importname !== '') {
315 return $importname . ' (' . $lng->txt('imported') . ')';
316 }
317
318 if ($row_active['user_fi'] === ANONYMOUS_USER_ID) {
319 return '';
320 }
321
322 $uname = ilObjUser::_lookupName($row_active['user_fi']);
323
324 $result_test = $ilDB->queryF(
325 'SELECT obj_fi FROM tst_tests WHERE test_id = %s',
327 [$row_active['test_fi']]
328 );
329 $row_test = $ilDB->fetchAssoc($result_test);
330 $obj_id = $row_test['obj_fi'];
331
332 $test_obj = new ilObjTest($obj_id, false);
333 if ($test_obj->getAnonymity()) {
334 return $lng->txt('anonymous');
335 }
336
337 if ($uname['firstname'] . $uname['lastname'] === '') {
338 return $lng->txt('deleted_user');
339 }
340
341 return trim($uname['lastname'] . ', ' . $uname['firstname']);
342 }
txt(string|LanguageIdentifier $a_topic, ?int $n=null)
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _lookupName(int $a_user_id)
const ANONYMOUS_USER_ID
Definition: constants.php:27

References $DIC, $ilDB, $lng, ilObjUser\_lookupName(), ANONYMOUS_USER_ID, ilDBConstants\T_INTEGER, and ilLanguage\txt().

Referenced by ilTestParticipantList\buildFullname(), ilTestParticipantData\getFormatedFullnameByActiveId(), and ilTestParticipantData\getOptionArray().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getParticipantId()

static ilObjTestAccess::_getParticipantId ( int  $active_id)
static

Get user id for active id.

Parameters
intactive ID of the participant
Returns
int user id

Definition at line 350 of file class.ilObjTestAccess.php.

350 : int
351 {
352 global $DIC;
353 $ilDB = $DIC['ilDB'];
354
355 $result = $ilDB->queryF(
356 'SELECT user_fi FROM tst_active WHERE active_id = %s',
358 [$active_id]
359 );
360 $row = $ilDB->fetchAssoc($result);
361 return $row['user_fi'];
362 }

References $DIC, $ilDB, and ilDBConstants\T_INTEGER.

Referenced by ILIAS\Test\Scoring\Manual\ConsecutiveScoring\store(), and ilTestPassFinishTasks\updateLearningProgressAfterPassFinishedIsWritten().

+ Here is the caller graph for this function:

◆ _getRandomTestsForQuestionPool()

static ilObjTestAccess::_getRandomTestsForQuestionPool ( int  $qpl_id)
static

Get all tests using a question pool for random selection.

Parameters
intquestion pool id
Returns
array list if test obj ids @access public

Definition at line 271 of file class.ilObjTestAccess.php.

271 : array
272 {
273 global $DIC;
274 $ilDB = $DIC['ilDB'];
275
276 $query = 'SELECT DISTINCT t.obj_fi' . PHP_EOL
277 . 'FROM tst_tests t' . PHP_EOL
278 . 'INNER JOIN tst_rnd_quest_set_qpls r' . PHP_EOL
279 . 'ON t.test_id = r.test_fi' . PHP_EOL
280 . 'WHERE r.pool_fi = %s' . PHP_EOL;
281
282 $result = $ilDB->queryF($query, [ilDBConstants::T_INTEGER], [$qpl_id]);
283
284 $tests = [];
285 while ($row = $ilDB->fetchAssoc($result)) {
286 $tests[] = $row['obj_fi'];
287 }
288
289 return $tests;
290 }

References $DIC, $ilDB, and ilDBConstants\T_INTEGER.

◆ _getTestIDFromObjectID()

static ilObjTestAccess::_getTestIDFromObjectID ( int  $object_id)
static

Returns the ILIAS test id for a given object id.

Parameters
integer$object_idThe object id
Returns
mixed The ILIAS test id or FALSE if the query was not successful @access public

Definition at line 247 of file class.ilObjTestAccess.php.

247 : int|false
248 {
249 global $DIC;
250 $ilDB = $DIC['ilDB'];
251 $test_id = false;
252 $result = $ilDB->queryF(
253 'SELECT test_id FROM tst_tests WHERE obj_fi = %s',
255 [$object_id]
256 );
257 if ($result->numRows()) {
258 $row = $ilDB->fetchAssoc($result);
259 $test_id = $row['test_id'];
260 }
261 return $test_id;
262 }

References $DIC, $ilDB, and ilDBConstants\T_INTEGER.

Referenced by ilLPStatusTestFinished\getParticipants(), and ilSoapTestAdministration\getTestAccess().

+ Here is the caller graph for this function:

◆ _isOffline()

static ilObjTestAccess::_isOffline ( int  $obj_id)
static

returns the objects's OFFline status

Used in ListGUI and Learning Progress

Reimplemented from ilObjectAccess.

Definition at line 390 of file class.ilObjTestAccess.php.

390 : bool
391 {
392 return ilObject::lookupOfflineStatus($obj_id);
393 }

References ilObject\lookupOfflineStatus().

Referenced by ilLOEditorStatus\checkTestOnline().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _preloadData()

static ilObjTestAccess::_preloadData ( array  $obj_ids,
array  $ref_ids 
)
static

Preload data.

Reimplemented from ilObjectAccess.

Definition at line 414 of file class.ilObjTestAccess.php.

414 : void
415 {
416 global $DIC;
417 if ((new ilCertificateActiveValidator())->validate()) {
418 self::$certificate_preloader = new ilCertificateObjectsForUserPreloader(new ilUserCertificateRepository());
419 self::$certificate_preloader->preLoad($DIC['ilUser']->getId(), $obj_ids);
420 self::$settings_result_summaries_by_obj_id = TestDIC::dic()['settings.scoring.repository']
421 ->getSettingsResultSummaryByObjIds($obj_ids);
422 }
423 }

References $DIC, and ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ canBeDelivered()

ilObjTestAccess::canBeDelivered ( ilWACPath  $ilWACPath)

Reimplemented from ilObjectAccess.

Definition at line 66 of file class.ilObjTestAccess.php.

66 : bool
67 {
68 $readable = new Readable($this->access);
69
70 $can_it = $this->findMatch($ilWACPath->getPath(), [
71 new AccessFileUploadAnswer($this->user, $this->db, $readable),
72 new AccessQuestionImage($readable),
73 new AccessFileUploadPreview($this->db, $this->access),
74 ]);
75
76 return !$can_it->isOk() || $can_it->value();
77 }
findMatch(string $path, array $array)

References ILIAS\Repository\access(), findMatch(), ilWACPath\getPath(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ deserializePercentageThresholds()

static ilObjTestAccess::deserializePercentageThresholds ( string  $value)
staticprivate
Returns
array{min_percentage: float, max_percentage: float}|false

Definition at line 451 of file class.ilObjTestAccess.php.

451 : array|false
452 {
453 $value_arr = unserialize($value);
454
455 if ($value_arr === false) {
456 return false;
457 }
458
459 return [
460 'min_percentage' => (float) ($value_arr['min_percentage'] ?? 0.0) / 100,
461 'max_percentage' => (float) ($value_arr['max_percentage'] ?? 0.0) / 100
462 ];
463 }

◆ findMatch()

ilObjTestAccess::findMatch ( string  $path,
array  $array 
)
private

Definition at line 79 of file class.ilObjTestAccess.php.

79 : Result
80 {
81 return array_reduce($array, fn(Result $result, SimpleAccess $access) => $result->except(
82 fn() => $access->isPermitted($path)
83 ), new Error('Not a known path.'));
84 }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Error.php:32
ilAccessHandler $access
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29
except(callable $f)
Feed the error into a callable and replace this with the result or do nothing if this is a value.

References $access, and ILIAS\Data\Result\except().

Referenced by canBeDelivered().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBypassActivationCheckForPermissions()

static ilObjTestAccess::getBypassActivationCheckForPermissions ( )
static

Definition at line 220 of file class.ilObjTestAccess.php.

220 : array
221 {
222 return [
223 'write',
224 'score_anon'
225 ];
226 }

◆ getConditionOperators()

◆ lookupCreationComplete()

static ilObjTestAccess::lookupCreationComplete ( int  $a_obj_id)
staticprivate

Definition at line 228 of file class.ilObjTestAccess.php.

228 : bool
229 {
230 global $DIC;
231 $db = $DIC->database();
232 $result = $db->queryF(
233 'SELECT complete FROM tst_tests WHERE obj_fi=%s',
235 [$a_obj_id]
236 );
237 return $result->numRows() > 0 && (bool) $db->fetchAssoc($result)['complete'];
238 }
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)

References $db, $DIC, ilDBInterface\fetchAssoc(), ilDBInterface\queryF(), and ilDBConstants\T_INTEGER.

Referenced by _checkAccess().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showCertificateFor()

ilObjTestAccess::showCertificateFor ( int  $user_id,
int  $obj_id 
)

Definition at line 425 of file class.ilObjTestAccess.php.

425 : bool
426 {
427 if (self::$certificate_preloader === null
428 || !self::$certificate_preloader->isPreloaded($user_id, $obj_id)
429 || !isset(self::$settings_result_summaries_by_obj_id[$obj_id])
430 || self::$settings_result_summaries_by_obj_id[$obj_id]->getScoreReporting()
431 === ScoreReportingTypes::SCORE_REPORTING_DISABLED) {
432 return false;
433 }
434
435 $score_reporting = self::$settings_result_summaries_by_obj_id[$obj_id]->getScoreReporting();
436 if ($score_reporting === ScoreReportingTypes::SCORE_REPORTING_IMMIDIATLY) {
437 return true;
438 }
439
440 if ($score_reporting === ScoreReportingTypes::SCORE_REPORTING_DATE
441 && self::$settings_result_summaries_by_obj_id[$obj_id]->getReportingDate() < new \DateTimeImmutable('now', new DateTimeZone('UTC'))) {
442 return true;
443 }
444
445 return false;
446 }

References $user_id.

◆ visibleUserResultExists()

static ilObjTestAccess::visibleUserResultExists ( int  $test_obj_id,
int  $user_id 
)
static

Definition at line 396 of file class.ilObjTestAccess.php.

396 : bool
397 {
398 global $DIC;
399 $ilDB = $DIC['ilDB'];
400 $ilUser = $DIC['ilUser'];
401
402 $test_obj = ilObjectFactory::getInstanceByObjId($test_obj_id, false);
403
404 if (!($test_obj instanceof ilObjTest)) {
405 return false;
406 }
407
408 $test_session_factory = new ilTestSessionFactory($test_obj, $ilDB, $ilUser);
409 $test_session = $test_session_factory->getSessionByUserId($user_id);
410
411 return $test_obj->canShowTestResults($test_session);
412 }
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id

References $DIC, $ilDB, $user_id, and ilObjectFactory\getInstanceByObjId().

Referenced by ilLOUtils\getTestResultLinkForUser().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $access

ilAccessHandler ilObjTestAccess::$access
private

Definition at line 50 of file class.ilObjTestAccess.php.

Referenced by findMatch().

◆ $certificate_preloader

ilCertificateObjectsForUserPreloader ilObjTestAccess::$certificate_preloader = null
staticprivate

Definition at line 52 of file class.ilObjTestAccess.php.

◆ $db

ilDBInterface ilObjTestAccess::$db
private

Definition at line 46 of file class.ilObjTestAccess.php.

Referenced by lookupCreationComplete().

◆ $lng

ilLanguage ilObjTestAccess::$lng
private

Definition at line 48 of file class.ilObjTestAccess.php.

Referenced by _getParticipantData().

◆ $rbac_system

ilRbacSystem ilObjTestAccess::$rbac_system
private

Definition at line 49 of file class.ilObjTestAccess.php.

◆ $settings_result_summaries_by_obj_id

array ilObjTestAccess::$settings_result_summaries_by_obj_id = []
staticprivate

Definition at line 53 of file class.ilObjTestAccess.php.

◆ $user

ilObjUser ilObjTestAccess::$user
private

Definition at line 47 of file class.ilObjTestAccess.php.


The documentation for this class was generated from the following file: