ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilTestInfoScreenToolbarGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\UI\Factory as UIFactory;
23use ILIAS\UI\Renderer as UIRenderer;
24
32{
33 private static array $TARGET_CLASS_PATH_BASE = ['ilRepositoryGUI', 'ilObjTestGUI'];
34
36 protected ?ilTestSession $testSession = null;
37
41 protected $testSequence;
42
43 private string $sessionLockString = '';
44 private array $infoMessages = [];
45 private array $failureMessages = [];
46
47 public function __construct(
48 private ilObjTest $test_obj,
49 private ilTestPlayerAbstractGUI $test_player_gui,
50 private ilTestQuestionSetConfig $test_question_set_config,
51 private ilTestSession $test_session,
52 private ilDBInterface $db,
53 private ilAccessHandler $access,
54 private ilCtrlInterface $ctrl,
55 protected ilLanguage $lng,
56 private UIFactory $ui_factory,
57 private UIRenderer $ui_renderer,
58 private ilGlobalTemplateInterface $main_tpl,
59 private ilToolbarGUI $global_toolbar
60 ) {
61 }
62
64 {
65 return $this->test_question_set_config;
66 }
67
68 private function getTestOBJ(): ilObjTest
69 {
70 return $this->test_obj;
71 }
72
74 {
75 return $this->test_player_gui;
76 }
77
78 private function getTestSession(): ?ilTestSession
79 {
80 return $this->test_session;
81 }
82
83 public function getSessionLockString(): ?string
84 {
86 }
87
89 {
90 $this->sessionLockString = $sessionLockString;
91 }
92
93 public function getInfoMessages(): array
94 {
96 }
97
101 public function addInfoMessage($infoMessage): void
102 {
103 $this->infoMessages[] = $infoMessage;
104 }
105
106 public function getFailureMessages(): array
107 {
109 }
110
111 public function addFailureMessage(string $failureMessage): void
112 {
113 $this->failureMessages[] = $failureMessage;
114 }
115
116 public function setFormAction(
117 string $a_val,
118 bool $a_multipart = false,
119 string $a_target = ""
120 ): void {
121 if ($this->global_toolbar instanceof parent) {
122 $this->global_toolbar->setFormAction($a_val, $a_multipart, $a_target);
123 } else {
124 parent::setFormAction($a_val, $a_multipart, $a_target);
125 }
126 }
127
128 public function setCloseFormTag(bool $a_val): void
129 {
130 if ($this->global_toolbar instanceof parent) {
131 $this->global_toolbar->setCloseFormTag($a_val);
132 } else {
133 parent::setCloseFormTag($a_val);
134 }
135 }
136
137 public function addInputItem(
138 ilToolbarItem $a_item,
139 bool $a_output_label = false
140 ): void {
141 if ($this->global_toolbar instanceof parent) {
142 $this->global_toolbar->addInputItem($a_item, $a_output_label);
143 } else {
144 parent::addInputItem($a_item, $a_output_label);
145 }
146 }
147
148 public function addFormInput($formInput): void
149 {
150 if ($this->global_toolbar instanceof parent) {
151 $this->global_toolbar->addFormInput($formInput);
152 }
153 }
154
155 public function clearItems(): void
156 {
157 if ($this->global_toolbar instanceof parent) {
158 $this->global_toolbar->setItems([]);
159 } else {
160 $this->setItems([]);
161 }
162 }
163
164 private function getClassName($target)
165 {
166 if (is_object($target)) {
167 $target = get_class($target);
168 }
169
170 return $target;
171 }
172
173 private function getClassNameArray($target): array
174 {
175 if (is_array($target)) {
176 return $target;
177 }
178
179 return [$this->getClassName($target)];
180 }
181
182 private function getClassPath($target): array
183 {
184 return array_merge(self::$TARGET_CLASS_PATH_BASE, $this->getClassNameArray($target));
185 }
186
187 private function setParameter($target, $parameter, $value): void
188 {
189 $this->ctrl->setParameterByClass($this->getClassName($target), $parameter, $value);
190 }
191
192 private function buildLinkTarget($target, $cmd = null): string
193 {
194 return $this->ctrl->getLinkTargetByClass($this->getClassPath($target), $cmd);
195 }
196
197 private function buildFormAction($target): string
198 {
199 return $this->ctrl->getFormActionByClass($this->getClassPath($target));
200 }
201
202 private function ensureInitialisedSessionLockString(): void
203 {
204 if ($this->getSessionLockString() === '') {
205 $this->setSessionLockString($this->buildSessionLockString());
206 }
207 }
208
209 private function buildSessionLockString(): string
210 {
211 return md5($_COOKIE[session_name()] . time());
212 }
213
214 public function build(): void
215 {
216 $this->ensureInitialisedSessionLockString();
217
218 $this->setParameter($this->getTestPlayerGUI(), 'lock', $this->getSessionLockString());
219 $this->setParameter($this->getTestPlayerGUI(), 'sequence', $this->getTestSession()->getLastSequence());
220 $this->setParameter('ilObjTestGUI', 'ref_id', $this->getTestOBJ()->getRefId());
221 $this->setFormAction($this->buildFormAction($this->getTestPlayerGUI()));
222
223 if ($this->getTestOBJ()->getOfflineStatus()) {
224 $message = $this->lng->txt('test_is_offline');
225
226 $links = [];
227
228 if ($this->access->checkAccess("write", "", $this->getTestOBJ()->getRefId())) {
229 $links[] = $this->ui_factory->link()->standard(
230 $this->lng->txt('test_edit_settings'),
231 $this->buildLinkTarget(SettingsMainGUI::class)
232 );
233 }
234
235 $msgBox = $this->ui_factory->messageBox()->info($message)->withLinks($links);
236
237 $this->populateMessage($this->ui_renderer->render($msgBox));
238 }
239
240 if ($this->access->checkAccess("write", "", $this->getTestOBJ()->getRefId())) {
241 $qsaImportFails = new ilAssQuestionSkillAssignmentImportFails($this->test_obj->getId());
242 $sltImportFails = new ilTestSkillLevelThresholdImportFails($this->test_obj->getId());
243
244 if ($qsaImportFails->failedImportsRegistered() || $sltImportFails->failedImportsRegistered()) {
245 $importFailsMsg = [];
246
247 if ($qsaImportFails->failedImportsRegistered()) {
248 $importFailsMsg[] = $qsaImportFails->getFailedImportsMessage($this->lng);
249 }
250
251 if ($sltImportFails->failedImportsRegistered()) {
252 $importFailsMsg[] = $sltImportFails->getFailedImportsMessage($this->lng);
253 }
254
255 $message = implode('<br />', $importFailsMsg);
256
257 $button = $this->ui_factory->button()->standard(
258 $this->lng->txt('ass_skl_import_fails_remove_btn'),
259 $this->ctrl->getLinkTargetByClass('ilObjTestGUI', 'removeImportFails')
260 );
261
262 $msgBox = $this->ui_factory->messageBox()->failure($message)->withButtons([$button]);
263
264 $this->populateMessage($this->ui_renderer->render($msgBox));
265 }
266 }
267 }
268
269 protected function populateMessage($message): void
270 {
271 $this->main_tpl->setCurrentBlock('mess');
272 $this->main_tpl->setVariable('MESSAGE', $message);
273 $this->main_tpl->parseCurrentBlock();
274 }
275
276 public function sendMessages(): void
277 {
278 $info_messages = $this->getInfoMessages();
279 if ($info_messages !== []) {
280 $this->main_tpl->setOnScreenMessage('info', array_pop($info_messages));
281 }
282
283 $failure_messages = $this->getFailureMessages();
284 if ($failure_messages !== []) {
285 $this->main_tpl->setOnScreenMessage('failure', array_pop($failure_messages));
286 }
287 }
288}
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'))
$_COOKIE[session_name()]
Definition: xapitoken.php:52