ILIAS  release_8 Revision v8.24
class.ilTestRandomQuestionSetConfigStateMessageHandler.php
Go to the documentation of this file.
1<?php
2
20use ILIAS\UI\Component\Button\Standard as StandardButton;
21
29{
30 protected UIServices $ui;
31 protected ilLanguage $lng;
32 protected ilCtrl $ctrl;
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(
56 ) {
57 $this->lng = $lng;
58 $this->ui = $ui;
59 $this->ctrl = $ctrl;
60 $this->validationFailed = false;
61 $this->validationReports = array();
62 }
63
67 public function getLostPools(): array
68 {
69 return $this->lostPools;
70 }
71
75 public function setLostPools(array $lostPools): void
76 {
77 $this->lostPools = $lostPools;
78 }
79
83 public function doesParticipantDataExists(): bool
84 {
86 }
87
89 {
90 $this->participantDataExists = $participantDataExists;
91 }
92
94 {
95 return $this->targetGUI;
96 }
97
99 {
100 $this->targetGUI = $targetGUI;
101 }
102
103 public function getContext(): string
104 {
105 return $this->context;
106 }
107
108 public function setContext(string $context)
109 {
110 $this->context = $context;
111 }
112
114 {
116 }
117
119 {
120 $this->questionSetConfig = $questionSetConfig;
121 }
122
123 public function isValidationFailed(): bool
124 {
126 }
127
128 protected function setValidationFailed(bool $validationFailed)
129 {
130 $this->validationFailed = $validationFailed;
131 }
132
133 public function getValidationReportHtml(): string
134 {
135 return implode('<br />', $this->validationReports);
136 }
137
138 public function hasValidationReports(): int
139 {
140 return count($this->validationReports);
141 }
142
143 protected function addValidationReport(string $validationReport)
144 {
145 $this->validationReports[] = $validationReport;
146 }
147
148 public function getSyncInfoMessage(): string
149 {
151 }
152
153 protected function setSyncInfoMessage(string $message): void
154 {
155 $this->sync_info_message = $message;
156 }
157
158 public function handle(): void
159 {
161 $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_no_pools_available'));
162 } elseif ($this->getLostPools()) {
164 } elseif (!$this->questionSetConfig->isQuestionAmountConfigComplete()) {
165 $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_incomplete_quest_amount_cfg'));
166
168 $this->addValidationReport(
169 sprintf(
170 $this->lng->txt('tst_msg_rand_quest_set_change_quest_amount_here'),
171 $this->buildGeneralConfigSubTabLink()
172 )
173 );
175 $this->addValidationReport(
176 sprintf(
177 $this->lng->txt('tst_msg_rand_quest_set_change_quest_amount_here'),
178 $this->buildQuestionSelectionSubTabLink()
179 )
180 );
181 }
182 } elseif (!$this->questionSetConfig->hasSourcePoolDefinitions()) {
183 $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_no_src_pool_defs'));
184 } elseif ($this->questionSetConfig->getLastQuestionSyncTimestamp() === 0 ||
185 $this->questionSetConfig->getLastQuestionSyncTimestamp() === null) {
187 } elseif (!$this->questionSetConfig->isQuestionSetBuildable()) {
188 $this->setValidationFailed(true);
189 $this->addValidationReport($this->lng->txt('tst_msg_rand_quest_set_pass_not_buildable'));
190 $this->addValidationReport(implode('<br />', $this->questionSetConfig->getBuildableMessages()));
191 } elseif ($this->questionSetConfig->getLastQuestionSyncTimestamp()) {
193 }
194 }
195
196 private function buildLostQuestionPoolsString(): string
197 {
198 $titles = array();
199
200 foreach ($this->getLostPools() as $lostPool) {
201 $titles[] = $lostPool->getTitle();
202 }
203
204 return implode(', ', $titles);
205 }
206
207 private function getAfterRebuildQuestionStageCommand(): string
208 {
209 switch ($this->getContext()) {
211
213
215 default:
216
218 }
219 }
220
221 private function buildQuestionStageRebuildButton(): StandardButton
222 {
223 $this->ctrl->setParameter(
224 $this->getTargetGUI(),
227 );
228
229 $href = $this->ctrl->getLinkTarget(
230 $this->getTargetGUI(),
232 );
233 $label = $this->lng->txt('tst_btn_rebuild_random_question_stage');
234
235 return $this->ui->factory()->button()->standard($label, $href)->withLoadingAnimationOnClick(true);
236 }
237
238 private function buildGeneralConfigSubTabLink(): string
239 {
240 $href = $this->ctrl->getLinkTarget(
241 $this->getTargetGUI(),
243 );
244
245 $label = $this->lng->txt('tst_rnd_quest_cfg_tab_general');
246
247 return "<a href=\"{$href}\">{$label}</a>";
248 }
249
250 private function buildQuestionSelectionSubTabLink(): string
251 {
252 $href = $this->ctrl->getLinkTarget(
253 $this->getTargetGUI(),
255 );
256
257 $label = $this->lng->txt('tst_rnd_quest_cfg_tab_pool');
258
259 return "<a href=\"{$href}\">{$label}</a>";
260 }
261
267 {
268 if ($this->getContext() != self::CONTEXT_POOL_SELECTION) {
269 return false;
270 }
271
272 if ($this->questionSetConfig->doesSelectableQuestionPoolsExist()) {
273 return false;
274 }
275
276 return true;
277 }
278
284 {
285 if ($this->getContext() != self::CONTEXT_GENERAL_CONFIG) {
286 return false;
287 }
288
289 if (!$this->questionSetConfig->isQuestionAmountConfigurationModePerPool()) {
290 return false;
291 }
292
293 return true;
294 }
295
297 {
298 if ($this->getContext() != self::CONTEXT_POOL_SELECTION) {
299 return false;
300 }
301
302 if (!$this->questionSetConfig->isQuestionAmountConfigurationModePerTest()) {
303 return false;
304 }
305
306 return true;
307 }
308
309 protected function buildLostPoolsReportMessage(): string
310 {
311 $report = sprintf(
312 $this->lng->txt('tst_msg_rand_quest_set_lost_pools'),
313 $this->buildLostQuestionPoolsString()
314 );
315
316 if ($this->getContext() == self::CONTEXT_GENERAL_CONFIG) {
317 $action = $this->ctrl->getLinkTarget(
318 $this->getTargetGUI(),
320 );
321
322 $link = $this->ui->factory()->link()->standard(
323 $this->lng->txt('tst_msg_rand_quest_set_lost_pools_link'),
324 $action
325 );
326
327 $msg_box = $this->ui->factory()->messageBox()->info($report)->withLinks(array($link));
328 } else {
329 $msg_box = $this->ui->factory()->messageBox()->info($report);
330 }
331
332 return $this->ui->renderer()->render($msg_box);
333 }
334
335 protected function buildLastSyncMessage(): string
336 {
337 $sync_date = new ilDateTime(
338 $this->questionSetConfig->getLastQuestionSyncTimestamp(),
340 );
341 $message = sprintf(
342 $this->lng->txt('tst_msg_rand_quest_set_stage_pool_last_sync'),
344 );
345 if ($this->doesParticipantDataExists()) {
346 $message .= '<br>' . $this->lng->txt('tst_msg_cannot_modify_random_question_set_conf_due_to_part');
347
348 $msg_box = $this->ui->factory()->messageBox()->info($message);
349 } else {
350 $href = $this->ctrl->getLinkTargetByClass(ilTestRandomQuestionSetConfigGUI::class, ilTestRandomQuestionSetConfigGUI::CMD_RESET_POOLSYNC);
351 $label = $this->lng->txt('tst_btn_reset_pool_sync');
352
353 $buttons = [
354 $this->ui->factory()->button()->standard($label, $href)
355 ];
356
357 $msg_box = $this->ui->factory()->messageBox()
358 ->info($message)
359 ->withButtons($buttons);
360 }
361
362 return $this->ui->renderer()->render($msg_box);
363 }
364
365 protected function buildNotSyncedMessage(): string
366 {
367 $message = $this->lng->txt('tst_msg_rand_quest_set_not_sync');
368 $button = $this->buildQuestionStageRebuildButton();
369 $msg_box = $this->ui->factory()->messageBox()->info($message)->withButtons(array($button));
370
371 return $this->ui->renderer()->render($msg_box);
372 }
373}
Provides fluid interface to RBAC services.
Definition: UIServices.php:24
const IL_CAL_UNIX
Class ilCtrl provides processing control methods.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
language handling
This describes a standard button.
Definition: Standard.php:27
$message
Definition: xapiexit.php:32