ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
37  public function __construct($a_title = "", $a_postvar = "")
38  {
39  global $DIC;
40 
41  $this->lng = $DIC->language();
42  $this->user = $DIC->user();
43  parent::__construct($a_title, $a_postvar);
44  $this->setType("datetime");
45  }
46 
58  public function setDate(ilDateTime $a_date = null)
59  {
60  $this->date = $a_date;
61  }
62 
68  public function getDate()
69  {
70  return $this->date;
71  }
72 
78  public function setShowTime($a_showtime)
79  {
80  $this->showtime = $a_showtime;
81  }
82 
88  public function getShowTime()
89  {
90  return $this->showtime;
91  }
92 
98  public function setStartYear($a_year)
99  {
100  $this->startyear = $a_year;
101  }
102 
108  public function getStartYear()
109  {
110  return $this->startyear;
111  }
112 
121  public function setMinuteStepSize($a_step_size)
122  {
123  $this->minute_step_size = $a_step_size;
124  }
125 
132  public function getMinuteStepSize()
133  {
135  }
136 
142  public function setShowSeconds($a_showseconds)
143  {
144  $this->showseconds = $a_showseconds;
145  }
146 
152  public function getShowSeconds()
153  {
154  return $this->showseconds;
155  }
156 
162  public function setValueByArray($a_values)
163  {
164  $incoming = $a_values[$this->getPostVar()];
166 
167  foreach ($this->getSubItems() as $item) {
168  $item->setValueByArray($a_values);
169  }
170  }
171 
172  protected function getDatePickerTimeFormat()
173  {
174  return (int) $this->getShowTime() + (int) $this->getShowSeconds();
175  }
176 
177  public function hasInvalidInput()
178  {
179  return (bool) $this->invalid_input;
180  }
181 
187  public function checkInput()
188  {
189  $lng = $this->lng;
190 
191  if ($this->getDisabled()) {
192  return true;
193  }
194 
195  $post = $_POST[$this->getPostVar()];
196 
197  // always done to make sure there are no obsolete values left
198  $this->setDate(null);
199 
200  $valid = false;
201  if (trim($post)) {
203  if ($parsed) {
204  $this->setDate($parsed);
205  $valid = true;
206  }
207  } elseif (!$this->getRequired()) {
208  $valid = true;
209  }
210 
211  if ($valid &&
212  $this->getDate() &&
213  $this->getStartYear() &&
214  $this->getDate()->get(IL_CAL_FKT_DATE, "Y") < $this->getStartYear()) {
215  $valid = false;
216  }
217 
218  if (!$valid) {
219  $this->invalid_input = $post;
220  $_POST[$this->getPostVar()] = null;
221 
222  $this->setAlert($lng->txt("form_msg_wrong_date"));
223  } else {
224  if ($this->getDate() !== null) {
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  } else {
231  $_POST[$this->getPostVar()] = null;
232  }
233  }
234 
235  if ($valid) {
236  $valid = $this->checkSubItemsInput();
237  }
238 
239  return $valid;
240  }
241 
247  protected function parseDatePickerConfig()
248  {
249  $config = null;
250  if ($this->getMinuteStepSize()) {
251  $config['stepping'] = (int) $this->getMinuteStepSize();
252  }
253  if ($this->getStartYear()) {
254  $config['minDate'] = $this->getStartYear() . '-01-01';
255  }
256  return $config;
257  }
258 
263  public function render()
264  {
266  $lng = $this->lng;
267 
268  $tpl = new ilTemplate("tpl.prop_datetime.html", true, true, "Services/Form");
269 
270  // config picker
271  if (!$this->getDisabled()) {
272  $picker_id = md5($this->getPostVar()); // :TODO: unique?
273  $tpl->setVariable('DATEPICKER_ID', $picker_id);
274 
276  $picker_id,
277  $this->getDatePickerTimeFormat(),
278  $this->parseDatePickerConfig(),
279  null,
280  null,
281  null,
282  "subform_" . $this->getPostVar()
283  );
284  } else {
285  $tpl->setVariable('DATEPICKER_DISABLED', 'disabled="disabled" ');
286  }
287 
288  // :TODO: i18n?
290  $tpl->setVariable('PLACEHOLDER', $pl_format);
291 
292  // accessibility description
293  $tpl->setVariable(
294  'DESCRIPTION',
295  ilUtil::prepareFormOutput($lng->txt("form_date_aria_desc") . " " . $pl_format)
296  );
297 
298  // current value
299  $date_value = htmlspecialchars($this->invalid_input);
300  if (!$date_value &&
301  $this->getDate()) {
302  $out_format = ilCalendarUtil::getUserDateFormat($this->getDatePickerTimeFormat(), true);
303  $date_value = $this->getDate()->get(IL_CAL_FKT_DATE, $out_format, $ilUser->getTimeZone());
304  }
305 
306  $tpl->setVariable('DATEPICKER_VALUE', $date_value);
307  $tpl->setVariable('DATE_ID', $this->getPostVar());
308 
309  if ($this->getRequired()) {
310  $tpl->setVariable("REQUIRED", "required=\"required\"");
311  }
312 
313  return $tpl->get();
314  }
315 
321  public function insert($a_tpl)
322  {
323  $html = $this->render();
324 
325  $a_tpl->setCurrentBlock("prop_generic");
326  $a_tpl->setVariable("PROP_GENERIC", $html);
327  $a_tpl->parseCurrentBlock();
328  }
329 
333  public function getTableFilterHTML()
334  {
335  $html = $this->render();
336  return $html;
337  }
338 
342  public function serializeData()
343  {
344  if ($this->getDate()) {
345  return serialize($this->getDate()->get(IL_CAL_UNIX));
346  }
347  }
348 
352  public function unserializeData($a_data)
353  {
354  $tmp = unserialize($a_data);
355  if ($tmp) {
356  // we used to serialize the complete instance
357  if (is_object($tmp)) {
358  $date = $tmp;
359  } else {
360  $date = $this->getShowTime()
361  ? new ilDateTime($tmp, IL_CAL_UNIX)
362  : new ilDate($tmp, IL_CAL_UNIX);
363  }
364  $this->setDate($date);
365  } else {
366  $this->setDate(null);
367  }
368  }
369 
375  public function getPostValueForComparison()
376  {
377  // :TODO:
378  return trim($_POST[$this->getPostVar()]);
379  }
380 
384  public function getToolbarHTML()
385  {
386  $html = $this->render("toolbar");
387  return $html;
388  }
389 
390  public function hideSubForm()
391  {
392  return (!$this->getDate() || $this->getDate()->isNull());
393  }
394 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
Interface for property form input GUI classes that can be used in table filters.
parseDatePickerConfig()
parse properties to datepicker config
const IL_CAL_DATETIME
$config
Definition: bootstrap.php:15
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
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
__construct($a_title="", $a_postvar="")
Constructor.
user()
Definition: user.php:4
setAlert($a_alert)
Set Alert Text.
This class represents a date/time property in a property form.
getShowTime()
Get Show Time Information.
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.
special template class to simplify handling of ITX/PEAR
const IL_CAL_FKT_DATE
setDate(ilDateTime $a_date=null)
set date E.g $dt_form->setDate(new ilDateTime(time(),IL_CAL_UTC)); or $dt_form->setDate(new ilDateTim...
$post
Definition: post.php:34
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.
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.