ILIAS  release_8 Revision v8.24
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,
71 Refinery $refinery,
72 Factory $data_factory
73 ): \ILIAS\UI\Component\Input\Container\Form\FormInput {
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 ->withRequired(true)
86 ],
87 $lng->txt('prg_deadline_period')
88 );
89 $grp3 = $input->group(
90 [
91 'deadline_date' => $input->dateTime(
92 $lng->txt('prg_deadline_date_label'),
93 $lng->txt('prg_deadline_date_desc')
94 )
95 ->withFormat($format)
96 ->withValue($this->getDeadlineDate() !== null ? $this->getDeadlineDate()->format('d.m.Y') : '')
97 ->withRequired(true)
98 ],
99 $lng->txt('prg_deadline_date')
100 );
101
102 $sg = $input->switchableGroup(
103 [
104 'opt_no_deadline' => $grp1,
105 'opt_deadline_period' => $grp2,
106 'opt_deadline_date' => $grp3
107 ],
108 ''
109 );
110
111 $deadline = "opt_no_deadline";
112 if (!is_null($this->getDeadlinePeriod()) && $this->getDeadlinePeriod() > 0) {
113 $deadline = 'opt_deadline_period';
114 }
115
116 if (!is_null($this->getDeadlineDate())) {
117 $deadline = 'opt_deadline_date';
118 }
119
120 return $input->section(
121 ['prg_deadline' => $sg->withValue($deadline)],
122 $lng->txt('prg_deadline_settings')
123 )
124 ->withAdditionalTransformation($refinery->custom()->transformation(
125 function ($vals) {
126 $period = null;
127 $date = null;
128
129 if (isset($vals['prg_deadline'][1]['deadline_period'])) {
130 $period = (int) $vals['prg_deadline'][1]['deadline_period'];
131 }
132
133 if (isset($vals['prg_deadline'][1]['deadline_date'])) {
134 $date = $vals['prg_deadline'][1]['deadline_date'];
135 }
136
137 return new ilStudyProgrammeDeadlineSettings($period, $date);
138 }
139 ));
140 }
141}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
Builds data types.
Definition: Factory.php:21
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:32
This is a legacy support of Component\Input\Field\Input that has been moved to Component\Input\Contai...
Definition: Input.php:32
$format
Definition: metadata.php:235
Refinery Factory $refinery
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$lng