ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestRandomQuestionSetConfigStateMessageHandler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
32 {
34 
35  public const CONTEXT_GENERAL_CONFIG = 'generalConfigContext';
36  public const CONTEXT_POOL_SELECTION = 'poolSelectionContext';
37 
38  protected string $context;
39  protected bool $participantDataExists;
40 
44  protected array $lostPools;
45 
47 
48  protected bool $validationFailed = false;
49  protected array $validationReports = [];
50  protected string $sync_info_message = '';
51 
52  public function __construct(
53  private ilLanguage $lng,
54  private UIFactory $ui_factory,
55  private UIRenderer $ui_renderer,
56  private ilCtrl $ctrl
57  ) {
58  $this->validationFailed = false;
59  $this->validationReports = [];
60  }
61 
65  public function getLostPools(): array
66  {
67  return $this->lostPools;
68  }
69 
73  public function setLostPools(array $lostPools): void
74  {
75  $this->lostPools = $lostPools;
76  }
77 
81  public function doesParticipantDataExists(): bool
82  {
84  }
85 
86  public function setParticipantDataExists(bool $participantDataExists): void
87  {
88  $this->participantDataExists = $participantDataExists;
89  }
90 
92  {
93  return $this->targetGUI;
94  }
95 
96  public function setTargetGUI(ilTestRandomQuestionSetConfigGUI $targetGUI)
97  {
98  $this->targetGUI = $targetGUI;
99  }
100 
101  public function getContext(): string
102  {
103  return $this->context;
104  }
105 
106  public function setContext(string $context)
107  {
108  $this->context = $context;
109  }
110 
112  {
114  }
115 
116  public function setQuestionSetConfig(ilTestRandomQuestionSetConfig $questionSetConfig)
117  {
118  $this->questionSetConfig = $questionSetConfig;
119  }
120 
121  public function isValidationFailed(): bool
122  {
124  }
125 
126  protected function setValidationFailed(bool $validationFailed)
127  {
128  $this->validationFailed = $validationFailed;
129  }
130 
131  public function getValidationReportHtml(): string
132  {
133  return implode('<br />', $this->validationReports);
134  }
135 
136  public function hasValidationReports(): int
137  {
138  return count($this->validationReports);
139  }
140 
141  protected function addValidationReport(string $validationReport)
142  {
143  $this->validationReports[] = $validationReport;
144  }
145 
146  public function getSyncInfoMessage(): string
147  {
149  }
150 
151  protected function setSyncInfoMessage(string $message): void
152  {
153  $this->sync_info_message = $message;
154  }
155 
156  public function handle(): void
157  {
159  $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_no_pools_available'));
160  } elseif ($this->getLostPools()) {
162  } elseif (!$this->questionSetConfig->isQuestionAmountConfigComplete()) {
163  $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_incomplete_quest_amount_cfg'));
164 
166  $this->addValidationReport(
167  sprintf(
168  $this->lng->txt('tst_msg_rand_quest_set_change_quest_amount_here'),
170  )
171  );
172  } elseif ($this->isQuestionAmountConfigPerPoolHintRequired()) {
173  $this->addValidationReport(
174  sprintf(
175  $this->lng->txt('tst_msg_rand_quest_set_change_quest_amount_here'),
177  )
178  );
179  }
180  } elseif (!$this->questionSetConfig->hasSourcePoolDefinitions()) {
181  $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_no_src_pool_defs'));
182  } elseif ($this->questionSetConfig->getLastQuestionSyncTimestamp() === 0 ||
183  $this->questionSetConfig->getLastQuestionSyncTimestamp() === null) {
184  $this->setSyncInfoMessage($this->buildNotSyncedMessage());
185  } elseif (!$this->questionSetConfig->isQuestionSetBuildable()) {
186  $this->setValidationFailed(true);
187  $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_pass_not_buildable'));
188  $this->addValidationReport(implode('<br />', $this->questionSetConfig->getBuildableMessages()));
189  } elseif ($this->questionSetConfig->getLastQuestionSyncTimestamp()) {
190  $this->setSyncInfoMessage($this->buildLastSyncMessage());
191  }
192  }
193 
194  private function buildLostQuestionPoolsString(): string
195  {
196  $titles = array();
197 
198  foreach ($this->getLostPools() as $lostPool) {
199  $titles[] = $lostPool->getTitle();
200  }
201 
202  return implode(', ', $titles);
203  }
204 
205  private function getAfterRebuildQuestionStageCommand(): string
206  {
207  switch ($this->getContext()) {
208  case self::CONTEXT_POOL_SELECTION:
209 
211 
212  case self::CONTEXT_GENERAL_CONFIG:
213  default:
214 
216  }
217  }
218 
220  {
221  $this->ctrl->setParameter(
222  $this->getTargetGUI(),
225  );
226 
227  $href = $this->ctrl->getLinkTarget(
228  $this->getTargetGUI(),
230  );
231  $label = $this->lng->txt('tst_btn_rebuild_random_question_stage');
232 
233  return $this->ui_factory->button()->standard($label, $href)->withLoadingAnimationOnClick(true);
234  }
235 
236  private function buildGeneralConfigSubTabLink(): string
237  {
238  $href = $this->ctrl->getLinkTarget(
239  $this->getTargetGUI(),
241  );
242 
243  $label = $this->lng->txt('tst_rnd_quest_cfg_tab_general');
244 
245  return "<a href=\"{$href}\">{$label}</a>";
246  }
247 
248  private function buildQuestionSelectionSubTabLink(): string
249  {
250  $href = $this->ctrl->getLinkTarget(
251  $this->getTargetGUI(),
253  );
254 
255  $label = $this->lng->txt('tst_rnd_quest_cfg_tab_pool');
256 
257  return "<a href=\"{$href}\">{$label}</a>";
258  }
259 
264  private function isNoAvailableQuestionPoolsHintRequired(): bool
265  {
266  if ($this->getContext() !== self::CONTEXT_POOL_SELECTION) {
267  return false;
268  }
269 
270  if ($this->questionSetConfig->doesSelectableQuestionPoolsExist()) {
271  return false;
272  }
273 
274  return true;
275  }
276 
282  {
283  if ($this->getContext() != self::CONTEXT_GENERAL_CONFIG) {
284  return false;
285  }
286 
287  if (!$this->questionSetConfig->isQuestionAmountConfigurationModePerPool()) {
288  return false;
289  }
290 
291  return true;
292  }
293 
295  {
296  if ($this->getContext() != self::CONTEXT_POOL_SELECTION) {
297  return false;
298  }
299 
300  if (!$this->questionSetConfig->isQuestionAmountConfigurationModePerTest()) {
301  return false;
302  }
303 
304  return true;
305  }
306 
307  protected function buildLostPoolsReportMessage(): string
308  {
309  $report = sprintf(
310  $this->lng->txt('tst_msg_rand_quest_set_lost_pools'),
312  );
313 
314  if ($this->getContext() == self::CONTEXT_GENERAL_CONFIG) {
315  $action = $this->ctrl->getLinkTarget(
316  $this->getTargetGUI(),
318  );
319 
320  $link = $this->ui_factory->link()->standard(
321  $this->lng->txt('tst_msg_rand_quest_set_lost_pools_link'),
322  $action
323  );
324 
325  $msg_box = $this->ui_factory->messageBox()->info($report)->withLinks(array($link));
326  } else {
327  $msg_box = $this->ui_factory->messageBox()->info($report);
328  }
329 
330  return $this->ui_renderer->render($msg_box);
331  }
332 
333  protected function buildLastSyncMessage(): string
334  {
335  $sync_date = new ilDateTime(
336  $this->questionSetConfig->getLastQuestionSyncTimestamp(),
338  );
339  $message = sprintf(
340  $this->lng->txt('tst_msg_rand_quest_set_stage_pool_last_sync'),
342  );
343  if ($this->doesParticipantDataExists()) {
344  $message .= '<br>' . $this->lng->txt('tst_msg_cannot_modify_random_question_set_conf_due_to_part');
345 
346  $msg_box = $this->ui_factory->messageBox()->info($message);
347  } else {
348  $href = $this->ctrl->getLinkTargetByClass(ilTestRandomQuestionSetConfigGUI::class, ilTestRandomQuestionSetConfigGUI::CMD_RESET_POOLSYNC);
349  $label = $this->lng->txt('tst_btn_reset_pool_sync');
350 
351  $buttons = [
352  $this->ui_factory->button()->standard($label, $href)
353  ];
354 
355  $msg_box = $this->ui_factory->messageBox()
356  ->info($message)
357  ->withButtons($buttons);
358  }
359 
360  return $this->ui_renderer->render($msg_box);
361  }
362 
363  protected function buildNotSyncedMessage(): string
364  {
365  $message = $this->lng->txt('tst_msg_rand_quest_set_not_sync');
366  $button = $this->buildQuestionStageRebuildButton();
367  $msg_box = $this->ui_factory->messageBox()->info($message)->withButtons(array($button));
368 
369  return $this->ui_renderer->render($msg_box);
370  }
371 }
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const IL_CAL_UNIX
$lng
$message
Definition: xapiexit.php:32
__construct(private ilLanguage $lng, private UIFactory $ui_factory, private UIRenderer $ui_renderer, private ilCtrl $ctrl)