ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilStudyProgrammeDeadlineSettings.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6use \ILIAS\UI\Component\Input\Field;
7use \ILIAS\Refinery\Factory as Refinery;
8
10{
15
19 protected $deadline_date;
20
21 public function __construct(
24 ) {
25 if (!is_null($deadline_period) && 0 > $deadline_period) {
26 throw new InvalidArgumentException(
27 'Numbers less than 0 are not allowed'
28 );
29 }
30
31 $this->deadline_period = $deadline_period;
32 $this->deadline_date = $deadline_date;
33 }
34
35 public function getDeadlinePeriod() : ?int
36 {
38 }
39
41 {
42 if (!is_null($deadline_period) && 0 > $deadline_period) {
43 throw new InvalidArgumentException(
44 'Numbers less than 0 are not allowed'
45 );
46 }
47
48 $clone = clone $this;
49 $clone->deadline_period = $deadline_period;
50 return $clone;
51 }
52
53 public function getDeadlineDate() : ?DateTime
54 {
56 }
57
59 {
60 $clone = clone $this;
61 $clone->deadline_date = $deadline_date;
62 return $clone;
63 }
64
65 public function toFormInput(
66 Field\Factory $input,
68 Refinery $refinery,
69 Factory $data_factory
70 ) : Field\Input {
71 $format = $data_factory->dateFormat()->germanShort();
72
73 $grp1 = $input->group([], $lng->txt('prg_no_deadline'));
74 $grp2 = $input->group(
75 [
76 'deadline_period' => $input->numeric(
77 '',
78 $lng->txt('prg_deadline_period_desc')
79 )
80 ->withAdditionalTransformation($refinery->int()->isGreaterThan(-1))
81 ->withValue($this->getDeadlinePeriod() !== null ? $this->getDeadlinePeriod() : null)
82 ],
83 $lng->txt('prg_deadline_period')
84 );
85 $grp3 = $input->group(
86 [
87 'deadline_date' => $input->dateTime(
88 '',
89 $lng->txt('prg_deadline_date_desc')
90 )
91 ->withFormat($format)
92 ->withValue($this->getDeadlineDate() !== null ? $this->getDeadlineDate()->format('d.m.Y') : '')
93 ->withRequired(true)
94 ],
95 $lng->txt('prg_deadline_date')
96 );
97
98 $sg = $input->switchableGroup(
99 [
100 'opt_no_deadline' => $grp1,
101 'opt_deadline_period' => $grp2,
102 'opt_deadline_date' => $grp3
103 ],
104 ''
105 );
106
107 $deadline = "opt_no_deadline";
108 if (!is_null($this->getDeadlinePeriod()) && $this->getDeadlinePeriod() > 0) {
109 $deadline = 'opt_deadline_period';
110 }
111
112 if (!is_null($this->getDeadlineDate())) {
113 $deadline = 'opt_deadline_date';
114 }
115
116 return $input->section(
117 ['prg_deadline' => $sg->withValue($deadline)],
118 $lng->txt('prg_deadline_settings')
119 )
120 ->withAdditionalTransformation($refinery->custom()->transformation(
121 function ($vals) {
122 $period = null;
123 $date = null;
124
125 if (isset($vals['prg_deadline'][1]['deadline_period'])) {
126 $period = (int) $vals['prg_deadline'][1]['deadline_period'];
127 }
128
129 if (isset($vals['prg_deadline'][1]['deadline_date'])) {
130 $date = new DateTime($vals['prg_deadline'][1]['deadline_date']);
131 }
132
133 return new ilStudyProgrammeDeadlineSettings($period, $date);
134 }
135 ));
136 }
137}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
language handling
toFormInput(Field\Factory $input, \ilLanguage $lng, Refinery $refinery, Factory $data_factory)
__construct(?int $deadline_period, ?DateTime $deadline_date)
This describes the datetime-field.
Definition: DateTime.php:14
This describes commonalities between all inputs.
Definition: Input.php:32
$format
Definition: metadata.php:218
$lng