ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilStudyProgrammeValidityOfAchievedQualificationSettings.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
26 {
27  protected ?int $qualification_period;
29  protected ?int $restart_period;
30  protected $restart_recheck;
31 
32  public function __construct(
33  ?int $qualification_period,
34  ?DateTimeImmutable $qualification_date,
35  ?int $restart_period,
36  bool $restart_recheck
37  ) {
38  if (!is_null($qualification_period) && 0 > $qualification_period) {
39  throw new InvalidArgumentException(
40  'Numbers less than 0 are not allowed for qualification_period'
41  );
42  }
43 
44  if (!is_null($restart_period) && 0 > $restart_period) {
45  throw new InvalidArgumentException(
46  'Numbers less than 0 are not allowed for restart_period'
47  );
48  }
49 
50  $this->qualification_period = $qualification_period;
51  $this->qualification_date = $qualification_date;
52  $this->restart_period = $restart_period;
53  $this->restart_recheck = $restart_recheck;
54  }
55 
56  public function getQualificationPeriod(): ?int
57  {
59  }
60 
61  public function withQualificationPeriod(
62  ?int $qualification_period
64  if (!is_null($qualification_period) && 0 > $qualification_period) {
65  throw new InvalidArgumentException(
66  'Numbers less than 0 are not allowed'
67  );
68  }
69  $clone = clone $this;
70  $clone->qualification_period = $qualification_period;
71 
72  return $clone;
73  }
74 
76  {
78  }
79 
80  public function withQualificationDate(
81  ?DateTimeImmutable $qualification_date
83  $clone = clone $this;
84  $clone->qualification_date = $qualification_date;
85 
86  return $clone;
87  }
88 
89  public function getRestartPeriod(): ?int
90  {
91  return $this->restart_period;
92  }
93 
94  public function withRestartPeriod(
95  ?int $restart_period
97  if (!is_null($restart_period) && 0 > $restart_period) {
98  throw new InvalidArgumentException(
99  'Numbers less than 0 are not allowed'
100  );
101  }
102  $clone = clone $this;
103  $clone->restart_period = $restart_period;
104 
105  return $clone;
106  }
107 
108  public function toFormInput(
109  Field\Factory $input,
112  Factory $data_factory
113  ): \ILIAS\UI\Component\Input\Container\Form\FormInput {
114  $format = $data_factory->dateFormat()->germanShort();
115  $grp1 = $input->group([], $lng->txt('prg_no_validity_qualification'));
116  $grp2 = $input->group(
117  [
118  'vq_period' => $input->numeric(
119  $lng->txt('vq_period_label'),
120  $lng->txt('validity_qualification_period_desc')
121  )
122  ->withAdditionalTransformation($refinery->int()->isGreaterThanOrEqual(1))
124  ],
125  $lng->txt('validity_qualification_period')
126  );
127  $grp3 = $input->group(
128  [
129  'vq_date' => $input->dateTime(
130  $lng->txt('vq_date_label'),
131  $lng->txt('validity_qualification_date_desc')
132  )
133  ->withFormat($format)
134  ->withValue($this->getQualificationDate() !== null ? $this->getQualificationDate()->format('d.m.Y') : '')
135  ->withRequired(true)
136  ],
137  $lng->txt('validity_qualification_date')
138  );
139  $grp4 = $input->group([], $lng->txt('prg_no_restart'));
140  $grp5 = $input->group(
141  [
142  'vq_restart_period' => $input->numeric(
143  $lng->txt('restart_period_label'),
144  $lng->txt('restart_period_desc')
145  )
146  ->withAdditionalTransformation($refinery->int()->isGreaterThan(0))
147  ->withValue($this->getRestartPeriod() !== null ? $this->getRestartPeriod() : null)
148  ->withRequired(true),
149 
150  'vq_restart_recheck' => $input->checkbox(
151  $lng->txt('restart_recheck_label'),
152  $lng->txt('restart_recheck_desc')
153  )
154  ->withValue($this->getRestartRecheck())
155 
156  ],
157  $lng->txt('restart_period')
158  );
159 
160  $sg1 = $input->switchableGroup(
161  [
162  'opt_no_validity_qualification' => $grp1,
163  'opt_validity_qualification_period' => $grp2,
164  'opt_validity_qualification_date' => $grp3
165  ],
166  ''
167  )->withLabel($lng->txt('optgrp_label_validity'));
168 
169  $sg2 = $input->switchableGroup(
170  [
171  'opt_no_restart' => $grp4,
172  'opt_restart_period' => $grp5,
173  ],
174  ''
175  )->withLabel($lng->txt('optgrp_label_restart'));
176 
177  $validity_qualification = "opt_no_validity_qualification";
178  if (!is_null($this->getQualificationPeriod()) && $this->getQualificationPeriod() > 0) {
179  $validity_qualification = 'opt_validity_qualification_period';
180  }
181 
182  if (!is_null($this->getQualificationDate())) {
183  $validity_qualification = 'opt_validity_qualification_date';
184  }
185 
186  $restart_value = 'opt_no_restart';
187  if (!is_null($this->getRestartPeriod()) && $this->getRestartPeriod() > 0) {
188  $restart_value = 'opt_restart_period';
189  }
190 
191  return $input->section(
192  [
193  'validity_qualification' => $sg1->withValue($validity_qualification),
194  'restart' => $sg2->withValue($restart_value)
195  ],
196  $lng->txt('prg_validity_of_qualification')
197  )
198  ->withAdditionalTransformation($refinery->custom()->transformation(function (array $vals) {
199  $vq_period = null;
200  $vq_date = null;
201  $restart = null;
202  $restart_recheck = false;
203 
204  if (isset($vals['validity_qualification'][1]['vq_period'])) {
205  $vq_period = (int) $vals['validity_qualification'][1]['vq_period'];
206  }
207 
208  if (isset($vals['validity_qualification'][1]['vq_date'])) {
209  $vq_date = $vals['validity_qualification'][1]['vq_date'];
210  }
211 
212  if (
213  count($vals['restart'][1]) > 0 &&
214  !is_null($vals['restart'][1]['vq_restart_period'])
215  ) {
216  $restart = (int) $vals['restart'][1]['vq_restart_period'];
217  $restart_recheck = (bool) $vals['restart'][1]['vq_restart_recheck'];
218  }
219 
221  $vq_period,
222  $vq_date,
223  $restart,
225  );
226  }));
227  }
228 
229  public function getRestartRecheck(): bool
230  {
231  return $this->restart_recheck;
232  }
233 
235  {
236  $clone = clone $this;
237  $clone->restart_recheck = $restart_recheck;
238  return $clone;
239  }
240 }
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...
Class ChatMainBarProvider .
__construct(?int $qualification_period, ?DateTimeImmutable $qualification_date, ?int $restart_period, bool $restart_recheck)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
$lng
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:58
toFormInput(Field\Factory $input, ilLanguage $lng, Refinery $refinery, Factory $data_factory)
This describes inputs that can be used in forms.
Definition: FormInput.php:31
Refinery Factory $refinery