ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilStudyProgrammeDeadlineSettings.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
26 {
27  protected ?int $deadline_period;
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 
45  public function withDeadlinePeriod(?int $deadline_period): ilStudyProgrammeDeadlineSettings
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  {
58  return $this->deadline_date;
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
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  ],
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 }
toFormInput(Field\Factory $input, ilLanguage $lng, Refinery $refinery, Factory $data_factory)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(?int $deadline_period, ?DateTimeImmutable $deadline_date)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Builds data types.
Definition: Factory.php:35
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
withDeadlineDate(?DateTimeImmutable $deadline_date)
global $lng
Definition: privfeed.php:31
This describes inputs that can be used in forms.
Definition: FormInput.php:32