ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTestRandomQuestionSetConfigStateMessageHandler.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
12{
16 protected $DIC;
20 protected $lng;
21
25 protected $ctrl;
26
30 protected $targetGUI;
31
32 const CONTEXT_GENERAL_CONFIG = 'generalConfigContext';
33 const CONTEXT_POOL_SELECTION = 'poolSelectionContext';
34
38 protected $context;
39
44
48 protected $lostPools;
49
54
59
64
69 {
70 global $DIC; /* @var ILIAS\DI\Container $DIC */
71 $this->DIC = $DIC;
72
73 $this->lng = $lng;
74 $this->ctrl = $ctrl;
75 $this->validationFailed = false;
76 $this->validationReports = array();
77 }
78
82 public function getLostPools()
83 {
84 return $this->lostPools;
85 }
86
90 public function setLostPools($lostPools)
91 {
92 $this->lostPools = $lostPools;
93 }
94
98 public function doesParticipantDataExists()
99 {
101 }
102
107 {
108 $this->participantDataExists = $participantDataExists;
109 }
110
114 public function getTargetGUI()
115 {
116 return $this->targetGUI;
117 }
118
122 public function setTargetGUI($targetGUI)
123 {
124 $this->targetGUI = $targetGUI;
125 }
126
130 public function getContext()
131 {
132 return $this->context;
133 }
134
138 public function setContext($context)
139 {
140 $this->context = $context;
141 }
142
146 public function getQuestionSetConfig()
147 {
149 }
150
155 {
156 $this->questionSetConfig = $questionSetConfig;
157 }
158
162 public function isValidationFailed()
163 {
165 }
166
171 {
172 $this->validationFailed = $validationFailed;
173 }
174
178 public function getValidationReportHtml()
179 {
180 return implode('<br />', $this->validationReports);
181 }
182
186 public function hasValidationReports()
187 {
188 return count($this->validationReports);
189 }
190
194 public function addValidationReport($validationReport)
195 {
196 $this->validationReports[] = $validationReport;
197 }
198
199 public function handle()
200 {
202 $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_no_pools_available'));
203 } elseif ($this->getLostPools()) {
205 } elseif (!$this->questionSetConfig->isQuestionAmountConfigComplete()) {
206 $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_incomplete_quest_amount_cfg'));
207
209 $this->addValidationReport(
210 sprintf(
211 $this->lng->txt('tst_msg_rand_quest_set_change_quest_amount_here'),
212 $this->buildGeneralConfigSubTabLink()
213 )
214 );
216 $this->addValidationReport(
217 sprintf(
218 $this->lng->txt('tst_msg_rand_quest_set_change_quest_amount_here'),
219 $this->buildQuestionSelectionSubTabLink()
220 )
221 );
222 }
223 } elseif (!$this->questionSetConfig->hasSourcePoolDefinitions()) {
224 $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_no_src_pool_defs'));
225 }
226 // fau: delayCopyRandomQuestions - show info message if date of last synchronisation is empty
227 elseif ($this->questionSetConfig->getLastQuestionSyncTimestamp() == 0) {
228 $message = $this->DIC->language()->txt('tst_msg_rand_quest_set_not_sync');
229 $button = $this->buildQuestionStageRebuildButton();
230 $msgBox = $this->DIC->ui()->factory()->messageBox()->info($message)->withButtons(array($button));
231 $this->populateMessage($this->DIC->ui()->renderer()->render($msgBox));
232 }
233 // fau.
234
235 elseif (!$this->questionSetConfig->isQuestionSetBuildable()) {
236 $this->setValidationFailed(true);
237 $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_pass_not_buildable'));
238
239 //fau: fixRandomTestBuildable - show the messages if set is not buildable
240 $this->addValidationReport(implode('<br />', $this->questionSetConfig->getBuildableMessages()));
241 //fau.
242 } elseif ($this->questionSetConfig->getLastQuestionSyncTimestamp()) {
243 $message = $this->lng->txt('tst_msg_rand_quest_set_pass_buildable');
244
245 $syncDate = new ilDateTime(
246 $this->questionSetConfig->getLastQuestionSyncTimestamp(),
248 );
249
250 $message .= sprintf(
251 ' ' . $this->lng->txt('tst_msg_rand_quest_set_stage_pool_last_sync'),
253 );
254
255 if (!$this->doesParticipantDataExists() && !$this->getLostPools()) {
256 $msgBox = $this->DIC->ui()->factory()->messageBox()->info($message)->withButtons(
257 array($this->buildQuestionStageRebuildButton())
258 );
259 } else {
260 $msgBox = $this->DIC->ui()->factory()->messageBox()->info($message);
261 }
262
263 $this->populateMessage($this->DIC->ui()->renderer()->render($msgBox));
264 }
265 }
266
268 {
269 $titles = array();
270
271 foreach ($this->getLostPools() as $lostPool) {
272 $titles[] = $lostPool->getTitle();
273 }
274
275 return implode(', ', $titles);
276 }
277
279 {
280 switch ($this->getContext()) {
282
284
286 default:
287
289 }
290 }
291
292 private function buildQuestionStageRebuildButton() : \ILIAS\UI\Component\Button\Standard
293 {
294 $this->ctrl->setParameter(
295 $this->getTargetGUI(),
298 );
299
300 $href = $this->ctrl->getLinkTarget(
301 $this->getTargetGUI(),
303 );
304 $label = $this->lng->txt('tst_btn_rebuild_random_question_stage');
305
306 return $this->DIC->ui()->factory()->button()->standard($label, $href)->withLoadingAnimationOnClick(true);
307 }
308
310 {
311 $href = $this->ctrl->getLinkTarget(
312 $this->getTargetGUI(),
314 );
315
316 $label = $this->lng->txt('tst_rnd_quest_cfg_tab_general');
317
318 return "<a href=\"{$href}\">{$label}</a>";
319 }
320
322 {
323 $href = $this->ctrl->getLinkTarget(
324 $this->getTargetGUI(),
326 );
327
328 $label = $this->lng->txt('tst_rnd_quest_cfg_tab_pool');
329
330 return "<a href=\"{$href}\">{$label}</a>";
331 }
332
338 {
339 if ($this->getContext() != self::CONTEXT_POOL_SELECTION) {
340 return false;
341 }
342
343 if ($this->questionSetConfig->doesSelectableQuestionPoolsExist()) {
344 return false;
345 }
346
347 return true;
348 }
349
355 {
356 if ($this->getContext() != self::CONTEXT_GENERAL_CONFIG) {
357 return false;
358 }
359
360 if (!$this->questionSetConfig->isQuestionAmountConfigurationModePerPool()) {
361 return false;
362 }
363
364 return true;
365 }
366
372 {
373 if ($this->getContext() != self::CONTEXT_POOL_SELECTION) {
374 return false;
375 }
376
377 if (!$this->questionSetConfig->isQuestionAmountConfigurationModePerTest()) {
378 return false;
379 }
380
381 return true;
382 }
383
387 protected function buildLostPoolsReportMessage()
388 {
389 $report = sprintf(
390 $this->lng->txt('tst_msg_rand_quest_set_lost_pools'),
391 $this->buildLostQuestionPoolsString()
392 );
393
394 if ($this->getContext() == self::CONTEXT_GENERAL_CONFIG) {
395 $action = $this->ctrl->getLinkTarget(
396 $this->getTargetGUI(),
398 );
399
400 $link = $this->DIC->ui()->factory()->link()->standard(
401 $this->lng->txt('tst_msg_rand_quest_set_lost_pools_link'),
402 $action
403 );
404
405 $msgBox = $this->DIC->ui()->factory()->messageBox()->info($report)->withLinks(array($link));
406 } else {
407 $msgBox = $this->DIC->ui()->factory()->messageBox()->info($report);
408 }
409
410 return $this->DIC->ui()->renderer()->render($msgBox);
411 }
412
416 protected function populateMessage($message)
417 {
418 $this->DIC->ui()->mainTemplate()->setCurrentBlock('mess');
419 $this->DIC->ui()->mainTemplate()->setVariable('MESSAGE', $message);
420 $this->DIC->ui()->mainTemplate()->parseCurrentBlock();
421 }
422}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
This class provides processing control methods.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
language handling
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$message
Definition: xapiexit.php:14