ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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 ilCtrlInterface $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  return;
161  }
162 
163  if ($this->getLostPools()) {
165  return;
166  }
167 
168  if (!$this->questionSetConfig->isQuestionAmountConfigComplete()) {
169  $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_incomplete_quest_amount_cfg'));
170 
172  $this->addValidationReport(
173  sprintf(
174  $this->lng->txt('tst_msg_rand_quest_set_change_quest_amount_here'),
176  )
177  );
178  return;
179  }
180 
182  $this->addValidationReport(
183  sprintf(
184  $this->lng->txt('tst_msg_rand_quest_set_change_quest_amount_here'),
186  )
187  );
188  return;
189  }
190  }
191 
192  if (!$this->questionSetConfig->hasSourcePoolDefinitions()) {
193  $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_no_src_pool_defs'));
194  return;
195  }
196 
197  if ($this->questionSetConfig->getLastQuestionSyncTimestamp() === 0 ||
198  $this->questionSetConfig->getLastQuestionSyncTimestamp() === null) {
199  $this->setSyncInfoMessage($this->buildNotSyncedMessage());
200  return;
201  }
202 
203  if (!$this->questionSetConfig->isQuestionSetBuildable()) {
204  $this->setValidationFailed(true);
205  $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_pass_not_buildable'));
206  $this->addValidationReport(implode('<br />', $this->questionSetConfig->getBuildableMessages()));
207  return;
208  }
209 
210  if ($this->questionSetConfig->getLastQuestionSyncTimestamp()) {
211  $this->setSyncInfoMessage($this->buildLastSyncMessage());
212  return;
213  }
214  }
215 
216  private function buildLostQuestionPoolsString(): string
217  {
218  $titles = [];
219 
220  foreach ($this->getLostPools() as $lostPool) {
221  $titles[] = $lostPool->getTitle();
222  }
223 
224  return implode(', ', $titles);
225  }
226 
227  private function getAfterRebuildQuestionStageCommand(): string
228  {
229  switch ($this->getContext()) {
230  case self::CONTEXT_POOL_SELECTION:
231 
233 
234  case self::CONTEXT_GENERAL_CONFIG:
235  default:
236 
238  }
239  }
240 
242  {
243  $this->ctrl->setParameter(
244  $this->getTargetGUI(),
247  );
248 
249  $href = $this->ctrl->getLinkTarget(
250  $this->getTargetGUI(),
252  );
253  $label = $this->lng->txt('tst_btn_rebuild_random_question_stage');
254 
255  return $this->ui_factory->button()->standard($label, $href)->withLoadingAnimationOnClick(true);
256  }
257 
258  private function buildGeneralConfigSubTabLink(): string
259  {
260  $href = $this->ctrl->getLinkTarget(
261  $this->getTargetGUI(),
263  );
264 
265  $label = $this->lng->txt('tst_rnd_quest_cfg_tab_general');
266 
267  return "<a href=\"{$href}\">{$label}</a>";
268  }
269 
270  private function buildQuestionSelectionSubTabLink(): string
271  {
272  $href = $this->ctrl->getLinkTarget(
273  $this->getTargetGUI(),
275  );
276 
277  $label = $this->lng->txt('tst_rnd_quest_cfg_tab_pool');
278 
279  return "<a href=\"{$href}\">{$label}</a>";
280  }
281 
286  private function isNoAvailableQuestionPoolsHintRequired(): bool
287  {
288  if ($this->getContext() !== self::CONTEXT_POOL_SELECTION) {
289  return false;
290  }
291 
292  if ($this->questionSetConfig->doesSelectableQuestionPoolsExist()) {
293  return false;
294  }
295 
296  return true;
297  }
298 
304  {
305  if ($this->getContext() != self::CONTEXT_GENERAL_CONFIG) {
306  return false;
307  }
308 
309  if (!$this->questionSetConfig->isQuestionAmountConfigurationModePerPool()) {
310  return false;
311  }
312 
313  return true;
314  }
315 
317  {
318  if ($this->getContext() != self::CONTEXT_POOL_SELECTION) {
319  return false;
320  }
321 
322  if (!$this->questionSetConfig->isQuestionAmountConfigurationModePerTest()) {
323  return false;
324  }
325 
326  return true;
327  }
328 
329  protected function buildLostPoolsReportMessage(): string
330  {
331  $report = sprintf(
332  $this->lng->txt('tst_msg_rand_quest_set_lost_pools'),
334  );
335 
336  if ($this->getContext() == self::CONTEXT_GENERAL_CONFIG) {
337  $action = $this->ctrl->getLinkTarget(
338  $this->getTargetGUI(),
340  );
341 
342  $link = $this->ui_factory->link()->standard(
343  $this->lng->txt('tst_msg_rand_quest_set_lost_pools_link'),
344  $action
345  );
346 
347  $msg_box = $this->ui_factory->messageBox()->info($report)->withLinks([$link]);
348  } else {
349  $msg_box = $this->ui_factory->messageBox()->info($report);
350  }
351 
352  return $this->ui_renderer->render($msg_box);
353  }
354 
355  protected function buildLastSyncMessage(): string
356  {
357  $sync_date = new ilDateTime(
358  $this->questionSetConfig->getLastQuestionSyncTimestamp(),
360  );
361  $message = sprintf(
362  $this->lng->txt('tst_msg_rand_quest_set_stage_pool_last_sync'),
364  );
365  if ($this->doesParticipantDataExists()) {
366  $message .= '<br>' . $this->lng->txt('tst_msg_cannot_modify_random_question_set_conf_due_to_part');
367 
368  $msg_box = $this->ui_factory->messageBox()->info($message);
369  } else {
370  $href = $this->ctrl->getLinkTargetByClass(ilTestRandomQuestionSetConfigGUI::class, ilTestRandomQuestionSetConfigGUI::CMD_RESET_POOLSYNC);
371  $label = $this->lng->txt('tst_btn_reset_pool_sync');
372 
373  $buttons = [
374  $this->ui_factory->button()->standard($label, $href)
375  ];
376 
377  $msg_box = $this->ui_factory->messageBox()
378  ->info($message)
379  ->withButtons($buttons);
380  }
381 
382  return $this->ui_renderer->render($msg_box);
383  }
384 
385  protected function buildNotSyncedMessage(): string
386  {
387  $message = $this->lng->txt('tst_msg_rand_quest_set_not_sync');
388  $button = $this->buildQuestionStageRebuildButton();
389  $msg_box = $this->ui_factory->messageBox()->info($message)->withButtons([$button]);
390 
391  return $this->ui_renderer->render($msg_box);
392  }
393 }
const IL_CAL_UNIX
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(private ilLanguage $lng, private UIFactory $ui_factory, private UIRenderer $ui_renderer, private ilCtrlInterface $ctrl)
global $lng
Definition: privfeed.php:31
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
$message
Definition: xapiexit.php:31