ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilStudyProgrammeDeadlineSettings.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 protected ?int $deadline_period;
28 protected ?DateTimeImmutable $deadline_date;
29
30 public function __construct(?int $deadline_period, ?DateTimeImmutable $deadline_date)
31 {
32 if (!is_null($deadline_period) && 0 > $deadline_period) {
33 throw new InvalidArgumentException('Numbers less than 0 are not allowed');
34 }
35
36 $this->deadline_period = $deadline_period;
37 $this->deadline_date = $deadline_date;
38 }
39
40 public function getDeadlinePeriod(): ?int
41 {
43 }
44
46 {
47 if (!is_null($deadline_period) && 0 > $deadline_period) {
48 throw new InvalidArgumentException('Numbers less than 0 are not allowed');
49 }
50
51 $clone = clone $this;
52 $clone->deadline_period = $deadline_period;
53 return $clone;
54 }
55
56 public function getDeadlineDate(): ?DateTimeImmutable
57 {
59 }
60
62 {
63 $clone = clone $this;
64 $clone->deadline_date = $deadline_date;
65 return $clone;
66 }
67
68 public function toFormInput(
69 Field\Factory $input,
72 Factory $data_factory
74 $format = $data_factory->dateFormat()->germanShort();
75
76 $grp1 = $input->group([], $lng->txt('prg_no_deadline'));
77 $grp2 = $input->group(
78 [
79 'deadline_period' => $input->numeric(
80 $lng->txt('prg_deadline_period_label'),
81 $lng->txt('prg_deadline_period_desc')
82 )
83 ->withAdditionalTransformation($refinery->int()->isGreaterThanOrEqual(1))
84 ->withValue($this->getDeadlinePeriod())
85 ],
86 $lng->txt('prg_deadline_period')
87 );
88 $grp3 = $input->group(
89 [
90 'deadline_date' => $input->dateTime(
91 $lng->txt('prg_deadline_date_label'),
92 $lng->txt('prg_deadline_date_desc')
93 )
94 ->withFormat($format)
95 ->withValue($this->getDeadlineDate() !== null ? $this->getDeadlineDate()->format('d.m.Y') : '')
96 ->withRequired(true)
97 ],
98 $lng->txt('prg_deadline_date')
99 );
100
101 $sg = $input->switchableGroup(
102 [
103 'opt_no_deadline' => $grp1,
104 'opt_deadline_period' => $grp2,
105 'opt_deadline_date' => $grp3
106 ],
107 ''
108 );
109
110 $deadline = "opt_no_deadline";
111 if (!is_null($this->getDeadlinePeriod()) && $this->getDeadlinePeriod() > 0) {
112 $deadline = 'opt_deadline_period';
113 }
114
115 if (!is_null($this->getDeadlineDate())) {
116 $deadline = 'opt_deadline_date';
117 }
118
119 return $input->section(
120 ['prg_deadline' => $sg->withValue($deadline)],
121 $lng->txt('prg_deadline_settings')
122 )
123 ->withAdditionalTransformation($refinery->custom()->transformation(
124 function ($vals) {
125 $period = null;
126 $date = null;
127
128 if (isset($vals['prg_deadline'][1]['deadline_period'])) {
129 $period = (int) $vals['prg_deadline'][1]['deadline_period'];
130 }
131
132 if (isset($vals['prg_deadline'][1]['deadline_date'])) {
133 $date = $vals['prg_deadline'][1]['deadline_date'];
134 }
135
136 return new ilStudyProgrammeDeadlineSettings($period, $date);
137 }
138 ));
139 }
140}
Builds data types.
Definition: Factory.php:36
Definition: UI.php:24
language handling
withDeadlineDate(?DateTimeImmutable $deadline_date)
__construct(?int $deadline_period, ?DateTimeImmutable $deadline_date)
toFormInput(Field\Factory $input, ilLanguage $lng, Refinery $refinery, Factory $data_factory)
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