ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
19 protected $lng;
20
24 protected $user;
25
26 protected $date;
27 protected $time = "00:00:00";
28 protected $showtime = false;
29 protected $showseconds = false;
30 protected $minute_step_size = 5;
31 protected $startyear = '';
32 protected $invalid_input = '';
33
40 public function __construct($a_title = "", $a_postvar = "")
41 {
42 global $DIC;
43
44 $this->lng = $DIC->language();
45 $this->user = $DIC->user();
46 parent::__construct($a_title, $a_postvar);
47 $this->setType("datetime");
48 }
49
61 public function setDate(ilDateTime $a_date = null)
62 {
63 $this->date = $a_date;
64 }
65
71 public function getDate()
72 {
73 return $this->date;
74 }
75
81 public function setShowTime($a_showtime)
82 {
83 $this->showtime = $a_showtime;
84 }
85
91 public function getShowTime()
92 {
93 return $this->showtime;
94 }
95
101 public function setStartYear($a_year)
102 {
103 $this->startyear = $a_year;
104 }
105
111 public function getStartYear()
112 {
113 return $this->startyear;
114 }
115
124 public function setMinuteStepSize($a_step_size)
125 {
126 $this->minute_step_size = $a_step_size;
127 }
128
135 public function getMinuteStepSize()
136 {
138 }
139
145 public function setShowSeconds($a_showseconds)
146 {
147 $this->showseconds = $a_showseconds;
148 }
149
155 public function getShowSeconds()
156 {
157 return $this->showseconds;
158 }
159
165 public function setValueByArray($a_values)
166 {
167 $incoming = $a_values[$this->getPostVar()];
169
170 foreach ($this->getSubItems() as $item) {
171 $item->setValueByArray($a_values);
172 }
173 }
174
175 protected function getDatePickerTimeFormat()
176 {
177 return (int) $this->getShowTime() + (int) $this->getShowSeconds();
178 }
179
180 public function hasInvalidInput()
181 {
182 return (bool) $this->invalid_input;
183 }
184
190 public function checkInput()
191 {
193
194 if ($this->getDisabled()) {
195 return true;
196 }
197
198 $post = $_POST[$this->getPostVar()];
199
200 // always done to make sure there are no obsolete values left
201 $this->setDate(null);
202
203 $valid = false;
204 if (trim($post)) {
206 if ($parsed) {
207 $this->setDate($parsed);
208 $valid = true;
209 }
210 } elseif (!$this->getRequired()) {
211 $valid = true;
212 }
213
214 if ($valid &&
215 $this->getDate() &&
216 $this->getStartYear() &&
217 $this->getDate()->get(IL_CAL_FKT_DATE, "Y") < $this->getStartYear()) {
218 $valid = false;
219 }
220
221 if (!$valid) {
222 $this->invalid_input = $post;
223 $_POST[$this->getPostVar()] = null;
224
225 $this->setAlert($lng->txt("form_msg_wrong_date"));
226 } else {
227 if ($this->getDate() !== null) {
228 // getInput() should return a generic format
229 $post_format = $this->getShowTime()
231 : IL_CAL_DATE;
232 $_POST[$this->getPostVar()] = $this->getDate()->get($post_format);
233 } else {
234 $_POST[$this->getPostVar()] = null;
235 }
236 }
237
238 if ($valid) {
239 $valid = $this->checkSubItemsInput();
240 }
241
242 return $valid;
243 }
244
250 protected function parseDatePickerConfig()
251 {
252 $config = null;
253 if ($this->getMinuteStepSize()) {
254 $config['stepping'] = (int) $this->getMinuteStepSize();
255 }
256 if ($this->getStartYear()) {
257 $config['minDate'] = $this->getStartYear() . '-01-01';
258 }
259 return $config;
260 }
261
266 public function render()
267 {
269
270 $tpl = new ilTemplate("tpl.prop_datetime.html", true, true, "Services/Form");
271
272 // config picker
273 if (!$this->getDisabled()) {
274 $picker_id = md5($this->getPostVar()); // :TODO: unique?
275 $tpl->setVariable('DATEPICKER_ID', $picker_id);
276
278 $picker_id,
280 $this->parseDatePickerConfig(),
281 null,
282 null,
283 null,
284 "subform_" . $this->getPostVar()
285 );
286 } else {
287 $tpl->setVariable('DATEPICKER_DISABLED', 'disabled="disabled" ');
288 }
289
290 // :TODO: i18n?
292 $tpl->setVariable('PLACEHOLDER', $pl_format);
293
294 // current value
295 $date_value = htmlspecialchars($this->invalid_input);
296 if (!$date_value &&
297 $this->getDate()) {
299 $date_value = $this->getDate()->get(IL_CAL_FKT_DATE, $out_format, $ilUser->getTimeZone());
300 }
301
302 $tpl->setVariable('DATEPICKER_VALUE', $date_value);
303 $tpl->setVariable('DATE_ID', $this->getPostVar());
304
305 if ($this->getRequired()) {
306 $tpl->setVariable("REQUIRED", "required=\"required\"");
307 }
308
309 return $tpl->get();
310 }
311
317 public function insert($a_tpl)
318 {
319 $html = $this->render();
320
321 $a_tpl->setCurrentBlock("prop_generic");
322 $a_tpl->setVariable("PROP_GENERIC", $html);
323 $a_tpl->parseCurrentBlock();
324 }
325
329 public function getTableFilterHTML()
330 {
331 $html = $this->render();
332 return $html;
333 }
334
338 public function serializeData()
339 {
340 if ($this->getDate()) {
341 return serialize($this->getDate()->get(IL_CAL_UNIX));
342 }
343 }
344
348 public function unserializeData($a_data)
349 {
350 $tmp = unserialize($a_data);
351 if ($tmp) {
352 // we used to serialize the complete instance
353 if (is_object($tmp)) {
354 $date = $tmp;
355 } else {
356 $date = $this->getShowTime()
357 ? new ilDateTime($tmp, IL_CAL_UNIX)
358 : new ilDate($tmp, IL_CAL_UNIX);
359 }
360 $this->setDate($date);
361 } else {
362 $this->setDate(null);
363 }
364 }
365
372 {
373 // :TODO:
374 return trim($_POST[$this->getPostVar()]);
375 }
376
380 public function getToolbarHTML()
381 {
382 $html = $this->render("toolbar");
383 return $html;
384 }
385
386 public function hideSubForm()
387 {
388 return (!$this->getDate() || $this->getDate()->isNull());
389 }
390}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
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
$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.
$post
Definition: post.php:34
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18