ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestInfoScreenToolbarGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
31 {
32  private static array $TARGET_CLASS_PATH_BASE = ['ilRepositoryGUI', 'ilObjTestGUI'];
33 
35  protected ?ilTestSession $testSession = null;
36 
40  protected $testSequence;
41 
42  private string $sessionLockString = '';
43  private array $infoMessages = [];
44  private array $failureMessages = [];
45 
46  public function __construct(
47  private ilObjTest $test_obj,
48  private ilTestPlayerAbstractGUI $test_player_gui,
49  private ilTestQuestionSetConfig $test_question_set_config,
50  private ilTestSession $test_session,
51  private ilDBInterface $db,
52  private ilAccessHandler $access,
53  private ilCtrl $ctrl,
54  protected ilLanguage $lng,
55  private UIFactory $ui_factory,
56  private UIRenderer $ui_renderer,
57  private ilGlobalTemplateInterface $main_tpl,
58  private ilToolbarGUI $global_toolbar
59  ) {
60  }
61 
63  {
64  return $this->test_question_set_config;
65  }
66 
67  private function getTestOBJ(): ilObjTest
68  {
69  return $this->test_obj;
70  }
71 
73  {
74  return $this->test_player_gui;
75  }
76 
77  private function getTestSession(): ?ilTestSession
78  {
79  return $this->test_session;
80  }
81 
82  public function getSessionLockString(): ?string
83  {
85  }
86 
87  public function setSessionLockString($sessionLockString): void
88  {
89  $this->sessionLockString = $sessionLockString;
90  }
91 
92  public function getInfoMessages(): array
93  {
94  return $this->infoMessages;
95  }
96 
100  public function addInfoMessage($infoMessage): void
101  {
102  $this->infoMessages[] = $infoMessage;
103  }
104 
105  public function getFailureMessages(): array
106  {
107  return $this->failureMessages;
108  }
109 
110  public function addFailureMessage(string $failureMessage): void
111  {
112  $this->failureMessages[] = $failureMessage;
113  }
114 
115  public function setFormAction(
116  string $a_val,
117  bool $a_multipart = false,
118  string $a_target = ""
119  ): void {
120  if ($this->global_toolbar instanceof parent) {
121  $this->global_toolbar->setFormAction($a_val, $a_multipart, $a_target);
122  } else {
123  parent::setFormAction($a_val, $a_multipart, $a_target);
124  }
125  }
126 
127  public function setCloseFormTag(bool $a_val): void
128  {
129  if ($this->global_toolbar instanceof parent) {
130  $this->global_toolbar->setCloseFormTag($a_val);
131  } else {
132  parent::setCloseFormTag($a_val);
133  }
134  }
135 
136  public function addInputItem(
137  ilToolbarItem $a_item,
138  bool $a_output_label = false
139  ): void {
140  if ($this->global_toolbar instanceof parent) {
141  $this->global_toolbar->addInputItem($a_item, $a_output_label);
142  } else {
143  parent::addInputItem($a_item, $a_output_label);
144  }
145  }
146 
147  public function addFormInput($formInput): void
148  {
149  if ($this->global_toolbar instanceof parent) {
150  $this->global_toolbar->addFormInput($formInput);
151  }
152  }
153 
154  public function clearItems(): void
155  {
156  if ($this->global_toolbar instanceof parent) {
157  $this->global_toolbar->setItems([]);
158  } else {
159  $this->setItems([]);
160  }
161  }
162 
163  private function getClassName($target)
164  {
165  if (is_object($target)) {
166  $target = get_class($target);
167  }
168 
169  return $target;
170  }
171 
172  private function getClassNameArray($target): array
173  {
174  if (is_array($target)) {
175  return $target;
176  }
177 
178  return [$this->getClassName($target)];
179  }
180 
181  private function getClassPath($target): array
182  {
183  return array_merge(self::$TARGET_CLASS_PATH_BASE, $this->getClassNameArray($target));
184  }
185 
186  private function setParameter($target, $parameter, $value): void
187  {
188  $this->ctrl->setParameterByClass($this->getClassName($target), $parameter, $value);
189  }
190 
191  private function buildLinkTarget($target, $cmd = null): string
192  {
193  return $this->ctrl->getLinkTargetByClass($this->getClassPath($target), $cmd);
194  }
195 
196  private function buildFormAction($target): string
197  {
198  return $this->ctrl->getFormActionByClass($this->getClassPath($target));
199  }
200 
201  private function ensureInitialisedSessionLockString(): void
202  {
203  if ($this->getSessionLockString() === '') {
205  }
206  }
207 
208  private function buildSessionLockString(): string
209  {
210  return md5($_COOKIE[session_name()] . time());
211  }
212 
214  {
215  if (!$this->test_obj->isFixedTest()) {
216  return false;
217  }
218 
219  $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
220  $assignmentList->setParentObjId($this->test_obj->getId());
221  $assignmentList->loadFromDb();
222 
223  return $assignmentList->hasSkillsAssignedLowerThanBarrier();
224  }
225 
226  private function getSkillAssignBarrierInfo(): string
227  {
228  return sprintf(
229  $this->lng->txt('tst_skill_triggerings_num_req_answers_not_reached_warn'),
231  );
232  }
233 
234  public function build(): void
235  {
237 
238  $this->setParameter($this->getTestPlayerGUI(), 'lock', $this->getSessionLockString());
239  $this->setParameter($this->getTestPlayerGUI(), 'sequence', $this->getTestSession()->getLastSequence());
240  $this->setParameter('ilObjTestGUI', 'ref_id', $this->getTestOBJ()->getRefId());
241 
242  $this->setFormAction($this->buildFormAction($this->getTestPlayerGUI()));
243 
244  if (!$this->getTestOBJ()->getOfflineStatus() && $this->getTestOBJ()->isComplete($this->getTestQuestionSetConfig())) {
245  if ($this->access->checkAccess("read", "", $this->getTestOBJ()->getRefId())) {
246  $executable = $this->getTestOBJ()->isExecutable(
247  $this->getTestSession(),
248  $this->getTestSession()->getUserId(),
249  true
250  );
251 
252  if ($executable['executable'] && $this->getTestOBJ()->areObligationsEnabled() && $this->getTestOBJ()->hasObligations()) {
253  $this->addInfoMessage($this->lng->txt('tst_test_contains_obligatory_questions'));
254  }
255  }
256  }
257  if ($this->getTestOBJ()->getOfflineStatus() && !$this->getTestQuestionSetConfig()->areDepenciesBroken()) {
258  $message = $this->lng->txt("test_is_offline");
259 
260  $links = [];
261 
262  if ($this->access->checkAccess("write", "", $this->getTestOBJ()->getRefId())) {
263  $links[] = $this->ui_factory->link()->standard(
264  $this->lng->txt('test_edit_settings'),
265  $this->buildLinkTarget('ilobjtestsettingsmaingui')
266  );
267  }
268 
269  $msgBox = $this->ui_factory->messageBox()->info($message)->withLinks($links);
270 
271  $this->populateMessage($this->ui_renderer->render($msgBox));
272  }
273 
274  if ($this->access->checkAccess("write", "", $this->getTestOBJ()->getRefId())) {
275  $qsaImportFails = new ilAssQuestionSkillAssignmentImportFails($this->test_obj->getId());
276  $sltImportFails = new ilTestSkillLevelThresholdImportFails($this->test_obj->getId());
277 
278  if ($qsaImportFails->failedImportsRegistered() || $sltImportFails->failedImportsRegistered()) {
279  $importFailsMsg = [];
280 
281  if ($qsaImportFails->failedImportsRegistered()) {
282  $importFailsMsg[] = $qsaImportFails->getFailedImportsMessage($this->lng);
283  }
284 
285  if ($sltImportFails->failedImportsRegistered()) {
286  $importFailsMsg[] = $sltImportFails->getFailedImportsMessage($this->lng);
287  }
288 
289  $message = implode('<br />', $importFailsMsg);
290 
291  $button = $this->ui_factory->button()->standard(
292  $this->lng->txt('ass_skl_import_fails_remove_btn'),
293  $this->ctrl->getLinkTargetByClass('ilObjTestGUI', 'removeImportFails')
294  );
295 
296  $msgBox = $this->ui_factory->messageBox()->failure($message)->withButtons([$button]);
297 
298  $this->populateMessage($this->ui_renderer->render($msgBox));
299  } elseif ($this->getTestOBJ()->isSkillServiceToBeConsidered()) {
301  $this->addInfoMessage($this->getSkillAssignBarrierInfo());
302  }
303  }
304 
305  if ($this->getTestQuestionSetConfig()->areDepenciesBroken()) {
306  $this->addFailureMessage($this->getTestQuestionSetConfig()->getDepenciesBrokenMessage($this->lng));
307 
308  $this->clearItems();
309  } elseif ($this->getTestQuestionSetConfig()->areDepenciesInVulnerableState()) {
310  $this->addInfoMessage($this->getTestQuestionSetConfig()->getDepenciesInVulnerableStateMessage($this->lng));
311  }
312  }
313  }
314 
315  protected function populateMessage($message): void
316  {
317  $this->main_tpl->setCurrentBlock('mess');
318  $this->main_tpl->setVariable('MESSAGE', $message);
319  $this->main_tpl->parseCurrentBlock();
320  }
321 
322  public function sendMessages(): void
323  {
324  $info_messages = $this->getInfoMessages();
325  if ($info_messages !== []) {
326  $this->main_tpl->setOnScreenMessage('info', array_pop($info_messages));
327  }
328 
329  $failure_messages = $this->getFailureMessages();
330  if ($failure_messages !== []) {
331  $this->main_tpl->setOnScreenMessage('failure', array_pop($failure_messages));
332  }
333  }
334 }
setParameter($target, $parameter, $value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFormAction(string $a_val, bool $a_multipart=false, string $a_target="")
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 ilCtrl $ctrl, protected ilLanguage $lng, private UIFactory $ui_factory, private UIRenderer $ui_renderer, private ilGlobalTemplateInterface $main_tpl, private ilToolbarGUI $global_toolbar)
addInputItem(ilToolbarItem $a_item, bool $a_output_label=false)
$message
Definition: xapiexit.php:32
$_COOKIE[session_name()]
Definition: xapitoken.php:54
setItems(array $items)
Output class for assessment test execution.