ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilDateDurationInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Table/interfaces/interface.ilTableFilterItem.php';
5 
15 {
16  protected $start = null;
17  protected $startyear = null;
18  protected $start_text = null;
19  protected $end_text = null;
20  protected $minute_step_size = 5;
21  protected $end = null;
22  protected $showtime = false;
23  protected $toggle_fulltime = false;
24  protected $toggle_fulltime_txt = '';
25  protected $toggle_fulltime_checked = false;
26 
33  public function __construct($a_title = "", $a_postvar = "")
34  {
35  parent::__construct($a_title, $a_postvar);
36  $this->setType("dateduration");
37  }
38 
45  public function enableToggleFullTime($a_title,$a_checked)
46  {
47  $this->toggle_fulltime_txt = $a_title;
48  $this->toggle_fulltime_checked = $a_checked;
49  $this->toggle_fulltime = true;
50  }
51 
56  public function enabledToggleFullTime()
57  {
59  }
60 
72  public function setStart(ilDateTime $a_date = null)
73  {
74  $this->start = $a_date;
75  }
76 
82  public function setStartText($a_txt)
83  {
84  $this->start_text = $a_txt;
85  }
86 
91  public function getStartText()
92  {
93  return $this->start_text;
94  }
95 
101  public function setEndText($a_txt)
102  {
103  $this->end_text = $a_txt;
104  }
105 
110  public function getEndText()
111  {
112  return $this->end_text;
113  }
114 
120  public function getStart()
121  {
122  return $this->start;
123  }
124 
136  public function setEnd(ilDateTime $a_date = null)
137  {
138  $this->end = $a_date;
139  }
140 
146  public function getEnd()
147  {
148  return $this->end;
149  }
150 
156  public function setShowTime($a_showtime)
157  {
158  $this->showtime = $a_showtime;
159  }
160 
166  public function getShowTime()
167  {
168  return $this->showtime;
169  }
170 
175  public function getShowSeconds()
176  {
177  return false;
178  }
179 
185  public function setStartYear($a_year)
186  {
187  $this->startyear = $a_year;
188  }
189 
195  public function getStartYear()
196  {
197  return $this->startyear;
198  }
199 
208  public function setMinuteStepSize($a_step_size)
209  {
210  $this->minute_step_size = $a_step_size;
211  }
212 
219  public function getMinuteStepSize()
220  {
222  }
223 
229  public function setValueByArray($a_values)
230  {
231  $incoming = $a_values[$this->getPostVar()];
232  if(is_array($incoming))
233  {
234  $format = $this->getDatePickerTimeFormat();
235  $this->setStart(ilCalendarUtil::parseIncomingDate($incoming["start"], $format));
236  $this->setEnd(ilCalendarUtil::parseIncomingDate($incoming["end"], $format));
237  }
238 
239  foreach($this->getSubItems() as $item)
240  {
241  $item->setValueByArray($a_values);
242  }
243  }
244 
250  public function checkInput()
251  {
252  global $lng;
253 
254  if($this->getDisabled())
255  {
256  return true;
257  }
258 
259  $post = $_POST[$this->getPostVar()];
260  if(!is_array($post))
261  {
262  return false;
263  }
264 
265  $start = $post["start"];
266  $end = $post["end"];
267 
268  // if full day is active, ignore time format
269  $format = $post['tgl']
270  ? 0
271  : $this->getDatePickerTimeFormat();
272 
273  // always done to make sure there are no obsolete values left
274  $this->setStart(null);
275  $this->setEnd(null);
276 
277  $valid_start = false;
278  if(trim($start))
279  {
280  $parsed = ilCalendarUtil::parseIncomingDate($start, $format);
281  if($parsed)
282  {
283  $this->setStart($parsed);
284  $valid_start = true;
285  }
286  }
287  else if(!$this->getRequired() && !trim($end))
288  {
289  $valid_start = true;
290  }
291 
292  $valid_end = false;
293  if(trim($end))
294  {
295  $parsed = ilCalendarUtil::parseIncomingDate($end, $format);
296  if($parsed)
297  {
298  $this->setEnd($parsed);
299  $valid_end = true;
300  }
301  }
302  else if(!$this->getRequired() && !trim($start))
303  {
304  $valid_end = true;
305  }
306 
307  if($this->getStartYear())
308  {
309  if($valid_start &&
310  $this->getStart()->get(IL_CAL_FKT_DATE, "Y") < $this->getStartYear())
311  {
312  $valid_start = false;
313  }
314  if($valid_end &&
315  $this->getEnd()->get(IL_CAL_FKT_DATE, "Y") < $this->getStartYear())
316  {
317  $valid_end = false;
318  }
319  }
320 
321  $valid = ($valid_start && $valid_end);
322 
323  if($valid &&
324  $this->getStart() &&
325  $this->getEnd() &&
326  ilDateTime::_after($this->getStart(), $this->getEnd()))
327  {
328  $valid = false;
329  }
330 
331  if(!$valid)
332  {
333  $this->invalid_input_start = $start;
334  $this->invalid_input_end = $end;
335 
336  $_POST[$this->getPostVar()]["start"] = null;
337  $_POST[$this->getPostVar()]["end"] = null;
338 
339  $this->setAlert($lng->txt("form_msg_wrong_date"));
340  }
341  else
342  {
343  if($this->getStart() &&
344  $this->getEnd())
345  {
346  // getInput() should return a generic format
347  $post_format = $format
349  : IL_CAL_DATE;
350  $_POST[$this->getPostVar()]["start"] = $this->getStart()->get($post_format);
351  $_POST[$this->getPostVar()]["end"] = $this->getEnd()->get($post_format);
352  unset($_POST[$this->getPostVar()]["tgl"]);
353  }
354  else
355  {
356  $_POST[$this->getPostVar()]["start"] = null;
357  $_POST[$this->getPostVar()]["end"] = null;
358  }
359  }
360 
361  if($valid)
362  {
363  $valid = $this->checkSubItemsInput();
364  }
365 
366  return $valid;
367  }
368 
369  protected function getDatePickerTimeFormat()
370  {
371  return (int)$this->getShowTime() + (int)$this->getShowSeconds();
372  }
373 
379  protected function parseDatePickerConfig()
380  {
381  $config = null;
382  if($this->getMinuteStepSize())
383  {
384  $config['stepping'] = (int)$this->getMinuteStepSize();
385  }
386  if($this->getStartYear())
387  {
388  $config['minDate'] = $this->getStartYear().'-01-01';
389  }
390  return $config;
391  }
392 
397  public function render()
398  {
399  global $ilUser, $lng;
400 
401  $tpl = new ilTemplate("tpl.prop_datetime_duration.html", true, true, "Services/Form");
402 
403  if($this->enabledToggleFullTime())
404  {
405  $this->setShowTime(true);
406 
407  $toggle_id = md5($this->getPostVar().'_fulltime'); // :TODO: unique?
408 
409  $tpl->setCurrentBlock('toggle_fullday');
410  $tpl->setVariable('DATE_TOGGLE_ID', $this->getPostVar().'[tgl]');
411  $tpl->setVariable('FULLDAY_TOGGLE_ID', $toggle_id);
412  $tpl->setVariable('FULLDAY_TOGGLE_CHECKED', $this->toggle_fulltime_checked ? 'checked="checked"' : '');
413  $tpl->setVariable('FULLDAY_TOGGLE_DISABLED', $this->getDisabled() ? 'disabled="disabled"' : '');
414  $tpl->setVariable('TXT_TOGGLE_FULLDAY', $this->toggle_fulltime_txt);
415  $tpl->parseCurrentBlock();
416  }
417 
418  // config picker
419  if(!$this->getDisabled())
420  {
421  // :TODO: unique?
422  $picker_start_id = md5($this->getPostVar().'_start');
423  $picker_end_id = md5($this->getPostVar().'_end');
424 
425  $tpl->setVariable('DATEPICKER_START_ID', $picker_start_id);
426  $tpl->setVariable('DATEPICKER_END_ID', $picker_end_id);
427 
429  $picker_start_id,
430  $this->getDatePickerTimeFormat(),
431  $this->parseDatePickerConfig(),
432  $picker_end_id,
433  $this->parseDatePickerConfig(),
434  $toggle_id,
435  "subform_".$this->getPostVar()
436  );
437  }
438  else
439  {
440  $tpl->setVariable('DATEPICKER_START_DISABLED', 'disabled="disabled" ');
441  $tpl->setVariable('DATEPICKER_END_DISABLED', 'disabled="disabled" ');
442  }
443 
444  $start_txt = $this->getStartText();
445  if($start_txt === null)
446  {
447  $start_txt = $lng->txt("form_date_duration_start");
448  }
449  if(trim($start_txt))
450  {
451  $tpl->setVariable('START_LABEL', $start_txt);
452  $tpl->touchBlock('start_width_bl');
453  }
454 
455  $end_txt = $this->getEndText();
456  if($end_txt === null)
457  {
458  $end_txt = $lng->txt("form_date_duration_end");
459  }
460  if(trim($end_txt))
461  {
462  $tpl->setVariable('END_LABEL', $end_txt);
463  $tpl->touchBlock('end_width_bl');
464  }
465 
466 
467  $tpl->setVariable('DATE_START_ID', $this->getPostVar().'[start]');
468  $tpl->setVariable('DATE_END_ID', $this->getPostVar().'[end]');
469 
470  // placeholder
471  // :TODO: i18n?
473  $tpl->setVariable('START_PLACEHOLDER', $pl_format);
474  $tpl->setVariable('END_PLACEHOLDER', $pl_format);
475 
476 
477  // values
478 
479  $date_value = htmlspecialchars($this->invalid_input_start);
480  if(!$date_value &&
481  $this->getStart())
482  {
483  $out_format = ilCalendarUtil::getUserDateFormat($this->getDatePickerTimeFormat(), true);
484  $date_value = $this->getStart()->get(IL_CAL_FKT_DATE, $out_format, $ilUser->getTimeZone());
485  }
486  $tpl->setVariable('DATEPICKER_START_VALUE', $date_value);
487 
488  $date_value = htmlspecialchars($this->invalid_input_end);
489  if(!$date_value &&
490  $this->getEnd())
491  {
492  $out_format = ilCalendarUtil::getUserDateFormat($this->getDatePickerTimeFormat(), true);
493  $date_value = $this->getEnd()->get(IL_CAL_FKT_DATE, $out_format, $ilUser->getTimeZone());
494  }
495  $tpl->setVariable('DATEPICKER_END_VALUE', $date_value);
496 
497  if($this->getRequired())
498  {
499  $tpl->setVariable("START_REQUIRED", "required=\"required\"");
500  $tpl->setVariable("END_REQUIRED", "required=\"required\"");
501  }
502 
503  return $tpl->get();
504  }
505 
511  public function insert($a_tpl)
512  {
513  $html = $this->render();
514 
515  $a_tpl->setCurrentBlock("prop_generic");
516  $a_tpl->setVariable("PROP_GENERIC", $html);
517  $a_tpl->parseCurrentBlock();
518  }
519 
524  public function getTableFilterHTML()
525  {
526  return $this->render();
527  }
528 
533  public function getValue()
534  {
535  return array(
536  'start' => $this->getStart()->get(IL_CAL_UNIX),
537  'end' => $this->getEnd()->get(IL_CAL_UNIX)
538  );
539  }
540 
547  public function setValue($value)
548  {
549  if(is_array($value))
550  {
551  $this->setStart(new ilDateTime($value['start'], IL_CAL_UNIX));
552  $this->setEnd(new ilDateTime($value['end'], IL_CAL_UNIX));
553  }
554  }
555 
556  public function hideSubForm()
557  {
558  if($this->invalid_input_start ||
559  $this->invalid_input_end)
560  {
561  return false;
562  }
563 
564  return ((!$this->getStart() || $this->getStart()->isNull()) &&
565  (!$this->getEnd() || $this->getEnd()->isNull()));
566  }
567 }
getShowSeconds()
Show seconds not implemented yet.
Interface for property form input GUI classes that can be used in table filters.
__construct($a_title="", $a_postvar="")
Constructor.
const IL_CAL_DATETIME
checkInput()
Check input, strip slashes etc.
setStartYear($a_year)
Set start year.
getPostVar()
Get Post Variable.
enabledToggleFullTime()
Check if toggling between date and time enabled.
static _after(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
setStart(ilDateTime $a_date=null)
Set start date E.g $dt_form->setDate(new ilDateTime(time(),IL_CAL_UTC)); or $dt_form->setDate(new ilD...
$valid
parseDatePickerConfig()
parse properties to datepicker config
getTableFilterHTML()
Used for table filter presentation.
const IL_CAL_UNIX
getValue()
Used for storing the date duration data in session for table gui filters.
setAlert($a_alert)
Set Alert Text.
getShowTime()
Get Show Time Information.
global $tpl
Definition: ilias.php:8
setType($a_type)
Set Type.
getMinuteStepSize()
Get minute step size.
input GUI for a time span (start and end date)
setMinuteStepSize($a_step_size)
Set minute step size E.g 5 => The selection will only show 00,05,10...
static getUserDateFormat($a_add_time=false, $a_for_parsing=false)
Parse current user setting into date/time format.
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.
special template class to simplify handling of ITX/PEAR
const IL_CAL_FKT_DATE
Date and time handling
$ilUser
Definition: imgupload.php:18
setValueByArray($a_values)
Set value by array.
setShowTime($a_showtime)
Set Show Time Information.
Create styles array
The data for the language used.
setStartText($a_txt)
Set text, which will be shown before the start date.
setEnd(ilDateTime $a_date=null)
Set end date E.g $dt_form->setDate(new ilDateTime(time(),IL_CAL_UTC)); or $dt_form->setDate(new ilDat...
const IL_CAL_DATE
setEndText($a_txt)
Set text, which will be shown before the end date.
This class represents a property that may include a sub form.
global $lng
Definition: privfeed.php:17
setValue($value)
Called from table gui with the stored session value Attention: If the user resets the table filter...
insert($a_tpl)
Insert property html.
enableToggleFullTime($a_title, $a_checked)
Enable toggling between date and time.
$_POST["username"]
$html
Definition: example_001.php:87
static parseIncomingDate($a_value, $a_add_time=null)
Try to parse incoming value to date object.