ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SettingsFinishing.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28use ILIAS\Refinery\Factory as Refinery;
29
31{
32 public function __construct(
33 int $test_id,
34 protected bool $show_answer_overview = false,
35 protected bool $concluding_remarks_enabled = false,
36 protected ?string $concluding_remarks_text = '',
37 protected ?int $concluding_remarks_page_id = null,
38 protected RedirectionModes $redirection_mode = RedirectionModes::NONE,
39 protected ?string $redirection_url = null,
40 protected int $mail_notification_content_type = 0,
41 protected bool $always_send_mail_notification = false
42 ) {
44 }
45
46 public function toForm(
48 FieldFactory $f,
50 ?array $environment = null
51 ): FormInput {
52 $inputs['show_answer_overview'] = $f->checkbox(
53 $lng->txt('enable_examview'),
54 $lng->txt('enable_examview_desc')
56
57 $inputs['show_concluding_remarks'] = $f->checkbox(
58 $lng->txt('final_statement'),
59 $lng->txt('final_statement_show_desc')
60 )->withValue((bool) $this->getConcludingRemarksEnabled());
61
62 $inputs['redirect_after_finish'] = $this->getRedirectionInputs($lng, $f, $refinery);
63
64 $inputs['finish_notification'] = $this->getMailNotificationInputs($lng, $f, $refinery);
65
66 return $f->section($inputs, $lng->txt('tst_final_information'));
67 }
68
69 private function getRedirectionInputs(
71 FieldFactory $f,
73 ): OptionalGroup {
74 $redirection_trafo = $refinery->custom()->transformation(
75 static function (?array $v): array {
76 if ($v === null) {
77 return [
78 'redirect_mode' => RedirectionModes::NONE,
79 'redirect_url' => ''
80 ];
81 }
82
83 return [
84 'redirect_mode' => RedirectionModes::tryFrom($v['redirect_mode'])
85 ?? RedirectionModes::NONE,
86 'redirect_url' => $v['redirect_url']
87 ];
88 }
89 );
90
91 $sub_inputs_redirect = [
92 'redirect_mode' => $f
93 ->radio($lng->txt('redirect_after_finishing_rule'))
94 ->withOption(
95 (string) RedirectionModes::ALWAYS->value,
96 $lng->txt('redirect_always')
97 )->withOption(
99 $lng->txt('redirect_always_to_logout')
100 )->withOption(
101 (string) RedirectionModes::IF_KIOSK_ACTIVATED->value,
102 $lng->txt('redirect_in_kiosk_mode')
103 )->withRequired(true)
104 ->withAdditionalTransformation($refinery->kindlyTo()->int()),
105 'redirect_url' => $f
106 ->text($lng->txt('redirection_url'))
107 ->withAdditionalTransformation($refinery->string()->hasMaxLength(4000))
109 $refinery->custom()->constraint(
110 static function ($v) use ($refinery): bool {
111 try {
112 return $v === '' || $refinery->to()->data('uri')->transform($v);
113 } catch (Throwable) {
114 return false;
115 }
116 },
117 $lng->txt('redirect_url_invalid')
118 )
119 )
120 ];
121
122 $redirection_input = $f
123 ->optionalGroup(
124 $sub_inputs_redirect,
125 $lng->txt('redirect_after_finishing_tst'),
126 $lng->txt('redirect_after_finishing_tst_desc')
127 )
128 ->withValue(null)
129 ->withAdditionalTransformation($redirection_trafo)
130 ->withAdditionalTransformation(
131 $refinery->custom()->constraint(
132 static function (array $v): bool {
133 return in_array(
134 $v['redirect_mode'],
135 [RedirectionModes::NONE, RedirectionModes::ALWAYS_TO_LOGOUT],
136 true
137 ) || $v['redirect_url'] !== '';
138 },
139 static function (\Closure $txt, array $value): string {
140 return sprintf(
141 $txt('redirect_url_required_for_rule'),
142 $value['redirect_mode'] === RedirectionModes::ALWAYS
143 ? $txt('redirect_always')
144 : $txt('redirect_in_kiosk_mode')
145 );
146 }
147 )
148 );
149
150 if ($this->getRedirectionMode() === RedirectionModes::NONE) {
151 return $redirection_input;
152 }
153
154 return $redirection_input->withValue(
155 [
156 'redirect_mode' => $this->getRedirectionMode()->value,
157 'redirect_url' => $this->getRedirectionUrl()
158 ]
159 );
160 }
161
164 FieldFactory $f,
166 ): OptionalGroup {
167 $notification_trafo = $refinery->custom()->transformation(
168 static function (?array $v): array {
169 if ($v === null) {
170 return [
171 'notification_content_type' => 0,
172 'always_notify' => false
173 ];
174 }
175
176 return $v;
177 }
178 );
179
180 $sub_inputs_finish_notification = [
181 'notification_content_type' => $f->radio(
182 $lng->txt('tst_finish_notification_content_type')
183 )->withOption(
184 '1',
185 $lng->txt('tst_finish_notification_simple')
186 )->withOption(
187 '2',
188 $lng->txt('tst_finish_notification_advanced')
189 )->withRequired(true)
190 ->withValue('1')
191 ->withAdditionalTransformation($refinery->kindlyTo()->int()),
192 'always_notify' => $f->checkbox(
193 $lng->txt('mailnottype'),
194 $lng->txt('mailnottype_desc')
195 )
196 ];
197
198 $mail_notification_inputs = $f->optionalGroup(
199 $sub_inputs_finish_notification,
200 $lng->txt('tst_finish_notification'),
201 $lng->txt('tst_finish_notification_desc')
202 )->withValue(null)
203 ->withAdditionalTransformation($notification_trafo);
204
205 if ($this->getMailNotificationContentType() === 0) {
206 return $mail_notification_inputs;
207 }
208
209 return $mail_notification_inputs->withValue(
210 [
211 'notification_content_type' => (string) $this->getMailNotificationContentType(),
212 'always_notify' => (bool) $this->getAlwaysSendMailNotification()
213 ]
214 );
215 }
216
217 public function toStorage(): array
218 {
219 return [
220 'enable_examview' => ['integer', (int) $this->getShowAnswerOverview()],
221 'showfinalstatement' => ['integer', (int) $this->getConcludingRemarksEnabled()],
222 'finalstatement' => ['text', $this->getConcludingRemarksText()],
223 'concluding_remarks_page_id' => ['integer', $this->getConcludingRemarksPageId()],
224 'redirection_mode' => ['integer', $this->getRedirectionMode()->value],
225 'redirection_url' => ['text', $this->getRedirectionUrl()],
226 'mailnotification' => ['integer', $this->getMailNotificationContentType()],
227 'mailnottype' => ['integer', (int) $this->getAlwaysSendMailNotification()]
228 ];
229 }
230
231 public function toLog(AdditionalInformationGenerator $additional_info): array
232 {
233 $log_array = [
234 AdditionalInformationGenerator::KEY_TEST_ANSWER_OVERVIEW_ENABLED => $additional_info
235 ->getEnabledDisabledTagForBool($this->getShowAnswerOverview()),
236 AdditionalInformationGenerator::KEY_TEST_CONCLUDING_REMARKS_ENABLED => $additional_info
237 ->getEnabledDisabledTagForBool($this->getConcludingRemarksEnabled()),
238 AdditionalInformationGenerator::KEY_TEST_REDIRECT_URL => $this->getRedirectionUrl(),
239
240 ];
241
242 switch ($this->getRedirectionMode()) {
243 case RedirectionModes::NONE:
244 $log_array[AdditionalInformationGenerator::KEY_TEST_REDIRECT_MODE] = $additional_info
245 ->getNoneTag();
246 break;
248 $log_array[AdditionalInformationGenerator::KEY_TEST_REDIRECT_MODE] = $additional_info
249 ->getTagForLangVar('redirect_always');
250 break;
251 case RedirectionModes::IF_KIOSK_ACTIVATED:
252 $log_array[AdditionalInformationGenerator::KEY_TEST_REDIRECT_MODE] = $additional_info
253 ->getTagForLangVar('redirect_in_kiosk_mode');
254 break;
255 }
256
257 switch ($this->getMailNotificationContentType()) {
258 case 0:
259 $log_array[AdditionalInformationGenerator::KEY_TEST_MAIL_NOTIFICATION_CONTENT_TYPE] = $additional_info
260 ->getNoneTag();
261 break;
262 case 1:
263 $log_array[AdditionalInformationGenerator::KEY_TEST_MAIL_NOTIFICATION_CONTENT_TYPE] = $additional_info
264 ->getTagForLangVar('tst_finish_notification_simple');
265 $log_array[AdditionalInformationGenerator::KEY_TEST_ALWAYS_SEND_NOTIFICATION] = $additional_info
266 ->getEnabledDisabledTagForBool($this->getAlwaysSendMailNotification());
267 break;
268 case 2:
269 $log_array[AdditionalInformationGenerator::KEY_TEST_MAIL_NOTIFICATION_CONTENT_TYPE] = $additional_info
270 ->getTagForLangVar('tst_finish_notification_advanced');
271 $log_array[AdditionalInformationGenerator::KEY_TEST_ALWAYS_SEND_NOTIFICATION] = $additional_info
272 ->getEnabledDisabledTagForBool($this->getAlwaysSendMailNotification());
273 break;
274 }
275
276 return $log_array;
277 }
278
279 public function getShowAnswerOverview(): bool
280 {
281 return $this->show_answer_overview;
282 }
283
284 public function withShowAnswerOverview(bool $show_answer_overview): self
285 {
286 $clone = clone $this;
287 $clone->show_answer_overview = $show_answer_overview;
288 return $clone;
289 }
290
291 public function getConcludingRemarksEnabled(): bool
292 {
293 return $this->concluding_remarks_enabled;
294 }
295
296 public function withConcludingRemarksEnabled(bool $concluding_remarks_enabled): self
297 {
298 $clone = clone $this;
299 $clone->concluding_remarks_enabled = $concluding_remarks_enabled;
300 return $clone;
301 }
302
303 public function getConcludingRemarksText(): string
304 {
305 return $this->concluding_remarks_text ?? '';
306 }
307
308 public function getConcludingRemarksPageId(): ?int
309 {
310 return $this->concluding_remarks_page_id;
311 }
312
313 public function withConcludingRemarksPageId(?int $concluding_remarks_page_id): self
314 {
315 $clone = clone $this;
316 $clone->concluding_remarks_page_id = $concluding_remarks_page_id;
317 return $clone;
318 }
319
321 {
322 return $this->redirection_mode;
323 }
324
325 public function withRedirectionMode(RedirectionModes $redirection_mode): self
326 {
327 $clone = clone $this;
328 $clone->redirection_mode = $redirection_mode;
329 return $clone;
330 }
331
332 public function getRedirectionUrl(): ?string
333 {
334 return $this->redirection_url;
335 }
336
337 public function withRedirectionUrl(?string $redirection_url): self
338 {
339 $clone = clone $this;
340 $clone->redirection_url = $redirection_url;
341 return $clone;
342 }
343
345 {
346 return $this->mail_notification_content_type;
347 }
348
349 public function withMailNotificationContentType(int $mail_notification_content_type): self
350 {
351 $clone = clone $this;
352 $clone->mail_notification_content_type = $mail_notification_content_type;
353 return $clone;
354 }
355
356 public function getAlwaysSendMailNotification(): bool
357 {
358 return $this->always_send_mail_notification;
359 }
360
361 public function withAlwaysSendMailNotification(bool $always_send_mail_notification): self
362 {
363 $clone = clone $this;
364 $clone->always_send_mail_notification = $always_send_mail_notification;
365 return $clone;
366 }
367}
const ALWAYS
Builds data types.
Definition: Factory.php:36
withConcludingRemarksPageId(?int $concluding_remarks_page_id)
getRedirectionInputs(\ilLanguage $lng, FieldFactory $f, Refinery $refinery)
getMailNotificationInputs(\ilLanguage $lng, FieldFactory $f, Refinery $refinery)
withAlwaysSendMailNotification(bool $always_send_mail_notification)
__construct(int $test_id, protected bool $show_answer_overview=false, protected bool $concluding_remarks_enabled=false, protected ?string $concluding_remarks_text='', protected ?int $concluding_remarks_page_id=null, protected RedirectionModes $redirection_mode=RedirectionModes::NONE, protected ?string $redirection_url=null, protected int $mail_notification_content_type=0, protected bool $always_send_mail_notification=false)
withMailNotificationContentType(int $mail_notification_content_type)
withRedirectionMode(RedirectionModes $redirection_mode)
toLog(AdditionalInformationGenerator $additional_info)
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, ?array $environment=null)
withConcludingRemarksEnabled(bool $concluding_remarks_enabled)
language handling
$txt
Definition: error.php:31
This describes inputs that can be used in forms.
Definition: FormInput.php:33
This is what a factory for input fields looks like.
Definition: Factory.php:31
This describes optional group inputs.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))