ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
SettingsFinishing.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
30 
32 {
33  public function __construct(
34  int $test_id,
35  protected bool $show_answer_overview = false,
36  protected bool $concluding_remarks_enabled = false,
37  protected ?string $concluding_remarks_text = '',
38  protected ?int $concluding_remarks_page_id = null,
39  protected int $redirection_mode = \ilObjTest::REDIRECT_NONE,
40  protected ?string $redirection_url = null,
41  protected int $mail_notification_content_type = 0,
42  protected bool $always_send_mail_notification = false
43  ) {
44  parent::__construct($test_id);
45  }
46 
47  public function toForm(
51  ?array $environment = null
52  ): FormInput {
53  $inputs['show_answer_overview'] = $f->checkbox(
54  $lng->txt('enable_examview'),
55  $lng->txt('enable_examview_desc')
56  )->withValue($this->getShowAnswerOverview());
57 
58  $inputs['show_concluding_remarks'] = $f->checkbox(
59  $lng->txt('final_statement'),
60  $lng->txt('final_statement_show_desc')
61  )->withValue((bool) $this->getConcludingRemarksEnabled());
62 
63  $inputs['redirect_after_finish'] = $this->getRedirectionInputs($lng, $f, $refinery);
64 
65  $inputs['finish_notification'] = $this->getMailNotificationInputs($lng, $f, $refinery);
66 
67  return $f->section($inputs, $lng->txt('tst_final_information'));
68  }
69 
70  private function getRedirectionInputs(
74  ): OptionalGroup {
75  $redirection_trafo = $refinery->custom()->transformation(
76  static function (?array $v): array {
77  if ($v === null) {
78  return [
79  'redirect_mode' => \ilObjTest::REDIRECT_NONE,
80  'redirect_url' => ''
81  ];
82  }
83 
84  return $v;
85  }
86  );
87 
88  $sub_inputs_redirect = [
89  'redirect_mode' => $f->radio(
90  $lng->txt('redirect_after_finishing_rule')
91  )->withOption(
93  $lng->txt('redirect_always')
94  )->withOption(
96  $lng->txt('redirect_in_kiosk_mode')
97  )->withRequired(true)
98  ->withAdditionalTransformation($refinery->kindlyTo()->int()),
99  'redirect_url' => $f->text(
100  $lng->txt('redirection_url')
101  )->withRequired(true)
102  ->withAdditionalTransformation($refinery->string()->hasMaxLength(4000))
103  ];
104 
105  $redirection_input = $f->optionalGroup(
106  $sub_inputs_redirect,
107  $lng->txt('redirect_after_finishing_tst'),
108  $lng->txt('redirect_after_finishing_tst_desc')
109  )->withValue(null)
110  ->withAdditionalTransformation($redirection_trafo);
111 
112  if ($this->getRedirectionMode() === \ilObjTest::REDIRECT_NONE) {
113  return $redirection_input;
114  }
115 
116  return $redirection_input->withValue(
117  [
118  'redirect_mode' => $this->getRedirectionMode(),
119  'redirect_url' => $this->getRedirectionUrl()
120  ]
121  );
122  }
123 
124  private function getMailNotificationInputs(
125  \ilLanguage $lng,
128  ): OptionalGroup {
129  $notification_trafo = $refinery->custom()->transformation(
130  static function (?array $v): array {
131  if ($v === null) {
132  return [
133  'notification_content_type' => 0,
134  'always_notify' => false
135  ];
136  }
137 
138  return $v;
139  }
140  );
141 
142  $sub_inputs_finish_notification = [
143  'notification_content_type' => $f->radio(
144  $lng->txt('tst_finish_notification_content_type')
145  )->withOption(
146  '1',
147  $lng->txt('tst_finish_notification_simple')
148  )->withOption(
149  '2',
150  $lng->txt('tst_finish_notification_advanced')
151  )->withRequired(true)
152  ->withValue('1')
153  ->withAdditionalTransformation($refinery->kindlyTo()->int()),
154  'always_notify' => $f->checkbox(
155  $lng->txt('mailnottype'),
156  $lng->txt('mailnottype_desc')
157  )
158  ];
159 
160  $mail_notification_inputs = $f->optionalGroup(
161  $sub_inputs_finish_notification,
162  $lng->txt('tst_finish_notification'),
163  $lng->txt('tst_finish_notification_desc')
164  )->withValue(null)
165  ->withAdditionalTransformation($notification_trafo);
166 
167  if ($this->getMailNotificationContentType() === 0) {
168  return $mail_notification_inputs;
169  }
170 
171  return $mail_notification_inputs->withValue(
172  [
173  'notification_content_type' => (string) $this->getMailNotificationContentType(),
174  'always_notify' => (bool) $this->getAlwaysSendMailNotification()
175  ]
176  );
177  }
178 
179  public function toStorage(): array
180  {
181  return [
182  'enable_examview' => ['integer', (int) $this->getShowAnswerOverview()],
183  'showfinalstatement' => ['integer', (int) $this->getConcludingRemarksEnabled()],
184  'finalstatement' => ['text', $this->getConcludingRemarksText()],
185  'concluding_remarks_page_id' => ['integer', $this->getConcludingRemarksPageId()],
186  'redirection_mode' => ['integer', $this->getRedirectionMode()],
187  'redirection_url' => ['text', $this->getRedirectionUrl()],
188  'mailnotification' => ['integer', $this->getMailNotificationContentType()],
189  'mailnottype' => ['integer', (int) $this->getAlwaysSendMailNotification()]
190  ];
191  }
192 
193  public function toLog(AdditionalInformationGenerator $additional_info): array
194  {
195  $log_array = [
201 
202  ];
203 
204  switch ($this->getRedirectionMode()) {
205  case \ilObjTest::REDIRECT_NONE:
206  $log_array[AdditionalInformationGenerator::KEY_TEST_REDIRECT_MODE] = $additional_info
207  ->getNoneTag();
208  break;
209  case \ilObjTest::REDIRECT_ALWAYS:
210  $log_array[AdditionalInformationGenerator::KEY_TEST_REDIRECT_MODE] = $additional_info
211  ->getTagForLangVar('redirect_always');
212  break;
213  case \ilObjTest::REDIRECT_KIOSK:
214  $log_array[AdditionalInformationGenerator::KEY_TEST_REDIRECT_MODE] = $additional_info
215  ->getTagForLangVar('redirect_in_kiosk_mode');
216  break;
217  }
218 
219  switch ($this->getMailNotificationContentType()) {
220  case 0:
222  ->getNoneTag();
223  break;
224  case 1:
226  ->getTagForLangVar('tst_finish_notification_simple');
229  break;
230  case 2:
232  ->getTagForLangVar('tst_finish_notification_advanced');
235  break;
236  }
237 
238  return $log_array;
239  }
240 
241  public function getShowAnswerOverview(): bool
242  {
243  return $this->show_answer_overview;
244  }
245 
246  public function withShowAnswerOverview(bool $show_answer_overview): self
247  {
248  $clone = clone $this;
249  $clone->show_answer_overview = $show_answer_overview;
250  return $clone;
251  }
252 
253  public function getConcludingRemarksEnabled(): bool
254  {
255  return $this->concluding_remarks_enabled;
256  }
257 
258  public function withConcludingRemarksEnabled(bool $concluding_remarks_enabled): self
259  {
260  $clone = clone $this;
261  $clone->concluding_remarks_enabled = $concluding_remarks_enabled;
262  return $clone;
263  }
264 
265  public function getConcludingRemarksText(): string
266  {
267  return $this->concluding_remarks_text ?? '';
268  }
269 
270  public function getConcludingRemarksPageId(): ?int
271  {
272  return $this->concluding_remarks_page_id;
273  }
274 
275  public function withConcludingRemarksPageId(?int $concluding_remarks_page_id): self
276  {
277  $clone = clone $this;
278  $clone->concluding_remarks_page_id = $concluding_remarks_page_id;
279  return $clone;
280  }
281 
282  public function getRedirectionMode(): int
283  {
284  return $this->redirection_mode;
285  }
286 
287  public function withRedirectionMode(int $redirection_mode): self
288  {
289  $clone = clone $this;
290  $clone->redirection_mode = $redirection_mode;
291  return $clone;
292  }
293 
294  public function getRedirectionUrl(): ?string
295  {
296  return $this->redirection_url;
297  }
298 
299  public function withRedirectionUrl(?string $redirection_url): self
300  {
301  $clone = clone $this;
302  $clone->redirection_url = $redirection_url;
303  return $clone;
304  }
305 
307  {
308  return $this->mail_notification_content_type;
309  }
310 
311  public function withMailNotificationContentType(int $mail_notification_content_type): self
312  {
313  $clone = clone $this;
314  $clone->mail_notification_content_type = $mail_notification_content_type;
315  return $clone;
316  }
317 
318  public function getAlwaysSendMailNotification(): bool
319  {
320  return $this->always_send_mail_notification;
321  }
322 
323  public function withAlwaysSendMailNotification(bool $always_send_mail_notification): self
324  {
325  $clone = clone $this;
326  $clone->always_send_mail_notification = $always_send_mail_notification;
327  return $clone;
328  }
329 }
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, ?array $environment=null)
toLog(AdditionalInformationGenerator $additional_info)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This describes optional group inputs.
withMailNotificationContentType(int $mail_notification_content_type)
getRedirectionInputs(\ilLanguage $lng, FieldFactory $f, Refinery $refinery)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
withConcludingRemarksEnabled(bool $concluding_remarks_enabled)
const REDIRECT_NONE
__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 int $redirection_mode=\ilObjTest::REDIRECT_NONE, protected ?string $redirection_url=null, protected int $mail_notification_content_type=0, protected bool $always_send_mail_notification=false)
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
withAlwaysSendMailNotification(bool $always_send_mail_notification)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMailNotificationInputs(\ilLanguage $lng, FieldFactory $f, Refinery $refinery)
withConcludingRemarksPageId(?int $concluding_remarks_page_id)
__construct(Container $dic, ilPlugin $plugin)
global $lng
Definition: privfeed.php:31
const REDIRECT_ALWAYS
This describes inputs that can be used in forms.
Definition: FormInput.php:32
const REDIRECT_KIOSK