ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables 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  ->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 }
toFormInput(Field\Factory $input, ilLanguage $lng, Refinery $refinery, Factory $data_factory)
Class 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...
$lng
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
__construct(?int $deadline_period, ?DateTimeImmutable $deadline_date)
$format
Definition: metadata.php:235
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59
withDeadlineDate(?DateTimeImmutable $deadline_date)
This describes inputs that can be used in forms.
Definition: FormInput.php:31
Refinery Factory $refinery