ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDateTimeInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
16 protected $lng;
17
21 protected $user;
22
23 protected $date;
24 protected $time = "00:00:00";
25 protected $showtime = false;
26 protected $showseconds = false;
27 protected $minute_step_size = 5;
28 protected $startyear = '';
29 protected $invalid_input = '';
30
34 protected $side_by_side = true;
36 protected $valid_incoming_datetime = null;
37
44 public function __construct($a_title = "", $a_postvar = "")
45 {
46 global $DIC;
47
48 $this->lng = $DIC->language();
49 $this->user = $DIC->user();
50 parent::__construct($a_title, $a_postvar);
51 $this->setType("datetime");
52 }
53
65 public function setDate(ilDateTime $a_date = null)
66 {
67 $this->date = $a_date;
68 }
69
75 public function getDate()
76 {
77 return $this->date;
78 }
79
85 public function setShowTime($a_showtime)
86 {
87 $this->showtime = $a_showtime;
88 }
89
95 public function getShowTime()
96 {
97 return $this->showtime;
98 }
99
105 public function setStartYear($a_year)
106 {
107 $this->startyear = $a_year;
108 }
109
115 public function getStartYear()
116 {
117 return $this->startyear;
118 }
119
128 public function setMinuteStepSize($a_step_size)
129 {
130 $this->minute_step_size = $a_step_size;
131 }
132
139 public function getMinuteStepSize()
140 {
142 }
143
149 public function setShowSeconds($a_showseconds)
150 {
151 $this->showseconds = $a_showseconds;
152 }
153
159 public function getShowSeconds()
160 {
161 return $this->showseconds;
162 }
163
169 public function setValueByArray($a_values)
170 {
171 if ($this->valid_incoming_datetime !== null) {
172 $this->setDate($this->valid_incoming_datetime);
173 } else {
174 $incoming = $a_values[$this->getPostVar()];
176 }
177
178 foreach ($this->getSubItems() as $item) {
179 $item->setValueByArray($a_values);
180 }
181 }
182
183 protected function getDatePickerTimeFormat()
184 {
185 return (int) $this->getShowTime() + (int) $this->getShowSeconds();
186 }
187
188 public function hasInvalidInput()
189 {
190 return (bool) $this->invalid_input;
191 }
192
198 public function checkInput()
199 {
201
202 if ($this->getDisabled()) {
203 return true;
204 }
205
206 $post = $_POST[$this->getPostVar()];
207
208 // always done to make sure there are no obsolete values left
209 $this->setDate(null);
210
211 $valid = false;
212 if (trim($post)) {
214 if ($parsed) {
215 $this->setDate($parsed);
216 $valid = true;
217 }
218 } elseif (!$this->getRequired()) {
219 $valid = true;
220 }
221
222 if ($valid &&
223 $this->getDate() &&
224 $this->getStartYear() &&
225 $this->getDate()->get(IL_CAL_FKT_DATE, "Y") < $this->getStartYear()) {
226 $valid = false;
227 }
228
229 if (!$valid) {
230 $this->invalid_input = $post;
231 $_POST[$this->getPostVar()] = null;
232
233 $this->setAlert($lng->txt("form_msg_wrong_date"));
234 } else {
235 if ($this->getDate() !== null) {
236 // getInput() should return a generic format
237 $post_format = $this->getShowTime()
239 : IL_CAL_DATE;
240 $this->valid_incoming_datetime = $this->getDate();
241 $_POST[$this->getPostVar()] = $this->getDate()->get($post_format);
242 } else {
243 $_POST[$this->getPostVar()] = null;
244 }
245 }
246
247 if ($valid) {
248 $valid = $this->checkSubItemsInput();
249 }
250
251 return $valid;
252 }
253
258 public function setSideBySide(bool $a_val)
259 {
260 $this->side_by_side = $a_val;
261 }
262
267 public function getSideBySide() : bool
268 {
269 return $this->side_by_side;
270 }
271
272
278 protected function parseDatePickerConfig()
279 {
280 $config = null;
281 if ($this->getMinuteStepSize()) {
282 $config['stepping'] = (int) $this->getMinuteStepSize();
283 }
284 if ($this->getStartYear()) {
285 $config['minDate'] = $this->getStartYear() . '-01-01';
286 }
287 $config['sideBySide'] = $this->getSideBySide();
288 return $config;
289 }
290
295 public function render()
296 {
299
300 $tpl = new ilTemplate("tpl.prop_datetime.html", true, true, "Services/Form");
301
302 // config picker
303 if (!$this->getDisabled()) {
304 $picker_id = md5($this->getPostVar()); // :TODO: unique?
305 $tpl->setVariable('DATEPICKER_ID', $picker_id);
306
308 $picker_id,
310 $this->parseDatePickerConfig(),
311 null,
312 null,
313 null,
314 "subform_" . $this->getPostVar()
315 );
316 } else {
317 $tpl->setVariable('DATEPICKER_DISABLED', 'disabled="disabled" ');
318 }
319
320 // :TODO: i18n?
322 $tpl->setVariable('PLACEHOLDER', $pl_format);
323
324 // accessibility description
325 $tpl->setVariable(
326 'DESCRIPTION',
327 ilUtil::prepareFormOutput($lng->txt("form_date_aria_desc") . " " . $pl_format)
328 );
329
330 // current value
331 $date_value = htmlspecialchars($this->invalid_input);
332 if (!$date_value &&
333 $this->getDate()) {
335 $date_value = $this->getDate()->get(IL_CAL_FKT_DATE, $out_format, $ilUser->getTimeZone());
336 }
337
338 $tpl->setVariable('DATEPICKER_VALUE', $date_value);
339 $tpl->setVariable('DATE_ID', $this->getPostVar());
340
341 if ($this->getRequired()) {
342 $tpl->setVariable("REQUIRED", "required=\"required\"");
343 }
344
345 return $tpl->get();
346 }
347
352 public function getOnloadCode() : array
353 {
354 $code = [];
355 if (!$this->getDisabled()) {
356 $picker_id = md5($this->getPostVar());
357
359 $picker_id,
361 $this->parseDatePickerConfig(),
362 null,
363 null,
364 null,
365 "subform_" . $this->getPostVar()
366 );
367 }
368 return $code;
369 }
370
376 public function insert($a_tpl)
377 {
378 $html = $this->render();
379
380 $a_tpl->setCurrentBlock("prop_generic");
381 $a_tpl->setVariable("PROP_GENERIC", $html);
382 $a_tpl->parseCurrentBlock();
383 }
384
388 public function getTableFilterHTML()
389 {
390 $html = $this->render();
391 return $html;
392 }
393
397 public function serializeData()
398 {
399 if ($this->getDate()) {
400 return serialize($this->getDate()->get(IL_CAL_UNIX));
401 }
402 }
403
407 public function unserializeData($a_data)
408 {
409 $tmp = unserialize($a_data);
410 if ($tmp) {
411 // we used to serialize the complete instance
412 if (is_object($tmp)) {
413 $date = $tmp;
414 } else {
415 $date = $this->getShowTime()
416 ? new ilDateTime($tmp, IL_CAL_UNIX)
417 : new ilDate($tmp, IL_CAL_UNIX);
418 }
419 $this->setDate($date);
420 } else {
421 $this->setDate(null);
422 }
423 }
424
431 {
432 // :TODO:
433 return trim($_POST[$this->getPostVar()]);
434 }
435
439 public function getToolbarHTML()
440 {
441 $html = $this->render("toolbar");
442 return $html;
443 }
444
445 public function hideSubForm()
446 {
447 return (!$this->getDate() || $this->getDate()->isNull());
448 }
449}
user()
Definition: user.php:4
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_CAL_FKT_DATE
static parseIncomingDate($a_value, $a_add_time=null)
Try to parse incoming value to date object.
static getCodeForPicker($a_id, $a_add_time=null, array $a_custom_config=null, $a_id2=null, $a_custom_config2=null, $a_toggle_id=null, $a_subform_id=null)
Add date time picker to element.
static addDateTimePicker($a_id, $a_add_time=null, array $a_custom_config=null, $a_id2=null, $a_custom_config2=null, $a_toggle_id=null, $a_subform_id=null)
Add date time picker to element.
static getUserDateFormat($a_add_time=false, $a_for_parsing=false)
Parse current user setting into date/time format.
This class represents a date/time property in a property form.
insert($a_tpl)
Insert property html.
render()
Insert property html.
setStartYear($a_year)
Set start year.
setSideBySide(bool $a_val)
Set side by side.
getTableFilterHTML()
Get HTML for table filter.
getToolbarHTML()
Get HTML for toolbar.
getMinuteStepSize()
Get minute step size.
getShowTime()
Get Show Time Information.
__construct($a_title="", $a_postvar="")
Constructor.
setMinuteStepSize($a_step_size)
Set minute step size E.g 5 => The selection will only show 00,05,10... minutes.
getSideBySide()
Get side by side.
getShowSeconds()
Get Show Seconds.
getOnloadCode()
Get onload code.
getPostValueForComparison()
parse post value to make it comparable
unserializeData($a_data)
unserialize data
checkInput()
Check input, strip slashes etc.
setShowTime($a_showtime)
Set Show Time Information.
hideSubForm()
Sub form hidden on init?
getDate()
Get Date, yyyy-mm-dd.
setValueByArray($a_values)
Set value by array.
parseDatePickerConfig()
parse properties to datepicker config
setShowSeconds($a_showseconds)
Set Show Seconds.
setDate(ilDateTime $a_date=null)
set date E.g $dt_form->setDate(new ilDateTime(time(),IL_CAL_UTC)); or $dt_form->setDate(new ilDateTim...
@classDescription Date and time handling
Class for single dates.
setType($a_type)
Set Type.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
This class represents a property that may include a sub form.
special template class to simplify handling of ITX/PEAR
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$valid
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
Interface for property form input GUI classes that can be used in table filters.
Interface for property form input GUI classes that can be used in ilToolbarGUI.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc