ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
DateTime.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
6
8use ILIAS\Data\Factory as DataFactory;
10
11
15
19class DateTime extends Input implements C\Input\Field\DateTime, JSBindabale
20{
23
24 const TIME_FORMAT = 'HH:mm';
25
29 protected $format;
30
34 protected $min_date;
35
39 protected $max_date;
40
44 protected $with_time = false;
45
49 protected $with_time_only = false;
50
55
60
64 protected $timezone;
65
72 public function __construct(
73 DataFactory $data_factory,
74 \ILIAS\Refinery\Factory $refinery,
75 $label,
76 $byline
77 ) {
78 parent::__construct($data_factory, $refinery, $label, $byline);
79
80 $this->format = $data_factory->dateFormat()->standard();
81
82 $datetime_trafo = $refinery->to()->dateTime();
83 $trafo = $this->getOptionalNullTransformation($datetime_trafo);
84 $this->setAdditionalTransformation($trafo);
85 }
86
87
88 protected function getOptionalNullTransformation($or_trafo)
89 {
90 return $this->refinery->custom()->transformation(
91 function ($v) use ($or_trafo) {
92 if (!$v) {
93 return null;
94 }
95 return $or_trafo->transform($v);
96 }
97 );
98 }
99
104 {
105 $clone = clone $this;
106 $clone->format = $format;
107 return $clone;
108 }
109
113 public function getFormat() : DateFormat\DateFormat
114 {
115 return $this->format;
116 }
117
121 public function withTimezone(string $tz) : C\Input\Field\DateTime
122 {
123 $timezone_trafo = $this->refinery->dateTime()->changeTimezone($tz);
124 $clone = clone $this;
125 $clone->timezone = $tz;
126
127 $trafo = $this->getOptionalNullTransformation($timezone_trafo);
128 return $clone->withAdditionalTransformation($trafo);
129 }
130
134 public function getTimezone()
135 {
136 return $this->timezone;
137 }
138
142 public function withMinValue(\DateTimeImmutable $date) : C\Input\Field\DateTime
143 {
144 $clone = clone $this;
145 $clone->min_date = $date;
146 return $clone;
147 }
148
152 public function getMinValue()
153 {
154 return $this->min_date;
155 }
156
160 public function withMaxValue(\DateTimeImmutable $date) : C\Input\Field\DateTime
161 {
162 $clone = clone $this;
163 $clone->max_date = $date;
164 return $clone;
165 }
166
170 public function getMaxValue()
171 {
172 return $this->max_date;
173 }
174
178 public function withUseTime(bool $with_time) : C\Input\Field\DateTime
179 {
180 $clone = clone $this;
181 $clone->with_time = $with_time;
182 return $clone;
183 }
184
188 public function getUseTime() : bool
189 {
190 return $this->with_time;
191 }
192
196 public function withTimeOnly(bool $with_time_only) : C\Input\Field\DateTime
197 {
198 $clone = clone $this;
199 $clone->with_time_only = $with_time_only;
200 return $clone;
201 }
202
206 public function getTimeOnly() : bool
207 {
208 return $this->with_time_only;
209 }
210
214 protected function isClientSideValueOk($value) : bool
215 {
216 return is_string($value);
217 }
218
222 protected function getConstraintForRequirement()
223 {
224 return $this->refinery->string()->hasMinLength(1);
225 }
226
231 public function getAdditionalPickerconfig() : array
232 {
233 return $this->additional_picker_config;
234 }
235
242 {
243 $clone = clone $this;
244 $clone->additional_picker_config = array_merge($clone->additional_picker_config, $config);
245 return $clone;
246 }
247
251 public function getUpdateOnLoadCode() : \Closure
252 {
253 return function ($id) {
254 $code = "$('#$id').on('input dp.change', function(event) {
255 il.UI.input.onFieldUpdate(event, '$id', $('#$id').find('input').val());
256 });
257 il.UI.input.onFieldUpdate(event, '$id', $('#$id').find('input').val());";
258 return $code;
259 };
260 }
261}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
getAdditionalPickerconfig()
Get config to be passed to the bootstrap picker.
Definition: DateTime.php:231
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, $label, $byline)
Definition: DateTime.php:72
withAdditionalPickerconfig(array $config)
The bootstrap picker can be configured, e.g.
Definition: DateTime.php:241
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event,...
Definition: DateTime.php:251
This describes the datetime-field.
Definition: DateTime.php:13
This describes commonalities between all inputs.
Definition: Input.php:32
Interface to be extended by components that have the possibility to bind to Javascript.
$format
Definition: metadata.php:218
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
trait ComponentHelper
Provides common functionality for component implementations.
Class ChatMainBarProvider \MainMenu\Provider.