19declare(strict_types=1);
37 protected bool $start_time_enabled =
false,
38 protected ?\DateTimeImmutable $start_time =
null,
39 protected bool $end_time_enabled =
false,
40 protected ?\DateTimeImmutable $end_time =
null,
41 protected bool $password_enabled =
false,
42 protected ?
string $password =
null,
43 protected ?
string $ip_range_from =
null,
44 protected ?
string $ip_range_to =
null,
45 protected bool $fixed_participants =
false
54 ?array $environment =
null
60 $inputs[
'fixed_participants_enabled'] =
$f->checkbox(
61 $lng->txt(
'participants_invitation'),
62 $lng->txt(
'participants_invitation_description')
64 if ($environment[
'participant_data_exists']) {
65 $inputs[
'fixed_participants_enabled'] =
$inputs[
'fixed_participants_enabled']
69 return $f->section(
$inputs,
$lng->txt(
'tst_settings_header_execution'));
76 ?array $environment =
null
79 static fn(array $vs) =>
80 $vs[
'start_time'] === null || $vs[
'end_time'] === null || $vs[
'start_time'] < $vs[
'end_time'],
81 $lng->txt(
'duration_end_must_not_be_earlier_than_start')
84 $trafo =
$refinery->custom()->transformation(
85 static function (array $vs): array {
86 $vs[
'start_time_enabled'] = $vs[
'start_time'] !==
null;
87 $vs[
'end_time_enabled'] = $vs[
'end_time'] !==
null;
92 return $f->group($this->getSubInputsAccessWindow(
$lng,
$f, $environment))
93 ->withAdditionalTransformation($constraint)
94 ->withAdditionalTransformation($trafo);
102 $sub_inputs_access_window[
'start_time'] =
$f->dateTime(
103 $lng->txt(
'tst_starting_time'),
104 $lng->txt(
'tst_starting_time_desc')
105 )->withTimezone($environment[
'user_time_zone'])
106 ->withFormat($environment[
'user_date_format'])
108 if ($this->getStartTime() !==
null) {
109 $sub_inputs_access_window[
'start_time'] = $sub_inputs_access_window[
'start_time']
110 ->withValue($this->getStartTime()->setTimezone(
new \DateTimeZone($environment[
'user_time_zone'])));
112 if ($environment[
'participant_data_exists']) {
113 $sub_inputs_access_window[
'start_time'] = $sub_inputs_access_window[
'start_time']->withDisabled(
true);
116 $sub_inputs_access_window[
'end_time'] =
$f->dateTime(
117 $lng->txt(
'tst_ending_time'),
118 $lng->txt(
'tst_ending_time_desc')
119 )->withTimezone($environment[
'user_time_zone'])
120 ->withFormat($environment[
'user_date_format'])
122 if ($this->getEndTime() !==
null) {
123 $sub_inputs_access_window[
'end_time'] = $sub_inputs_access_window[
'end_time']
124 ->withValue($this->getEndTime()->setTimezone(
new \DateTimeZone($environment[
'user_time_zone'])));
127 return $sub_inputs_access_window;
136 static function (?array $vs): array {
139 'password_enabled' =>
false,
140 'password_value' => null
144 $vs[
'password_enabled'] =
true;
149 $sub_inputs_password[
'password_value'] =
$f->text(
$lng->txt(
'tst_password_enter'))
150 ->withRequired(
true)->withMaxLength(self::MAX_PASSWORD_LENGTH);
152 $password_input =
$f->optionalGroup(
153 $sub_inputs_password,
154 $lng->txt(
'tst_password'),
155 $lng->txt(
'tst_password_details')
157 ->withAdditionalTransformation($trafo);
159 if (!$this->getPasswordEnabled()) {
160 return $password_input;
163 return $password_input->withValue(
164 [
'password_value' => $this->getPassword()]
174 static function (?string $v): bool {
178 return filter_var($v, FILTER_VALIDATE_IP) !==
false;
180 $lng->txt(
'invalid_ip')
183 $validate_order =
$refinery->custom()->constraint(
184 function (?array $vs):
bool {
188 return $this->checkIpRangeValidity(
189 $vs[
'ip_range_from'],
193 sprintf(
$lng->txt(
'not_greater_than'),
$lng->txt(
'max_ip_label'),
$lng->txt(
'min_ip_label'))
195 $trafo =
$refinery->custom()->transformation(
196 static function (?array $vs): array {
199 'ip_range_from' =>
null,
200 'ip_range_to' => null
207 $get_ip_range =
$f->optionalGroup(
209 'ip_range_from' =>
$f->text(
$lng->txt(
'min_ip_label'))
210 ->withAdditionalTransformation($validate_ip),
211 'ip_range_to' =>
$f->text(
$lng->txt(
'max_ip_label'))
212 ->withAdditionalTransformation($validate_ip)
214 $lng->txt(
'ip_range_label'),
215 $lng->txt(
'ip_range_info')
218 if ($this->isIpRangeEnabled()) {
219 $get_ip_range = $get_ip_range->withValue(
221 'ip_range_from' => $this->getIpRangeFrom(),
222 'ip_range_to' => $this->getIpRangeTo()
227 return $get_ip_range->withAdditionalTransformation($validate_order)
228 ->withAdditionalTransformation($trafo);
233 if (filter_var($start, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !==
false
234 && filter_var($end, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !==
false) {
235 return ip2long($start) <= ip2long($end);
238 if (filter_var($start, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !==
false
239 && filter_var($end, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !==
false) {
240 return bin2hex(inet_pton($start)) <= bin2hex(inet_pton($end));
248 'starting_time_enabled' => [
'integer', (
int) $this->getStartTimeEnabled()],
249 'starting_time' => [
'integer', $this->getStartTime() !==
null ? $this->getStartTime()->getTimestamp() : 0],
250 'ending_time_enabled' => [
'integer', (
int) $this->getEndTimeEnabled()],
251 'ending_time' => [
'integer', $this->getEndTime() !==
null ? $this->getEndTime()->getTimestamp() : 0],
252 'password_enabled' => [
'integer', (
int) $this->getPasswordEnabled()],
253 'password' => [
'text', $this->getPassword()],
254 'ip_range_from' => [
'text', $this->getIpRangeFrom()],
255 'ip_range_to' => [
'text', $this->getIpRangeTo()],
256 'fixed_participants' => [
'integer', (
int) $this->getFixedParticipants()]
262 $starting_time = $additional_info->
getNoneTag();
263 if (($st_immutable = $this->getStartTime()) instanceof \DateTimeImmutable) {
264 $starting_time = $st_immutable->format(AdditionalInformationGenerator::DATE_STORAGE_FORMAT);
268 if (($et_immutable = $this->getEndTime()) instanceof \DateTimeImmutable) {
269 $end_time = $et_immutable->format(AdditionalInformationGenerator::DATE_STORAGE_FORMAT);
273 AdditionalInformationGenerator::KEY_TEST_START_TIME => $starting_time,
274 AdditionalInformationGenerator::KEY_TEST_END_TIME => $end_time,
275 AdditionalInformationGenerator::KEY_TEST_PASSWORD => $this->getPassword() ?? $additional_info->
getNoneTag(),
276 AdditionalInformationGenerator::KEY_TEST_IP_RANGE => $this->isIpRangeEnabled()
277 ? $this->getIpRangeFrom() .
' - ' . $this->getIpRangeTo()
279 AdditionalInformationGenerator::KEY_TEST_FIXED_PARTICIPANTS => $additional_info
286 return $this->start_time_enabled;
290 $clone = clone $this;
291 $clone->start_time_enabled = $start_time_enabled;
297 return $this->start_time;
301 $clone = clone $this;
302 $clone->start_time = $start_time;
308 return $this->end_time_enabled;
312 $clone = clone $this;
313 $clone->end_time_enabled = $end_time_enabled;
319 return $this->end_time;
323 $clone = clone $this;
324 $clone->end_time = $end_time;
330 return $this->password_enabled;
334 $clone = clone $this;
335 $clone->password_enabled = $password_enabled;
341 return $this->password;
345 $clone = clone $this;
346 $clone->password = $password;
352 return $this->ip_range_from;
356 $clone = clone $this;
357 $clone->ip_range_from = $ip_range_from;
363 return $this->ip_range_to;
367 $clone = clone $this;
368 $clone->ip_range_to = $ip_range_to;
374 return $this->ip_range_from !==
null && $this->ip_range_to !==
null;
379 return $this->fixed_participants;
383 $clone = clone $this;
384 $clone->fixed_participants = $fixed_participants;
getSubInputsAccessWindow(\ilLanguage $lng, FieldFactory $f, array $environment)
withEndTimeEnabled(bool $end_time_enabled)
withIpRangeTo(?string $ip_range_to)
getInputIpRange(\ilLanguage $lng, FieldFactory $f, Refinery $refinery)
__construct(int $test_id, protected bool $start_time_enabled=false, protected ?\DateTimeImmutable $start_time=null, protected bool $end_time_enabled=false, protected ?\DateTimeImmutable $end_time=null, protected bool $password_enabled=false, protected ?string $password=null, protected ?string $ip_range_from=null, protected ?string $ip_range_to=null, protected bool $fixed_participants=false)
withIpRangeFrom(?string $ip_range_from)
getInputAccessWindow(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, ?array $environment=null)
toLog(AdditionalInformationGenerator $additional_info)
withStartTime(?\DateTimeImmutable $start_time)
withStartTimeEnabled(bool $start_time_enabled)
withPassword(?string $password)
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, ?array $environment=null)
checkIpRangeValidity(string $start, string $end)
const MAX_PASSWORD_LENGTH
withPasswordEnabled(bool $password_enabled)
getInputPassword(\ilLanguage $lng, FieldFactory $f, Refinery $refinery)
withFixedParticipants(bool $fixed_participants)
withEndTime(?\DateTimeImmutable $end_time)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))