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 {
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 {
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,
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()) {
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
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}
user()
Definition: user.php:4
$tpl
Definition: ilias.php:10
$_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.
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
$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.
$config
Definition: bootstrap.php:15
$post
Definition: post.php:34
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18