ILIAS  release_8 Revision v8.24
class.ilTestInfoScreenToolbarGUI.php
Go to the documentation of this file.
1<?php
2
26{
27 private static array $TARGET_CLASS_PATH_BASE = array('ilRepositoryGUI', 'ilObjTestGUI');
28
29 protected \ILIAS\DI\Container $DIC;
31
32 protected ilDBInterface $db;
34 protected ilCtrl $ctrl;
36 private \ilGlobalTemplateInterface $main_tpl;
37
38 protected ?ilObjTest $testOBJ = null;
41 protected ?ilTestSession $testSession = null;
42
46 protected $testSequence;
47
52 private array $infoMessages = array();
53 private array $failureMessages = array();
54
55 public function __construct(
61 ) {
62 global $DIC;
63 $this->main_tpl = $DIC->ui()->mainTemplate(); /* @var ILIAS\DI\Container $DIC */
64 $this->DIC = $DIC;
65 $this->db = $db;
66 $this->access = $access;
67 $this->ctrl = $ctrl;
68 $this->lng = $lng;
69 $this->component_repository = $component_repository;
70 }
71
72 public function getGlobalToolbar(): ?ilToolbarGUI
73 {
75 }
76
78 {
79 $this->globalToolbar = $globalToolbar;
80 }
81
82 public function getTestOBJ(): ?ilObjTest
83 {
84 return $this->testOBJ;
85 }
86
87 public function setTestOBJ(ilObjTest $testOBJ): void
88 {
89 $this->testOBJ = $testOBJ;
90 }
91
93 {
95 }
96
98 {
99 $this->testQuestionSetConfig = $testQuestionSetConfig;
100 }
101
103 {
105 }
106
108 {
109 $this->testPlayerGUI = $testPlayerGUI;
110 }
111
112 public function getTestSession(): ?ilTestSession
113 {
114 return $this->testSession;
115 }
116
118 {
119 $this->testSession = $testSession;
120 }
121
125 public function getTestSequence()
126 {
127 return $this->testSequence;
128 }
129
133 public function setTestSequence($testSequence): void
134 {
135 $this->testSequence = $testSequence;
136 }
137
138 public function getSessionLockString(): ?string
139 {
141 }
142
144 {
145 $this->sessionLockString = $sessionLockString;
146 }
147
148 public function getInfoMessages(): array
149 {
150 return $this->infoMessages;
151 }
152
156 public function addInfoMessage($infoMessage): void
157 {
158 $this->infoMessages[] = $infoMessage;
159 }
160
161 public function getFailureMessages(): array
162 {
164 }
165
166 public function addFailureMessage(string $failureMessage): void
167 {
168 $this->failureMessages[] = $failureMessage;
169 }
170
171 public function setFormAction(
172 string $a_val,
173 bool $a_multipart = false,
174 string $a_target = ""
175 ): void {
176 if ($this->globalToolbar instanceof parent) {
177 $this->globalToolbar->setFormAction($a_val, $a_multipart, $a_target);
178 } else {
179 parent::setFormAction($a_val, $a_multipart, $a_target);
180 }
181 }
182
183 public function addButtonInstance(ilButtonBase $a_button): void
184 {
185 if ($this->globalToolbar instanceof parent) {
186 $this->globalToolbar->addButtonInstance($a_button);
187 } else {
188 parent::addButtonInstance($a_button);
189 }
190 }
191
192 public function setCloseFormTag(bool $a_val): void
193 {
194 if ($this->globalToolbar instanceof parent) {
195 $this->globalToolbar->setCloseFormTag($a_val);
196 } else {
197 parent::setCloseFormTag($a_val);
198 }
199 }
200
201 public function addInputItem(
202 ilToolbarItem $a_item,
203 bool $a_output_label = false
204 ): void {
205 if ($this->globalToolbar instanceof parent) {
206 $this->globalToolbar->addInputItem($a_item, $a_output_label);
207 } else {
208 parent::addInputItem($a_item, $a_output_label);
209 }
210 }
211
212 public function addFormInput($formInput): void
213 {
214 if ($this->globalToolbar instanceof parent) {
215 $this->globalToolbar->addFormInput($formInput);
216 }
217 }
218
219 public function clearItems(): void
220 {
221 if ($this->globalToolbar instanceof parent) {
222 $this->globalToolbar->setItems(array());
223 } else {
224 $this->setItems(array());
225 }
226 }
227
228 private function getClassName($target)
229 {
230 if (is_object($target)) {
231 $target = get_class($target);
232 }
233
234 return $target;
235 }
236
237 private function getClassNameArray($target): array
238 {
239 if (is_array($target)) {
240 return $target;
241 }
242
243 return array($this->getClassName($target));
244 }
245
246 private function getClassPath($target): array
247 {
248 return array_merge(self::$TARGET_CLASS_PATH_BASE, $this->getClassNameArray($target));
249 }
250
251 private function setParameter($target, $parameter, $value): void
252 {
253 $this->ctrl->setParameterByClass($this->getClassName($target), $parameter, $value);
254 }
255
256 private function buildLinkTarget($target, $cmd = null): string
257 {
258 return $this->ctrl->getLinkTargetByClass($this->getClassPath($target), $cmd);
259 }
260
261 private function buildFormAction($target): string
262 {
263 return $this->ctrl->getFormActionByClass($this->getClassPath($target));
264 }
265
266 private function ensureInitialisedSessionLockString(): void
267 {
268 if (!strlen($this->getSessionLockString())) {
269 $this->setSessionLockString($this->buildSessionLockString());
270 }
271 }
272
273 private function buildSessionLockString(): string
274 {
275 return md5($_COOKIE[session_name()] . time());
276 }
277
278 private function areSkillLevelThresholdsMissing(): bool
279 {
280 if (!$this->getTestOBJ()->isSkillServiceEnabled()) {
281 return false;
282 }
283
284 $questionContainerId = $this->getTestOBJ()->getId();
285
286 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignmentList.php';
287 require_once 'Modules/Test/classes/class.ilTestSkillLevelThreshold.php';
288
289 $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
290 $assignmentList->setParentObjId($questionContainerId);
291 $assignmentList->loadFromDb();
292
293 foreach ($assignmentList->getUniqueAssignedSkills() as $data) {
294 foreach ($data['skill']->getLevelData() as $level) {
295 $treshold = new ilTestSkillLevelThreshold($this->db);
296 $treshold->setTestId($this->getTestOBJ()->getTestId());
297 $treshold->setSkillBaseId($data['skill_base_id']);
298 $treshold->setSkillTrefId($data['skill_tref_id']);
299 $treshold->setSkillLevelId($level['id']);
300
301 if (!$treshold->dbRecordExists()) {
302 return true;
303 }
304 }
305 }
306
307 return false;
308 }
309
310 private function getSkillLevelThresholdsMissingInfo(): string
311 {
312 $message = $this->lng->txt('tst_skl_level_thresholds_missing');
313
314 $linkTarget = $this->buildLinkTarget(
315 array('ilTestSkillAdministrationGUI', 'ilTestSkillLevelThresholdsGUI'),
317 );
318
319 $link = $this->DIC->ui()->factory()->link()->standard(
320 $this->DIC->language()->txt('tst_skl_level_thresholds_link'),
321 $linkTarget
322 );
323
324 $msgBox = $this->DIC->ui()->factory()->messageBox()->failure($message)->withLinks(array($link));
325
326 return $this->DIC->ui()->renderer()->render($msgBox);
327 }
328
330 {
331 if (!$this->testOBJ->isFixedTest()) {
332 return false;
333 }
334
335 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignmentList.php';
336 $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
337 $assignmentList->setParentObjId($this->testOBJ->getId());
338 $assignmentList->loadFromDb();
339
340 return $assignmentList->hasSkillsAssignedLowerThanBarrier();
341 }
342
343 private function getSkillAssignBarrierInfo(): string
344 {
345 require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
346
347 return sprintf(
348 $this->lng->txt('tst_skill_triggerings_num_req_answers_not_reached_warn'),
350 );
351 }
352
353 public function build(): void
354 {
355 if (!$this->testOBJ->isDynamicTest()) {
356 $this->ensureInitialisedSessionLockString();
357
358 $this->setParameter($this->getTestPlayerGUI(), 'lock', $this->getSessionLockString());
359 $this->setParameter($this->getTestPlayerGUI(), 'sequence', $this->getTestSession()->getLastSequence());
360 $this->setParameter('ilObjTestGUI', 'ref_id', $this->getTestOBJ()->getRefId());
361
362 $this->setFormAction($this->buildFormAction($this->getTestPlayerGUI()));
363 }
364
365 $online_access = false;
366 if ($this->getTestOBJ()->getFixedParticipants()) {
367 include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
368 $online_access_result = ilObjTestAccess::_lookupOnlineTestAccess($this->getTestOBJ()->getId(), $this->getTestSession()->getUserId());
369 if ($online_access_result === true) {
370 $online_access = true;
371 } else {
372 $this->addInfoMessage($online_access_result);
373 }
374 }
375
376 if (!$this->getTestOBJ()->getOfflineStatus() && $this->getTestOBJ()->isComplete($this->getTestQuestionSetConfig())) {
377 if ((!$this->getTestOBJ()->getFixedParticipants() || $online_access) && $this->access->checkAccess("read", "", $this->getTestOBJ()->getRefId())) {
378 $executable = $this->getTestOBJ()->isExecutable(
379 $this->getTestSession(),
380 $this->getTestSession()->getUserId(),
381 $allowPassIncrease = true
382 );
383
384 if ($executable["executable"]) {
385 if ($this->getTestOBJ()->areObligationsEnabled() && $this->getTestOBJ()->hasObligations($this->getTestOBJ()->getTestId())) {
386 $this->addInfoMessage($this->lng->txt('tst_test_contains_obligatory_questions'));
387 }
388
389 if ($this->getTestSession()->getActiveId() > 0) {
390 // resume test
391 require_once 'Modules/Test/classes/class.ilTestPassesSelector.php';
392 $testPassesSelector = new ilTestPassesSelector($this->db, $this->getTestOBJ());
393 $testPassesSelector->setActiveId($this->getTestSession()->getActiveId());
394 $testPassesSelector->setLastFinishedPass($this->getTestSession()->getLastFinishedPass());
395
396 $closedPasses = $testPassesSelector->getClosedPasses();
397 $existingPasses = $testPassesSelector->getExistingPasses();
398
399 if ($existingPasses > $closedPasses) {
401 $btn->setCaption('tst_resume_test');
402 $btn->setCommand('resumePlayer');
403 $btn->setPrimary(true);
404 $this->addButtonInstance($btn);
405 } else {
407 $btn->setCaption($this->getTestOBJ()->getStartTestLabel($this->getTestSession()->getActiveId()), false);
408 $btn->setCommand('startPlayer');
409 $btn->setPrimary(true);
410 $this->addButtonInstance($btn);
411 }
412 } else {
413 // start new test
415 $btn->setCaption($this->getTestOBJ()->getStartTestLabel($this->getTestSession()->getActiveId()), false);
416 $btn->setCommand('startPlayer');
417 $btn->setPrimary(true);
418 $this->addButtonInstance($btn);
419 }
420 } else {
421 $this->addInfoMessage($executable['errormessage']);
422 }
423 }
424
425 if ($this->DIC->user()->getId() == ANONYMOUS_USER_ID) {
426 if ($this->getItems()) {
427 $this->addSeparator();
428 }
429
430 require_once 'Services/Form/classes/class.ilTextInputGUI.php';
431 $anonymous_id = new ilTextInputGUI($this->lng->txt('enter_anonymous_code'), 'anonymous_id');
432 $anonymous_id->setSize(8);
433 $this->addInputItem($anonymous_id, true);
434 $button = ilSubmitButton::getInstance();
435 $button->setCaption('submit');
436 $button->setCommand('setAnonymousId');
437 $this->addButtonInstance($button);
438 }
439 }
440 if ($this->getTestOBJ()->getOfflineStatus() && !$this->getTestQuestionSetConfig()->areDepenciesBroken()) {
441 $message = $this->lng->txt("test_is_offline");
442
443 $links = array();
444
445 if ($this->access->checkAccess("write", "", $this->getTestOBJ()->getRefId())) {
446 $links[] = $this->DIC->ui()->factory()->link()->standard(
447 $this->DIC->language()->txt('test_edit_settings'),
448 $this->buildLinkTarget('ilobjtestsettingsgeneralgui')
449 );
450 }
451
452 $msgBox = $this->DIC->ui()->factory()->messageBox()->info($message)->withLinks($links);
453
454 $this->populateMessage($this->DIC->ui()->renderer()->render($msgBox));
455 }
456
457 if ($this->access->checkAccess("write", "", $this->getTestOBJ()->getRefId())) {
458 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImportFails.php';
459 $qsaImportFails = new ilAssQuestionSkillAssignmentImportFails($this->testOBJ->getId());
460 require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdImportFails.php';
461 $sltImportFails = new ilTestSkillLevelThresholdImportFails($this->testOBJ->getId());
462
463 if ($qsaImportFails->failedImportsRegistered() || $sltImportFails->failedImportsRegistered()) {
464 $importFailsMsg = array();
465
466 if ($qsaImportFails->failedImportsRegistered()) {
467 $importFailsMsg[] = $qsaImportFails->getFailedImportsMessage($this->lng);
468 }
469
470 if ($sltImportFails->failedImportsRegistered()) {
471 $importFailsMsg[] = $sltImportFails->getFailedImportsMessage($this->lng);
472 }
473
474 $message = implode('<br />', $importFailsMsg);
475
476 $button = $this->DIC->ui()->factory()->button()->standard(
477 $this->DIC->language()->txt('ass_skl_import_fails_remove_btn'),
478 $this->DIC->ctrl()->getLinkTargetByClass('ilObjTestGUI', 'removeImportFails')
479 );
480
481 $msgBox = $this->DIC->ui()->factory()->messageBox()->failure($message)->withButtons(array($button));
482
483 $this->populateMessage($this->DIC->ui()->renderer()->render($msgBox));
484 } elseif ($this->getTestOBJ()->isSkillServiceToBeConsidered()) {
485 if ($this->areSkillLevelThresholdsMissing()) {
486 $this->populateMessage($this->getSkillLevelThresholdsMissingInfo());
487 }
488
489 if ($this->hasFixedQuestionSetSkillAssignsLowerThanBarrier()) {
490 $this->addInfoMessage($this->getSkillAssignBarrierInfo());
491 }
492 }
493
494 if ($this->getTestQuestionSetConfig()->areDepenciesBroken()) {
495 $this->addFailureMessage($this->getTestQuestionSetConfig()->getDepenciesBrokenMessage($this->lng));
496
497 $this->clearItems();
498 } elseif ($this->getTestQuestionSetConfig()->areDepenciesInVulnerableState()) {
499 $this->addInfoMessage($this->getTestQuestionSetConfig()->getDepenciesInVulnerableStateMessage($this->lng));
500 }
501 }
502 }
503
504 protected function populateMessage($message): void
505 {
506 $this->DIC->ui()->mainTemplate()->setCurrentBlock('mess');
507 $this->DIC->ui()->mainTemplate()->setVariable('MESSAGE', $message);
508 $this->DIC->ui()->mainTemplate()->parseCurrentBlock();
509 }
510
511 public function sendMessages(): void
512 {
513 $info_messages = $this->getInfoMessages();
514 if ($info_messages !== array()) {
515 $this->main_tpl->setOnScreenMessage('info', array_pop($info_messages));
516 }
517
518 $failure_messages = $this->getFailureMessages();
519 if ($failure_messages !== array()) {
520 $this->main_tpl->setOnScreenMessage('failure', array_pop($failure_messages));
521 }
522 }
523}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
language handling
static _lookupOnlineTestAccess($a_test_id, $a_user_id)
Checks if a user is allowd to run an online exam.
addInfoMessage($infoMessage)
@ param string $infoMessage Could be.
setTestSession(ilTestSession $testSession)
addButtonInstance(ilButtonBase $a_button)
Add button instance.
__construct(ilDBInterface $db, ilAccessHandler $access, ilCtrl $ctrl, ilLanguage $lng, ilComponentRepository $component_repository)
setGlobalToolbar(ilToolbarGUI $globalToolbar)
setTestPlayerGUI(ilTestPlayerAbstractGUI $testPlayerGUI)
setTestQuestionSetConfig(ilTestQuestionSetConfig $testQuestionSetConfig)
setParameter($target, $parameter, $value)
addInputItem(ilToolbarItem $a_item, bool $a_output_label=false)
setFormAction(string $a_val, bool $a_multipart=false, string $a_target="")
Set form action (if form action is set, toolbar is wrapped into form tags)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
const ANONYMOUS_USER_ID
Definition: constants.php:27
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Readable part of repository interface to ilComponentDataDB.
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$message
Definition: xapiexit.php:32
$_COOKIE[session_name()]
Definition: xapitoken.php:54