ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestInfoScreenToolbarGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\UI\Factory as UIFactory;
24use ILIAS\UI\Renderer as UIRenderer;
25
33{
34 private static array $TARGET_CLASS_PATH_BASE = ['ilRepositoryGUI', 'ilObjTestGUI'];
35
37 protected ?ilTestSession $testSession = null;
38
42 protected $testSequence;
43
44 private string $sessionLockString = '';
45 private array $infoMessages = [];
46 private array $failureMessages = [];
47
48 public function __construct(
49 private ilObjTest $test_obj,
50 private ilTestPlayerAbstractGUI $test_player_gui,
51 private ilTestQuestionSetConfig $test_question_set_config,
52 private ilTestSession $test_session,
53 private ilDBInterface $db,
54 private ilAccessHandler $access,
55 private ilCtrlInterface $ctrl,
56 protected ilLanguage $lng,
57 private UIFactory $ui_factory,
58 private UIRenderer $ui_renderer,
59 private ilGlobalTemplateInterface $main_tpl,
60 private ilToolbarGUI $global_toolbar
61 ) {
62 }
63
65 {
66 return $this->test_question_set_config;
67 }
68
69 private function getTestOBJ(): ilObjTest
70 {
71 return $this->test_obj;
72 }
73
75 {
76 return $this->test_player_gui;
77 }
78
79 private function getTestSession(): ?ilTestSession
80 {
81 return $this->test_session;
82 }
83
84 public function getSessionLockString(): ?string
85 {
87 }
88
90 {
91 $this->sessionLockString = $sessionLockString;
92 }
93
94 public function getInfoMessages(): array
95 {
97 }
98
102 public function addInfoMessage($infoMessage): void
103 {
104 $this->infoMessages[] = $infoMessage;
105 }
106
107 public function getFailureMessages(): array
108 {
110 }
111
112 public function addFailureMessage(string $failureMessage): void
113 {
114 $this->failureMessages[] = $failureMessage;
115 }
116
117 public function setFormAction(
118 string $a_val,
119 bool $a_multipart = false,
120 string $a_target = ""
121 ): void {
122 if ($this->global_toolbar instanceof parent) {
123 $this->global_toolbar->setFormAction($a_val, $a_multipart, $a_target);
124 } else {
125 parent::setFormAction($a_val, $a_multipart, $a_target);
126 }
127 }
128
129 public function setCloseFormTag(bool $a_val): void
130 {
131 if ($this->global_toolbar instanceof parent) {
132 $this->global_toolbar->setCloseFormTag($a_val);
133 } else {
134 parent::setCloseFormTag($a_val);
135 }
136 }
137
138 public function addInputItem(
139 ilToolbarItem $a_item,
140 bool $a_output_label = false
141 ): void {
142 if ($this->global_toolbar instanceof parent) {
143 $this->global_toolbar->addInputItem($a_item, $a_output_label);
144 } else {
145 parent::addInputItem($a_item, $a_output_label);
146 }
147 }
148
149 public function addFormInput($formInput): void
150 {
151 if ($this->global_toolbar instanceof parent) {
152 $this->global_toolbar->addFormInput($formInput);
153 }
154 }
155
156 public function clearItems(): void
157 {
158 if ($this->global_toolbar instanceof parent) {
159 $this->global_toolbar->setItems([]);
160 } else {
161 $this->setItems([]);
162 }
163 }
164
165 private function getClassName($target)
166 {
167 if (is_object($target)) {
168 $target = get_class($target);
169 }
170
171 return $target;
172 }
173
174 private function getClassNameArray($target): array
175 {
176 if (is_array($target)) {
177 return $target;
178 }
179
180 return [$this->getClassName($target)];
181 }
182
183 private function getClassPath($target): array
184 {
185 return array_merge(self::$TARGET_CLASS_PATH_BASE, $this->getClassNameArray($target));
186 }
187
188 private function setParameter($target, $parameter, $value): void
189 {
190 $this->ctrl->setParameterByClass($this->getClassName($target), $parameter, $value);
191 }
192
193 private function buildLinkTarget($target, $cmd = null): string
194 {
195 return $this->ctrl->getLinkTargetByClass($this->getClassPath($target), $cmd);
196 }
197
198 private function buildFormAction($target): string
199 {
200 return $this->ctrl->getFormActionByClass($this->getClassPath($target));
201 }
202
203 private function ensureInitialisedSessionLockString(): void
204 {
205 if ($this->getSessionLockString() === '') {
206 $this->setSessionLockString($this->buildSessionLockString());
207 }
208 }
209
210 private function buildSessionLockString(): string
211 {
212 return md5($_COOKIE[session_name()] . time());
213 }
214
216 {
217 if (!$this->test_obj->isFixedTest()) {
218 return false;
219 }
220
221 $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
222 $assignmentList->setParentObjId($this->test_obj->getId());
223 $assignmentList->loadFromDb();
224
225 return $assignmentList->hasSkillsAssignedLowerThanBarrier();
226 }
227
228 private function getSkillAssignBarrierInfo(): string
229 {
230 return sprintf(
231 $this->lng->txt('tst_skill_triggerings_num_req_answers_not_reached_warn'),
232 $this->getTestOBJ()->getGlobalSettings()->getSkillTriggeringNumberOfAnswers()
233 );
234 }
235
236 public function build(): void
237 {
238 $this->ensureInitialisedSessionLockString();
239
240 $this->setParameter($this->getTestPlayerGUI(), 'lock', $this->getSessionLockString());
241 $this->setParameter($this->getTestPlayerGUI(), 'sequence', $this->getTestSession()->getLastSequence());
242 $this->setParameter('ilObjTestGUI', 'ref_id', $this->getTestOBJ()->getRefId());
243 $this->setFormAction($this->buildFormAction($this->getTestPlayerGUI()));
244
245 if ($this->getTestOBJ()->getOfflineStatus()) {
246 $message = $this->lng->txt('test_is_offline');
247
248 $links = [];
249
250 if ($this->access->checkAccess("write", "", $this->getTestOBJ()->getRefId())) {
251 $links[] = $this->ui_factory->link()->standard(
252 $this->lng->txt('test_edit_settings'),
253 $this->buildLinkTarget(SettingsMainGUI::class)
254 );
255 }
256
257 $msgBox = $this->ui_factory->messageBox()->info($message)->withLinks($links);
258
259 $this->populateMessage($this->ui_renderer->render($msgBox));
260 }
261
262 if ($this->access->checkAccess("write", "", $this->getTestOBJ()->getRefId())) {
263 $qsaImportFails = new ilAssQuestionSkillAssignmentImportFails($this->test_obj->getId());
264 $sltImportFails = new ilTestSkillLevelThresholdImportFails($this->test_obj->getId());
265
266 if ($qsaImportFails->failedImportsRegistered() || $sltImportFails->failedImportsRegistered()) {
267 $importFailsMsg = [];
268
269 if ($qsaImportFails->failedImportsRegistered()) {
270 $importFailsMsg[] = $qsaImportFails->getFailedImportsMessage($this->lng);
271 }
272
273 if ($sltImportFails->failedImportsRegistered()) {
274 $importFailsMsg[] = $sltImportFails->getFailedImportsMessage($this->lng);
275 }
276
277 $message = implode('<br />', $importFailsMsg);
278
279 $button = $this->ui_factory->button()->standard(
280 $this->lng->txt('ass_skl_import_fails_remove_btn'),
281 $this->ctrl->getLinkTargetByClass('ilObjTestGUI', 'removeImportFails')
282 );
283
284 $msgBox = $this->ui_factory->messageBox()->failure($message)->withButtons([$button]);
285
286 $this->populateMessage($this->ui_renderer->render($msgBox));
287 } elseif ($this->getTestOBJ()->isSkillServiceToBeConsidered()) {
288 if ($this->hasFixedQuestionSetSkillAssignsLowerThanBarrier()) {
289 $this->addInfoMessage($this->getSkillAssignBarrierInfo());
290 }
291 }
292 }
293 }
294
295 protected function populateMessage($message): void
296 {
297 $this->main_tpl->setCurrentBlock('mess');
298 $this->main_tpl->setVariable('MESSAGE', $message);
299 $this->main_tpl->parseCurrentBlock();
300 }
301
302 public function sendMessages(): void
303 {
304 $info_messages = $this->getInfoMessages();
305 if ($info_messages !== []) {
306 $this->main_tpl->setOnScreenMessage('info', array_pop($info_messages));
307 }
308
309 $failure_messages = $this->getFailureMessages();
310 if ($failure_messages !== []) {
311 $this->main_tpl->setOnScreenMessage('failure', array_pop($failure_messages));
312 }
313 }
314}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
@ilCtrl_Calls ILIAS\Test\Settings\MainSettings\SettingsMainGUI: ilPropertyFormGUI @ilCtrl_Calls ILIAS...
language handling
addInfoMessage($infoMessage)
@ param string $infoMessage Could be.
__construct(private ilObjTest $test_obj, private ilTestPlayerAbstractGUI $test_player_gui, private ilTestQuestionSetConfig $test_question_set_config, private ilTestSession $test_session, private ilDBInterface $db, private ilAccessHandler $access, private ilCtrlInterface $ctrl, protected ilLanguage $lng, private UIFactory $ui_factory, private UIRenderer $ui_renderer, private ilGlobalTemplateInterface $main_tpl, private ilToolbarGUI $global_toolbar)
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)
Test session handler.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))
$message
Definition: xapiexit.php:31
$_COOKIE[session_name()]
Definition: xapitoken.php:54