ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
AvailabilityPeriod.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29
34{
35 public function __construct(
36 private ?int $object_reference_id = null,
37 private ?bool $availability_period_enabled = null,
38 private ?\DateTimeImmutable $time_limit_start = null,
39 private ?\DateTimeImmutable $time_limit_end = null,
40 private ?bool $visible_when_disabled = false
41 ) {
42 }
43
44 public function getObjectReferenceId(): ?int
45 {
46 return $this->object_reference_id;
47 }
48
49 public function getAvailabilityPeriodEnabled(): bool
50 {
51 return $this->availability_period_enabled === true;
52 }
53
54 public function getAvailabilityPeriodStart(): ?\DateTimeImmutable
55 {
56 return $this->time_limit_start;
57 }
58
59 public function getAvailabilityPeriodEnd(): ?\DateTimeImmutable
60 {
61 return $this->time_limit_end;
62 }
63
64 public function getVisibleWhenDisabled(): bool
65 {
66 return $this->visible_when_disabled;
67 }
68
69 public function objectCurrentlyEnabled(): bool
70 {
71 if ($this->availability_period_enabled === false) {
72 return true;
73 }
74
75 $timing_start_utc = $this->timing_start->setTimezone(new \DateTimeZone('UTC'));
76 $timing_end_utc = $this->timing_end->setTimezone(new \DateTimeZone('UTC'));
77 $now_utc = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
78
79 if ($timing_start_utc < $now_utc && $now_utc < $timing_end_utc) {
80 return true;
81 }
82
83 return false;
84 }
85
86 public function withObjectReferenceId(int $object_reference_id): self
87 {
88 $clone = clone $this;
89 $clone->object_reference_id = $object_reference_id;
90 return $clone;
91 }
92
93 public function toForm(
94 \ilLanguage $language,
95 FieldFactory $field_factory,
97 ?array $environment = null
98 ): FormInput {
100 $refinery,
101 $language
102 );
105 new \DateTimeZone($environment['user_time_zone'])
106 );
107
108 $inputs['time_limit_start'] = $field_factory->dateTime($language->txt('rep_activation_limited_start'))
109 ->withTimezone($environment['user_time_zone'])
110 ->withFormat($environment['user_date_format'])
111 ->withUseTime(true);
112 $inputs['time_limit_end'] = $field_factory->dateTime($language->txt('rep_activation_limited_end'))
113 ->withTimezone($environment['user_time_zone'])
114 ->withFormat($environment['user_date_format'])
115 ->withUseTime(true);
116 $inputs['visible_when_disabled'] = $field_factory->checkbox(
117 $language->txt('activation_visible_when_disabled'),
118 $language->txt('activation_visible_when_disabled_info')
119 );
120
121 return $field_factory->optionalGroup(
122 $inputs,
123 $language->txt('rep_time_based_availability'),
124 $language->txt('rep_time_based_availability_info')
125 )->withAdditionalTransformation($constraint)
126 ->withAdditionalTransformation($trafo)
127 ->withValue($value);
128 }
129
131 {
132 return $refinery->custom()->transformation(
133 function (?array $vs): self {
134 if ($vs === null
135 || $vs['time_limit_start'] === null
136 && $vs['time_limit_end'] === null) {
137 return new self($this->getObjectReferenceId());
138 }
139
140 return new self(
141 $this->getObjectReferenceId(),
142 true,
143 $vs['time_limit_start']?->setTimezone(new \DateTimeZone('UTC')),
144 $vs['time_limit_end']?->setTimezone(new \DateTimeZone('UTC')),
145 $vs['visible_when_disabled']
146 );
147 }
148 );
149 }
150
153 \ilLanguage $language
154 ): Constraint {
155 return $refinery->custom()->constraint(
156 function (?array $vs): bool {
157 if ($vs === null
158 || $vs['time_limit_start'] === null
159 || $vs['time_limit_end'] === null) {
160 return true;
161 }
162
163 if ($vs['time_limit_start'] > $vs['time_limit_end']) {
164 return false;
165 }
166
167 return true;
168 },
169 $language->txt('duration_end_must_not_be_earlier_than_start')
170 );
171 }
172
173
174 private function getValueForActivationLimitedOptionalGroup(\DateTimeZone $timezone): ?array
175 {
176 $value = null;
177 if ($this->getAvailabilityPeriodEnabled()) {
178 $value = [
179 'time_limit_start' => $this->getAvailabilityPeriodStart()?->setTimezone($timezone)->format('Y-m-d H:i') ?? '',
180 'time_limit_end' => $this->getAvailabilityPeriodEnd()?->setTimezone($timezone)->format('Y-m-d H:i') ?? '',
181 'visible_when_disabled' => $this->getVisibleWhenDisabled()
182 ];
183 }
184 return $value;
185 }
186}
Builds data types.
Definition: Factory.php:36
toForm(\ilLanguage $language, FieldFactory $field_factory, Refinery $refinery, ?array $environment=null)
__construct(private ?int $object_reference_id=null, private ?bool $availability_period_enabled=null, private ?\DateTimeImmutable $time_limit_start=null, private ?\DateTimeImmutable $time_limit_end=null, private ?bool $visible_when_disabled=false)
language handling
txt(string|LanguageIdentifier $a_topic, ?int $n=null)
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
A transformation is a function from one datatype to another.
This describes inputs that can be used in forms.
Definition: FormInput.php:33
This is what a factory for input fields looks like.
Definition: Factory.php:31
if(!file_exists('../ilias.ini.php'))