ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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  ->withRequired(true)
125  ],
126  $lng->txt('validity_qualification_period')
127  );
128  $grp3 = $input->group(
129  [
130  'vq_date' => $input->dateTime(
131  $lng->txt('vq_date_label'),
132  $lng->txt('validity_qualification_date_desc')
133  )
134  ->withFormat($format)
135  ->withValue($this->getQualificationDate() !== null ? $this->getQualificationDate()->format('d.m.Y') : '')
136  ->withRequired(true)
137  ],
138  $lng->txt('validity_qualification_date')
139  );
140  $grp4 = $input->group([], $lng->txt('prg_no_restart'));
141  $grp5 = $input->group(
142  [
143  'vq_restart_period' => $input->numeric(
144  $lng->txt('restart_period_label'),
145  $lng->txt('restart_period_desc')
146  )
147  ->withAdditionalTransformation($refinery->int()->isGreaterThan(0))
148  ->withValue($this->getRestartPeriod() !== null ? $this->getRestartPeriod() : null)
149  ->withRequired(true)
150  ],
151  $lng->txt('restart_period')
152  );
153 
154  $sg1 = $input->switchableGroup(
155  [
156  'opt_no_validity_qualification' => $grp1,
157  'opt_validity_qualification_period' => $grp2,
158  'opt_validity_qualification_date' => $grp3
159  ],
160  ''
161  )->withLabel($lng->txt('optgrp_label_validity'));
162 
163  $sg2 = $input->switchableGroup(
164  [
165  'opt_no_restart' => $grp4,
166  'opt_restart_period' => $grp5,
167  ],
168  ''
169  )->withLabel($lng->txt('optgrp_label_restart'));
170 
171  $validity_qualification = "opt_no_validity_qualification";
172  if (!is_null($this->getQualificationPeriod()) && $this->getQualificationPeriod() > 0) {
173  $validity_qualification = 'opt_validity_qualification_period';
174  }
175 
176  if (!is_null($this->getQualificationDate())) {
177  $validity_qualification = 'opt_validity_qualification_date';
178  }
179 
180  $restart_value = 'opt_no_restart';
181  if (!is_null($this->getRestartPeriod()) && $this->getRestartPeriod() > 0) {
182  $restart_value = 'opt_restart_period';
183  }
184 
185  return $input->section(
186  [
187  'validity_qualification' => $sg1->withValue($validity_qualification),
188  'restart' => $sg2->withValue($restart_value)
189  ],
190  $lng->txt('prg_validity_of_qualification')
191  )
192  ->withAdditionalTransformation($refinery->custom()->transformation(function (array $vals) {
193  $vq_period = null;
194  $vq_date = null;
195  $restart = null;
196  $restart_recheck = false;
197 
198  if (isset($vals['validity_qualification'][1]['vq_period'])) {
199  $vq_period = (int) $vals['validity_qualification'][1]['vq_period'];
200  }
201 
202  if (isset($vals['validity_qualification'][1]['vq_date'])) {
203  $vq_date = $vals['validity_qualification'][1]['vq_date'];
204  }
205 
206  if (
207  count($vals['restart'][1]) > 0 &&
208  !is_null($vals['restart'][1]['vq_restart_period'])
209  ) {
210  $restart = (int) $vals['restart'][1]['vq_restart_period'];
211  }
212 
214  $vq_period,
215  $vq_date,
216  $restart,
218  );
219  }));
220  }
221 
222  public function getRestartRecheck(): bool
223  {
224  return $this->restart_recheck;
225  }
226 
228  {
229  $clone = clone $this;
230  $clone->restart_recheck = $restart_recheck;
231  return $clone;
232  }
233 }
Class Factory.
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...
$lng
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
$format
Definition: metadata.php:235
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59
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