ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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)
 

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

94 : bool
95 {
96 if (is_null($user_id)) {
97 $user_id = $this->user->getId();
98 }
99
100 $is_admin = $this->rbac_system->checkAccessOfUser($user_id, 'write', $ref_id)
101 || $this->rbac_system->checkAccessOfUser($user_id, 'score_anon', $ref_id);
102
103 $is_online = !ilObject::lookupOfflineStatus($obj_id);
104
105 if (!$is_admin && !$is_online) {
106 return false;
107 }
108
109 switch ($permission) {
110 case "visible":
111 case "read":
113 !$is_admin) {
114 $this->access->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $this->lng->txt("tst_warning_test_not_complete"));
115 return false;
116 }
117 break;
118 }
119
120 switch ($cmd) {
121 case "eval_stat":
123 $this->access->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $this->lng->txt("tst_warning_test_not_complete"));
124 return false;
125 }
126 break;
127 }
128
129 return true;
130 }
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 339 of file class.ilObjTestAccess.php.

339 : bool
340 {
341 global $DIC;
342 $ilAccess = $DIC['ilAccess'];
343
344 $t_arr = explode("_", $target);
345
346 if ($t_arr[0] != "tst" || ((int) $t_arr[1]) <= 0) {
347 return false;
348 }
349
350 if ($ilAccess->checkAccess("read", "", (int) $t_arr[1]) ||
351 $ilAccess->checkAccess("visible", "", (int) $t_arr[1])) {
352 return true;
353 }
354 return false;
355 }
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 174 of file class.ilObjTestAccess.php.

174 : array
175 {
176 global $DIC;
177 $DIC->language()->loadLanguageModule('assessment');
178
179 return [
180 ["permission" => "write", "cmd" => "questionsTabGateway", "lang_var" => "tst_edit_questions"],
181 ["permission" => "write", "cmd" => "ILIAS\Test\Settings\MainSettings\SettingsMainGUI::showForm", "lang_var" => "settings"],
182 ["permission" => "read", "cmd" => "ILIAS\Test\Presentation\TestScreenGUI::testScreen", "lang_var" => "tst_run", "default" => true],
183 ["permission" => "score_anon", "cmd" => "ILIAS\Test\Scoring\Manual\TestScoringByQuestionGUI::showManScoringByQuestionParticipantsTable", "lang_var" => "manscoring", "default" => true],
184 ];
185 }

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

272 : string
273 {
274 global $DIC;
275 $lng = $DIC['lng'];
276 $ilDB = $DIC['ilDB'];
277
278 $result_active = $ilDB->queryF(
279 'SELECT * FROM tst_active WHERE active_id = %s',
280 ['integer'],
281 [$active_id]
282 );
283 $row_active = $ilDB->fetchAssoc($result_active);
284 $importname = $row_active['importname'];
285
286 if ($importname !== null
287 && $importname !== '') {
288 return $importname . ' (' . $lng->txt('imported') . ')';
289 }
290
291 if ($row_active['user_fi'] === ANONYMOUS_USER_ID) {
292 return '';
293 }
294
295 $uname = ilObjUser::_lookupName($row_active['user_fi']);
296
297 $result_test = $ilDB->queryF(
298 "SELECT obj_fi FROM tst_tests WHERE test_id = %s",
299 ["integer"],
300 [$row_active['test_fi']]
301 );
302 $row_test = $ilDB->fetchAssoc($result_test);
303 $obj_id = $row_test["obj_fi"];
304
305 if (ilObjTest::_lookupAnonymity($obj_id)) {
306 return $lng->txt("anonymous");
307 }
308
309 if ($uname['firstname'] . $uname['lastname'] === '') {
310 return $lng->txt('deleted_user');
311 }
312
313 return trim($uname['lastname'] . ', ' . $uname['firstname']);
314 }
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 _lookupAnonymity($a_obj_id)
static _lookupName(int $a_user_id)
const ANONYMOUS_USER_ID
Definition: constants.php:27

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

Referenced by ilTestParticipantList\buildParticipantsFullname(), ilTestResultsToXML\exportActiveIDs(), 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 322 of file class.ilObjTestAccess.php.

322 : int
323 {
324 global $DIC;
325 $ilDB = $DIC['ilDB'];
326
327 $result = $ilDB->queryF(
328 'SELECT user_fi FROM tst_active WHERE active_id = %s',
329 ['integer'],
330 [$active_id]
331 );
332 $row = $ilDB->fetchAssoc($result);
333 return $row['user_fi'];
334 }

References $DIC, and $ilDB.

Referenced by ILIAS\Test\Scoring\Manual\TestScoringByQuestionGUI\saveManScoringByQuestion(), ILIAS\Test\Scoring\Manual\TestScoringByParticipantGUI\saveManScoringParticipantScreen(), 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 242 of file class.ilObjTestAccess.php.

