ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_once("./Services/Calendar/classes/class.ilCalendarUtil.php");
5 include_once("./Services/Table/interfaces/interface.ilTableFilterItem.php");
6 
15 {
16  protected $date;
17  protected $time = "00:00:00";
18  protected $showtime = false;
19  protected $showseconds = false;
20  protected $minute_step_size = 5;
21  protected $startyear = '';
22  protected $invalid_input = '';
23 
30  function __construct($a_title = "", $a_postvar = "")
31  {
32  parent::__construct($a_title, $a_postvar);
33  $this->setType("datetime");
34  }
35 
47  function setDate(ilDateTime $a_date = NULL)
48  {
49  $this->date = $a_date;
50  }
51 
57  function getDate()
58  {
59  return $this->date;
60  }
61 
67  function setShowTime($a_showtime)
68  {
69  $this->showtime = $a_showtime;
70  }
71 
77  function getShowTime()
78  {
79  return $this->showtime;
80  }
81 
87  function setStartYear($a_year)
88  {
89  $this->startyear = $a_year;
90  }
91 
97  function getStartYear()
98  {
99  return $this->startyear;
100  }
101 
110  public function setMinuteStepSize($a_step_size)
111  {
112  $this->minute_step_size = $a_step_size;
113  }
114 
121  public function getMinuteStepSize()
122  {
124  }
125 
131  function setShowSeconds($a_showseconds)
132  {
133  $this->showseconds = $a_showseconds;
134  }
135 
141  function getShowSeconds()
142  {
143  return $this->showseconds;
144  }
145 
151  function setValueByArray($a_values)
152  {
153  $incoming = $a_values[$this->getPostVar()];
155 
156  foreach($this->getSubItems() as $item)
157  {
158  $item->setValueByArray($a_values);
159  }
160  }
161 
162  protected function getDatePickerTimeFormat()
163  {
164  return (int)$this->getShowTime() + (int)$this->getShowSeconds();
165  }
166 
167  public function hasInvalidInput()
168  {
169  return (bool)$this->invalid_input;
170  }
171 
177  function checkInput()
178  {
179  global $lng;
180 
181  if ($this->getDisabled())
182  {
183  return true;
184  }
185 
186  $post = $_POST[$this->getPostVar()];
187 
188  // always done to make sure there are no obsolete values left
189  $this->setDate(null);
190 
191  $valid = false;
192  if(trim($post))
193  {
195  if($parsed)
196  {
197  $this->setDate($parsed);
198  $valid = true;
199  }
200  }
201  else if(!$this->getRequired())
202  {
203  $valid = true;
204  }
205 
206  if($valid &&
207  $this->getDate() &&
208  $this->getStartYear() &&
209  $this->getDate()->get(IL_CAL_FKT_DATE, "Y") < $this->getStartYear())
210  {
211  $valid = false;
212  }
213 
214  if(!$valid)
215  {
216  $this->invalid_input = $post;
217  $_POST[$this->getPostVar()] = null;
218 
219  $this->setAlert($lng->txt("form_msg_wrong_date"));
220  }
221  else
222  {
223  if($this->getDate() !== null)
224  {
225  // getInput() should return a generic format
226  $post_format = $this->getShowTime()
228  : IL_CAL_DATE;
229  $_POST[$this->getPostVar()] = $this->getDate()->get($post_format);
230  }
231  else
232  {
233  $_POST[$this->getPostVar()] = null;
234  }
235  }
236 
237  if($valid)
238  {
239  $valid = $this->checkSubItemsInput();
240  }
241 
242  return $valid;
243  }
244 
250  protected function parseDatePickerConfig()
251  {
252  $config = null;
253  if($this->getMinuteStepSize())
254  {
255  $config['stepping'] = (int)$this->getMinuteStepSize();
256  }
257  if($this->getStartYear())
258  {
259  $config['minDate'] = $this->getStartYear().'-01-01';
260  }
261  return $config;
262  }
263 
268  function render()
269  {
270  global $ilUser;
271 
272  $tpl = new ilTemplate("tpl.prop_datetime.html", true, true, "Services/Form");
273 
274  // config picker
275  if(!$this->getDisabled())
276  {
277  $picker_id = md5($this->getPostVar()); // :TODO: unique?
278  $tpl->setVariable('DATEPICKER_ID', $picker_id);
279 
281  $picker_id,
282  $this->getDatePickerTimeFormat(),
283  $this->parseDatePickerConfig(),
284  null,
285  null,
286  null,
287  "subform_".$this->getPostVar()
288  );
289  }
290  else
291  {
292  $tpl->setVariable('DATEPICKER_DISABLED', 'disabled="disabled" ');
293  }
294 
295  // :TODO: i18n?
297  $tpl->setVariable('PLACEHOLDER', $pl_format);
298 
299  // current value
300  $date_value = htmlspecialchars($this->invalid_input);
301  if(!$date_value &&
302  $this->getDate())
303  {
304  $out_format = ilCalendarUtil::getUserDateFormat($this->getDatePickerTimeFormat(), true);
305  $date_value = $this->getDate()->get(IL_CAL_FKT_DATE, $out_format, $ilUser->getTimeZone());
306  }
307 
308  $tpl->setVariable('DATEPICKER_VALUE', $date_value);
309  $tpl->setVariable('DATE_ID', $this->getPostVar());
310 
311  if($this->getRequired())
312  {
313  $tpl->setVariable("REQUIRED", "required=\"required\"");
314  }
315 
316  return $tpl->get();
317  }
318 
324  function insert($a_tpl)
325  {
326  $html = $this->render();
327 
328  $a_tpl->setCurrentBlock("prop_generic");
329  $a_tpl->setVariable("PROP_GENERIC", $html);
330  $a_tpl->parseCurrentBlock();
331  }
332 
337  {
338  $html = $this->render();
339  return $html;
340  }
341 
345  function serializeData()
346  {
347  if($this->getDate())
348  {
349  return serialize($this->getDate()->get(IL_CAL_UNIX));
350  }
351  }
352 
356  function unserializeData($a_data)
357  {
358  $tmp = unserialize($a_data);
359  if($tmp)
360  {
361  // we used to serialize the complete instance
362  if(is_object($tmp))
363  {
364  $date = $tmp;
365  }
366  else
367  {
368  $date = $this->getShowTime()
369  ? new ilDateTime($tmp, IL_CAL_UNIX)
370  : new ilDate($tmp, IL_CAL_UNIX);
371  }
372  $this->setDate($date);
373  }
374  else
375  {
376  $this->setDate(null);
377  }
378  }
379 
386  {
387  // :TODO:
388  return trim($_POST[$this->getPostVar()]);
389  }
390 
394  function getToolbarHTML()
395  {
396  $html = $this->render("toolbar");
397  return $html;
398  }
399 
400  public function hideSubForm()
401  {
402  return (!$this->getDate() || $this->getDate()->isNull());
403  }
404 }
405 
406 ?>
Interface for property form input GUI classes that can be used in table filters.
parseDatePickerConfig()
parse properties to datepicker config
const IL_CAL_DATETIME
getPostValueForComparison()
parse post value to make it comparable
getPostVar()
Get Post Variable.
getDate()
Get Date, yyyy-mm-dd.
$valid
getMinuteStepSize()
Get minute step size.
Interface for property form input GUI classes that can be used in ilToolbarGUI.
checkInput()
Check input, strip slashes etc.
setStartYear($a_year)
Set start year.
const IL_CAL_UNIX
setDate(ilDateTime $a_date=NULL)
set date E.g $dt_form->setDate(new ilDateTime(time(),IL_CAL_UTC)); or $dt_form->setDate(new ilDateTim...
__construct($a_title="", $a_postvar="")
Constructor.
setAlert($a_alert)
Set Alert Text.
This class represents a date/time property in a property form.
getShowTime()
Get Show Time Information.
global $tpl
Definition: ilias.php:8
setType($a_type)
Set Type.
setValueByArray($a_values)
Set value by array.
getTableFilterHTML()
Get HTML for table filter.
Class for single dates.
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.
setShowSeconds($a_showseconds)
Set Show Seconds.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
special template class to simplify handling of ITX/PEAR
const IL_CAL_FKT_DATE
Date and time handling
$ilUser
Definition: imgupload.php:18
getShowSeconds()
Get Show Seconds.
unserializeData($a_data)
unserialize data
setMinuteStepSize($a_step_size)
Set minute step size E.g 5 => The selection will only show 00,05,10...
const IL_CAL_DATE
getToolbarHTML()
Get HTML for toolbar.
This class represents a property that may include a sub form.
global $lng
Definition: privfeed.php:17
getStartYear()
Get start year.
render()
Insert property html.
$_POST["username"]
$html
Definition: example_001.php:87
static parseIncomingDate($a_value, $a_add_time=null)
Try to parse incoming value to date object.
setShowTime($a_showtime)
Set Show Time Information.
insert($a_tpl)
Insert property html.