ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilObjTestSettingsFinishing.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
27 {
28  public function __construct(
29  int $test_id,
30  protected bool $show_answer_overview = false,
31  protected bool $concluding_remarks_enabled = false,
32  protected ?string $concluding_remarks_text = '',
33  protected ?int $concluding_remarks_page_id = null,
34  protected int $redirection_mode = ilObjTest::REDIRECT_NONE,
35  protected ?string $redirection_url = null,
36  protected int $mail_notification_content_type = 0,
37  protected bool $always_send_mail_notification = false
38  ) {
39  parent::__construct($test_id);
40  }
41 
42  public function toForm(
46  array $environment = null
47  ): FormInput {
48  $inputs['show_answer_overview'] = $f->checkbox(
49  $lng->txt('enable_examview'),
50  $lng->txt('enable_examview_desc')
51  )->withValue($this->getShowAnswerOverview());
52 
53  $inputs['show_concluding_remarks'] = $f->checkbox(
54  $lng->txt('final_statement'),
55  $lng->txt('final_statement_show_desc')
56  )->withValue((bool) $this->getConcludingRemarksEnabled());
57 
58  $inputs['redirect_after_finish'] = $this->getRedirectionInputs($lng, $f, $refinery);
59 
60  $inputs['finish_notification'] = $this->getMailNotificationInputs($lng, $f, $refinery);
61 
62  return $f->section($inputs, $lng->txt('tst_final_information'));
63  }
64 
65  private function getRedirectionInputs(
69  ): OptionalGroup {
70  $redirection_trafo = $refinery->custom()->transformation(
71  static function (?array $v): array {
72  if ($v === null) {
73  return [
74  'redirect_mode' => ilObjTest::REDIRECT_NONE,
75  'redirect_url' => ''
76  ];
77  }
78 
79  return $v;
80  }
81  );
82 
83  $sub_inputs_redirect = [
84  'redirect_mode' => $f->radio(
85  $lng->txt('redirect_after_finishing_rule')
86  )->withOption(
88  $lng->txt('redirect_always')
89  )->withOption(
91  $lng->txt('redirect_in_kiosk_mode')
92  )->withRequired(true)
93  ->withAdditionalTransformation($refinery->kindlyTo()->int()),
94  'redirect_url' => $f->text(
95  $lng->txt('redirection_url')
96  )->withRequired(true)
97  ->withAdditionalTransformation($refinery->string()->hasMaxLength(4000))
98  ];
99 
100  $redirection_input = $f->optionalGroup(
101  $sub_inputs_redirect,
102  $lng->txt('redirect_after_finishing_tst'),
103  $lng->txt('redirect_after_finishing_tst_desc')
104  )->withValue(null)
105  ->withAdditionalTransformation($redirection_trafo);
106 
107  if ($this->getRedirectionMode() === ilObjTest::REDIRECT_NONE) {
108  return $redirection_input;
109  }
110 
111  return $redirection_input->withValue(
112  [
113  'redirect_mode' => $this->getRedirectionMode(),
114  'redirect_url' => $this->getRedirectionUrl()
115  ]
116  );
117  }
118 
119  private function getMailNotificationInputs(
123  ): OptionalGroup {
124  $notification_trafo = $refinery->custom()->transformation(
125  static function (?array $v): array {
126  if ($v === null) {
127  return [
128  'notification_content_type' => 0,
129  'always_notify' => false
130  ];
131  }
132 
133  return $v;
134  }
135  );
136 
137  $sub_inputs_finish_notification = [
138  'notification_content_type' => $f->radio(
139  $lng->txt('tst_finish_notification_content_type')
140  )->withOption(
141  '1',
142  $lng->txt('tst_finish_notification_simple')
143  )->withOption(
144  '2',
145  $lng->txt('tst_finish_notification_advanced')
146  )->withRequired(true)
147  ->withValue('1')
148  ->withAdditionalTransformation($refinery->kindlyTo()->int()),
149  'always_notify' => $f->checkbox(
150  $lng->txt('mailnottype'),
151  $lng->txt('mailnottype_desc')
152  )
153  ];
154 
155  $mail_notification_inputs = $f->optionalGroup(
156  $sub_inputs_finish_notification,
157  $lng->txt('tst_finish_notification'),
158  $lng->txt('tst_finish_notification_desc')
159  )->withValue(null)
160  ->withAdditionalTransformation($notification_trafo);
161 
162  if ($this->getMailNotificationContentType() === 0) {
163  return $mail_notification_inputs;
164  }
165 
166  return $mail_notification_inputs->withValue(
167  [
168  'notification_content_type' => (string) $this->getMailNotificationContentType(),
169  'always_notify' => (bool) $this->getAlwaysSendMailNotification()
170  ]
171  );
172  }
173 
174  public function toStorage(): array
175  {
176  return [
177  'enable_examview' => ['integer', (int) $this->getShowAnswerOverview()],
178  'showfinalstatement' => ['integer', (int) $this->getConcludingRemarksEnabled()],
179  'finalstatement' => ['text', $this->getConcludingRemarksText()],
180  'concluding_remarks_page_id' => ['integer', $this->getConcludingRemarksPageId()],
181  'redirection_mode' => ['integer', $this->getRedirectionMode()],
182  'redirection_url' => ['text', $this->getRedirectionUrl()],
183  'mailnotification' => ['integer', $this->getMailNotificationContentType()],
184  'mailnottype' => ['integer', (int) $this->getAlwaysSendMailNotification()]
185  ];
186  }
187 
188  public function getShowAnswerOverview(): bool
189  {
190  return $this->show_answer_overview;
191  }
192 
193  public function withShowAnswerOverview(bool $show_answer_overview): self
194  {
195  $clone = clone $this;
196  $clone->show_answer_overview = $show_answer_overview;
197  return $clone;
198  }
199 
200  public function getConcludingRemarksEnabled(): bool
201  {
202  return $this->concluding_remarks_enabled;
203  }
204 
205  public function withConcludingRemarksEnabled(bool $concluding_remarks_enabled): self
206  {
207  $clone = clone $this;
208  $clone->concluding_remarks_enabled = $concluding_remarks_enabled;
209  return $clone;
210  }
211 
212  public function getConcludingRemarksText(): string
213  {
214  return $this->concluding_remarks_text ?? '';
215  }
216 
217  public function getConcludingRemarksPageId(): ?int
218  {
219  return $this->concluding_remarks_page_id;
220  }
221 
222  public function withConcludingRemarksPageId(?int $concluding_remarks_page_id): self
223  {
224  $clone = clone $this;
225  $clone->concluding_remarks_page_id = $concluding_remarks_page_id;
226  return $clone;
227  }
228 
229  public function getRedirectionMode(): int
230  {
231  return $this->redirection_mode;
232  }
233 
234  public function withRedirectionMode(int $redirection_mode): self
235  {
236  $clone = clone $this;
237  $clone->redirection_mode = $redirection_mode;
238  return $clone;
239  }
240 
241  public function getRedirectionUrl(): ?string
242  {
243  return $this->redirection_url;
244  }
245 
246  public function withRedirectionUrl(?string $redirection_url): self
247  {
248  $clone = clone $this;
249  $clone->redirection_url = $redirection_url;
250  return $clone;
251  }
252 
254  {
255  return $this->mail_notification_content_type;
256  }
257 
258  public function withMailNotificationContentType(int $mail_notification_content_type): self
259  {
260  $clone = clone $this;
261  $clone->mail_notification_content_type = $mail_notification_content_type;
262  return $clone;
263  }
264 
265  public function getAlwaysSendMailNotification(): bool
266  {
267  return $this->always_send_mail_notification;
268  }
269 
270  public function withAlwaysSendMailNotification(bool $always_send_mail_notification): self
271  {
272  $clone = clone $this;
273  $clone->always_send_mail_notification = $always_send_mail_notification;
274  return $clone;
275  }
276 }
This is what a factory for input fields looks like.
Definition: Factory.php:28
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...
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, array $environment=null)
getMailNotificationInputs(ilLanguage $lng, FieldFactory $f, Refinery $refinery)
withConcludingRemarksEnabled(bool $concluding_remarks_enabled)
This describes optional group inputs.
withRedirectionUrl(?string $redirection_url)
__construct(VocabulariesInterface $vocabularies)
$lng
withMailNotificationContentType(int $mail_notification_content_type)
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:58
withRedirectionMode(int $redirection_mode)
withAlwaysSendMailNotification(bool $always_send_mail_notification)
withShowAnswerOverview(bool $show_answer_overview)
withConcludingRemarksPageId(?int $concluding_remarks_page_id)
const REDIRECT_ALWAYS
This describes inputs that can be used in forms.
Definition: FormInput.php:31
const REDIRECT_KIOSK
getRedirectionInputs(ilLanguage $lng, FieldFactory $f, Refinery $refinery)
Refinery Factory $refinery