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