ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
53  protected $questionSetConfig;
54 
58  protected $validationFailed;
59 
63  protected $validationReports;
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'),
213  )
214  );
215  } elseif ($this->isQuestionAmountConfigPerPoolHintRequired()) {
216  $this->addValidationReport(
217  sprintf(
218  $this->lng->txt('tst_msg_rand_quest_set_change_quest_amount_here'),
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 
267  private function buildLostQuestionPoolsString()
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()) {
281  case self::CONTEXT_POOL_SELECTION:
282 
284 
285  case self::CONTEXT_GENERAL_CONFIG:
286  default:
287 
289  }
290  }
291 
296  {
297  $this->ctrl->setParameter(
298  $this->getTargetGUI(),
301  );
302 
303  $href = $this->ctrl->getLinkTarget(
304  $this->getTargetGUI(),
306  );
307  $label = $this->lng->txt('tst_btn_rebuild_random_question_stage');
308 
309  return $this->DIC->ui()->factory()->button()->standard($label, $href);
310  }
311 
312  private function buildGeneralConfigSubTabLink()
313  {
314  $href = $this->ctrl->getLinkTarget(
315  $this->getTargetGUI(),
317  );
318 
319  $label = $this->lng->txt('tst_rnd_quest_cfg_tab_general');
320 
321  return "<a href=\"{$href}\">{$label}</a>";
322  }
323 
325  {
326  $href = $this->ctrl->getLinkTarget(
327  $this->getTargetGUI(),
329  );
330 
331  $label = $this->lng->txt('tst_rnd_quest_cfg_tab_pool');
332 
333  return "<a href=\"{$href}\">{$label}</a>";
334  }
335 
341  {
342  if ($this->getContext() != self::CONTEXT_POOL_SELECTION) {
343  return false;
344  }
345 
346  if ($this->questionSetConfig->doesSelectableQuestionPoolsExist()) {
347  return false;
348  }
349 
350  return true;
351  }
352 
358  {
359  if ($this->getContext() != self::CONTEXT_GENERAL_CONFIG) {
360  return false;
361  }
362 
363  if (!$this->questionSetConfig->isQuestionAmountConfigurationModePerPool()) {
364  return false;
365  }
366 
367  return true;
368  }
369 
375  {
376  if ($this->getContext() != self::CONTEXT_POOL_SELECTION) {
377  return false;
378  }
379 
380  if (!$this->questionSetConfig->isQuestionAmountConfigurationModePerTest()) {
381  return false;
382  }
383 
384  return true;
385  }
386 
390  protected function buildLostPoolsReportMessage()
391  {
392  $report = sprintf(
393  $this->lng->txt('tst_msg_rand_quest_set_lost_pools'),
395  );
396 
397  if ($this->getContext() == self::CONTEXT_GENERAL_CONFIG) {
398  $action = $this->ctrl->getLinkTarget(
399  $this->getTargetGUI(),
401  );
402 
403  $link = $this->DIC->ui()->factory()->link()->standard(
404  $this->lng->txt('tst_msg_rand_quest_set_lost_pools_link'),
405  $action
406  );
407 
408  $msgBox = $this->DIC->ui()->factory()->messageBox()->info($report)->withLinks(array($link));
409  } else {
410  $msgBox = $this->DIC->ui()->factory()->messageBox()->info($report);
411  }
412 
413  return $this->DIC->ui()->renderer()->render($msgBox);
414  }
415 
419  protected function populateMessage($message)
420  {
421  $this->DIC->ui()->mainTemplate()->setCurrentBlock('mess');
422  $this->DIC->ui()->mainTemplate()->setVariable('MESSAGE', $message);
423  $this->DIC->ui()->mainTemplate()->parseCurrentBlock();
424  }
425 }
This class provides processing control methods.
$action
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
catch(Exception $e) $message
Date and time handling
language handling