242 : array
243 {
244 global $DIC;
245 $ilDB = $DIC['ilDB'];
246
247 $query = "
248 SELECT DISTINCT t.obj_fi
249 FROM tst_tests t
250 INNER JOIN tst_rnd_quest_set_qpls r
251 ON t.test_id = r.test_fi
252 WHERE r.pool_fi = %s
253 ";
254
255 $result = $ilDB->queryF($query, ['integer'], [$qpl_id]);
256
257 $tests = [];
258 while ($row = $ilDB->fetchAssoc($result)) {
259 $tests[] = $row['obj_fi'];
260 }
261
262 return $tests;
263 }

References $DIC, and $ilDB.

◆ _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 218 of file class.ilObjTestAccess.php.

218 : int|false
219 {
220 global $DIC;
221 $ilDB = $DIC['ilDB'];
222 $test_id = false;
223 $result = $ilDB->queryF(
224 "SELECT test_id FROM tst_tests WHERE obj_fi = %s",
225 ['integer'],
226 [$object_id]
227 );
228 if ($result->numRows()) {
229 $row = $ilDB->fetchAssoc($result);
230 $test_id = $row["test_id"];
231 }
232 return $test_id;
233 }

References $DIC, and $ilDB.

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

362 : bool
363 {
364 return ilObject::lookupOfflineStatus($obj_id);
365 }

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

386 : void
387 {
388 global $DIC;
389 if ((new ilCertificateActiveValidator())->validate()) {
390 self::$certificate_preloader = new ilCertificateObjectsForUserPreloader(new ilUserCertificateRepository());
391 self::$certificate_preloader->preLoad($DIC['ilUser']->getId(), $obj_ids);
392 self::$settings_result_summaries_by_obj_id = (new ScoreSettingsDatabaseRepository($DIC['ilDB']))
393 ->getSettingsResultSummaryByObjIds($obj_ids);
394 }
395 }

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

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

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

+ Here is the call graph for this function:

◆ findMatch()

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

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

80 : Result
81 {
82 return array_reduce($array, fn(Result $result, SimpleAccess $access) => $result->except(
83 fn() => $access->isPermitted($path)
84 ), new Error('Not a known path.'));
85 }
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 191 of file class.ilObjTestAccess.php.

191 : array
192 {
193 return [
194 'write',
195 'score_anon'
196 ];
197 }

◆ getConditionOperators()

◆ lookupCreationComplete()

static ilObjTestAccess::lookupCreationComplete ( int  $a_obj_id)
staticprivate

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

199 : bool
200 {
201 global $DIC;
202 $db = $DIC->database();
203 $result = $db->queryF(
204 "SELECT complete FROM tst_tests WHERE obj_fi=%s",
205 ['integer'],
206 [$a_obj_id]
207 );
208 return $result->numRows() > 0 && (bool) $db->fetchAssoc($result)['complete'];
209 }
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)

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

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

397 : bool
398 {
399 if (self::$certificate_preloader === null
400 || !self::$certificate_preloader->isPreloaded($user_id, $obj_id)
401 || !isset(self::$settings_result_summaries_by_obj_id[$obj_id])
402 || self::$settings_result_summaries_by_obj_id[$obj_id]->getScoreReporting()
403 === ScoreReportingTypes::SCORE_REPORTING_DISABLED) {
404 return false;
405 }
406
407 $score_reporting = self::$settings_result_summaries_by_obj_id[$obj_id]->getScoreReporting();
408 if ($score_reporting === ScoreReportingTypes::SCORE_REPORTING_IMMIDIATLY) {
409 return true;
410 }
411
412 if ($score_reporting === ScoreReportingTypes::SCORE_REPORTING_DATE
413 && self::$settings_result_summaries_by_obj_id->getReportingDate() < new \DateTimeImmutable('now', new DateTimeZone('UTC'))) {
414 return true;
415 }
416
417 return false;
418 }

References $user_id.

◆ visibleUserResultExists()

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

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

368 : bool
369 {
370 global $DIC;
371 $ilDB = $DIC['ilDB'];
372 $ilUser = $DIC['ilUser'];
373
374 $test_obj = ilObjectFactory::getInstanceByObjId($test_obj_id, false);
375
376 if (!($test_obj instanceof ilObjTest)) {
377 return false;
378 }
379
380 $test_session_factory = new ilTestSessionFactory($test_obj, $ilDB, $ilUser);
381 $test_session = $test_session_factory->getSessionByUserId($user_id);
382
383 return $test_obj->canShowTestResults($test_session);
384 }
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 51 of file class.ilObjTestAccess.php.

Referenced by findMatch().

◆ $certificate_preloader

ilCertificateObjectsForUserPreloader ilObjTestAccess::$certificate_preloader = null
staticprivate

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

◆ $db

ilDBInterface ilObjTestAccess::$db
private

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

Referenced by lookupCreationComplete().

◆ $lng

ilLanguage ilObjTestAccess::$lng
private

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

Referenced by _getParticipantData().

◆ $rbac_system

ilRbacSystem ilObjTestAccess::$rbac_system
private

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

◆ $settings_result_summaries_by_obj_id

array ilObjTestAccess::$settings_result_summaries_by_obj_id = []
staticprivate

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

◆ $user

ilObjUser ilObjTestAccess::$user
private

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


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