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
4require_once("./Services/Calendar/classes/class.ilCalendarUtil.php");
5include_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,
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?>
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
global $tpl
Definition: ilias.php:8
$_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 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.
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.
getShowSeconds()
Get Show Seconds.
getPostValueForComparison()
parse post value to make it comparable
unserializeData($a_data)
unserialize data
checkInput()
Check input, strip slashes etc.
setDate(ilDateTime $a_date=NULL)
set date E.g $dt_form->setDate(new ilDateTime(time(),IL_CAL_UTC)); or $dt_form->setDate(new ilDateTim...
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.
@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
$valid
$html
Definition: example_001.php:87
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.
global $lng
Definition: privfeed.php:17
$ilUser
Definition: imgupload.php:18