ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
7 use ILIAS\UI\Component as C;
10 
11 
15 
19 class DateTime extends Input implements C\Input\Field\DateTime, JSBindabale
20 {
21  use ComponentHelper;
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 
54  protected $additional_picker_config = [];
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 
241  public function withAdditionalPickerconfig(array $config) : DateTime
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 }
getAdditionalPickerconfig()
Get config to be passed to the bootstrap picker.
Definition: DateTime.php:231
Class ChatMainBarProvider .
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
trait ComponentHelper
Provides common functionality for component implementations.
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, $label, $byline)
Definition: DateTime.php:72
$format
Definition: metadata.php:218
Builds data types.
Definition: Factory.php:19
__construct(Container $dic, ilPlugin $plugin)
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, &#39;$id&#39;, string_value);initially "onload" andon every input change. It must pass a readable string representation of its value in parameter &#39;string_value&#39;.string
Definition: DateTime.php:251