ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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.
$ref_id
Definition: ltiauth.php:66

References $ref_id, $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 366 of file class.ilObjTestAccess.php.

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

References $DIC.

◆ _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
190 return [
191 [
192 'permission' => 'write',
193 'cmd' => 'questionsTabGateway',
194 'lang_var' => 'tst_edit_questions'
195 ],
196 [
197 'permission' => 'write',
198 'cmd' => 'ILIAS\Test\Settings\MainSettings\SettingsMainGUI::showForm',
199 'lang_var' => 'settings'
200 ],
201 [
202 'permission' => 'read',
203 'cmd' => 'ILIAS\Test\Presentation\TestScreenGUI::testScreen',
204 'lang_var' => 'tst_run',
205 'default' => true
206 ],
207 [
208 'permission' => 'score_anon',
209 'cmd' => 'ILIAS\Test\Scoring\Manual\ConsecutiveScoringGUI::view',
210 'lang_var' => 'manscoring'
211 ],
212 ];
213 }
return true

References $DIC, and true.

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 298 of file class.ilObjTestAccess.php.

298 : string
299 {
300 global $DIC;
301 $lng = $DIC['lng'];
302 $ilDB = $DIC['ilDB'];
303
304 $result_active = $ilDB->queryF(
305 'SELECT * FROM tst_active WHERE active_id = %s',
307 [$active_id]
308 );
309 $row_active = $ilDB->fetchAssoc($result_active);
310 $importname = $row_active['importname'];
311
312 if ($importname !== null
313 && $importname !== '') {
314 return $importname . ' (' . $lng->txt('imported') . ')';
315 }
316
317 if ($row_active['user_fi'] === ANONYMOUS_USER_ID) {
318 return '';
319 }
320
321 $uname = ilObjUser::_lookupName($row_active['user_fi']);
322
323 $result_test = $ilDB->queryF(
324 'SELECT obj_fi FROM tst_tests WHERE test_id = %s',
326 [$row_active['test_fi']]
327 );
328 $row_test = $ilDB->fetchAssoc($result_test);
329 $obj_id = $row_test['obj_fi'];
330
331 $test_obj = new ilObjTest($obj_id, false);
332 if ($test_obj->getAnonymity()) {
333 return $lng->txt('anonymous');
334 }
335
336 if ($uname['firstname'] . $uname['lastname'] === '') {
337 return $lng->txt('deleted_user');
338 }
339
340 return trim($uname['lastname'] . ', ' . $uname['firstname']);
341 }
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...
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 349 of file class.ilObjTestAccess.php.

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

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 270 of file class.ilObjTestAccess.php.

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

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 246 of file class.ilObjTestAccess.php.

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

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 389 of file class.ilObjTestAccess.php.

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

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 413 of file class.ilObjTestAccess.php.

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

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 450 of file class.ilObjTestAccess.php.

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

◆ 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.
$path
Definition: ltiservices.php:30

References $access, $path, 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 219 of file class.ilObjTestAccess.php.

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

◆ getConditionOperators()

◆ lookupCreationComplete()

static ilObjTestAccess::lookupCreationComplete ( int  $a_obj_id)
staticprivate

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

227 : bool
228 {
229 global $DIC;
230 $db = $DIC->database();
231 $result = $db->queryF(
232 'SELECT complete FROM tst_tests WHERE obj_fi=%s',
234 [$a_obj_id]
235 );
236 return $result->numRows() > 0 && (bool) $db->fetchAssoc($result)['complete'];
237 }
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 424 of file class.ilObjTestAccess.php.

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

References $user_id.

◆ visibleUserResultExists()

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

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

395 : bool
396 {
397 global $DIC;
398 $ilDB = $DIC['ilDB'];
399 $ilUser = $DIC['ilUser'];
400
401 $test_obj = ilObjectFactory::getInstanceByObjId($test_obj_id, false);
402
403 if (!($test_obj instanceof ilObjTest)) {
404 return false;
405 }
406
407 $test_session_factory = new ilTestSessionFactory($test_obj, $ilDB, $ilUser);
408 $test_session = $test_session_factory->getSessionByUserId($user_id);
409
410 return $test_obj->canShowTestResults($test_session);
411 }
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: