19declare(strict_types=1);
47 string $a_postvar =
""
51 $this->
lng = $DIC->language();
52 $this->
user = $DIC->user();
62 $this->toggle_fulltime_txt = $a_title;
63 $this->toggle_fulltime_checked = $a_checked;
64 $this->toggle_fulltime =
true;
69 return $this->toggle_fulltime;
83 $this->start = $a_date;
88 $this->start_text = $a_txt;
93 return $this->start_text;
98 $this->end_text = $a_txt;
103 return $this->end_text;
122 $this->end = $a_date;
132 $this->showtime = $a_showtime;
137 return $this->showtime;
142 $this->startyear = $a_year;
147 return $this->startyear;
157 $this->minute_step_size = $a_step_size;
170 $incoming = $a_values[$this->getPostVar()] ?? [];
171 if (is_array($incoming) && $incoming !== []) {
172 $format = isset($incoming[
'tgl']) ? 0 : $this->getDatePickerTimeFormat();
173 $this->toggle_fulltime_checked = (bool) ($incoming[
'tgl'] ??
false);
175 if ($this->openIntervalsAllowed()) {
176 if (isset($incoming[
'start']) && is_string($incoming[
'start']) && trim($incoming[
'start']) !==
'') {
182 if (isset($incoming[
'end']) && is_string($incoming[
'end']) && trim($incoming[
'end']) !==
'') {
189 if ($incoming[
'start'] instanceof
ilDateTime) {
190 $this->setStart($incoming[
'start']);
195 $this->setEnd($incoming[
'end']);
202 foreach ($this->getSubItems() as $item) {
203 $item->setValueByArray($a_values);
211 if ($this->getDisabled()) {
217 $start =
$post[
"start"] ??
'';
218 $end =
$post[
"end"] ??
'';
221 $format = isset(
$post[
'tgl'])
223 : $this->getDatePickerTimeFormat();
229 $valid_start =
false;
233 $this->setStart($parsed);
236 } elseif (!$this->getRequired() && !trim($end)) {
238 } elseif ($this->openIntervalsAllowed() && !strlen(trim($start))) {
246 $this->setEnd($parsed);
249 } elseif (!$this->getRequired() && !trim($start)) {
251 } elseif ($this->openIntervalsAllowed() && !strlen(trim($end))) {
255 if ($this->getStartYear()) {
257 $this->getStart()->
get(
IL_CAL_FKT_DATE,
"Y") < $this->getStartYear()) {
258 $valid_start =
false;
265 $valid = ($valid_start && $valid_end);
274 if ($this->openIntervalsAllowed()) {
277 $this->invalid_input_start = $start;
278 $this->invalid_input_end = $end;
279 $this->setAlert(
$lng->txt(
"form_msg_wrong_date"));
283 $valid = $this->checkSubItemsInput();
291 $ret = $this->
strArray($this->getPostVar());
293 if ($this->openIntervalsAllowed()) {
294 if (!$this->getStart()) {
295 $ret[
"start"] =
null;
298 if (!$this->getEnd()) {
302 !$this->getStart() ||
305 $ret[
"start"] =
null;
308 $ret[
"fullday"] = (bool) ($ret[
"tgl"] ??
false);
314 return (
int) $this->getShowTime();
320 if ($this->getShowTime()) {
328 $ilUser = $this->user;
332 $tpl =
new ilTemplate(
"tpl.prop_datetime_duration.html",
true,
true,
"components/ILIAS/Form");
334 if ($this->enabledToggleFullTime()) {
335 $this->setShowTime(
true);
337 $toggle_id =
't' . md5($this->getPostVar() .
'_fulltime');
339 $tpl->setCurrentBlock(
'toggle_fullday');
340 $tpl->setVariable(
'DATE_TOGGLE_ID', $this->getPostVar() .
'[tgl]');
341 $tpl->setVariable(
'FULLDAY_TOGGLE_ID', $toggle_id);
342 $tpl->setVariable(
'FULLDAY_TOGGLE_CHECKED', $this->toggle_fulltime_checked ?
'checked="checked"' :
'');
343 $tpl->setVariable(
'FULLDAY_TOGGLE_DISABLED', $this->getDisabled() ?
'disabled="disabled"' :
'');
344 $tpl->setVariable(
'TXT_TOGGLE_FULLDAY', $this->toggle_fulltime_txt);
345 $tpl->parseCurrentBlock();
349 if (!$this->getDisabled()) {
351 $picker_start_id =
'p' . md5($this->getPostVar() .
'_start');
352 $picker_end_id =
'p' . md5($this->getPostVar() .
'_end');
354 $tpl->setVariable(
'DATEPICKER_START_ID', $picker_start_id);
355 $tpl->setVariable(
'DATEPICKER_END_ID', $picker_end_id);
357 $this->global_tpl->addOnLoadCode(
358 'il.Form.initDateDurationPicker("' .
359 $picker_start_id .
'","' .
360 $picker_end_id .
'","' .
365 $tpl->setVariable(
'DATEPICKER_START_DISABLED',
'disabled="disabled" ');
366 $tpl->setVariable(
'DATEPICKER_END_DISABLED',
'disabled="disabled" ');
370 if ($this->getShowTime()) {
371 $type =
'datetime-local';
373 $tpl->setVariable(
'DATEPICKER_START_TYPE', $type);
374 $tpl->setVariable(
'DATEPICKER_END_TYPE', $type);
376 $start_txt = $this->getStartText();
377 if ($start_txt ===
null) {
378 $start_txt =
$lng->txt(
"form_date_duration_start");
380 if (trim($start_txt)) {
381 $tpl->setVariable(
'START_LABEL', $start_txt);
383 $tpl->touchBlock(
'start_width_bl');
386 $end_txt = $this->getEndText();
387 if ($end_txt ===
null) {
388 $end_txt =
$lng->txt(
"form_date_duration_end");
390 if (trim($end_txt)) {
391 $tpl->setVariable(
'END_LABEL', $end_txt);
393 $tpl->touchBlock(
'end_width_bl');
397 $tpl->setVariable(
'DATE_START_ID', $this->getPostVar() .
'[start]');
398 $tpl->setVariable(
'DATE_END_ID', $this->getPostVar() .
'[end]');
405 if (!$this->getShowTime()) {
408 $tpl->setVariable(
'DATEPICKER_START_STEP', $step_size);
409 $tpl->setVariable(
'DATEPICKER_END_STEP', $step_size);
411 if ($this->getStartYear()) {
412 $min = DateTimeImmutable::createFromFormat(
414 (
string) $this->getStartYear()
415 )->format($this->getDatetimeFormatForInput());
416 $tpl->setVariable(
'DATEPICKER_START_MIN', $min);
417 $tpl->setVariable(
'DATEPICKER_END_MIN', $min);
422 $out_format = $this->getDatetimeFormatForInput();
423 $date_value = $this->prepareInvalidInputAsValue($this->invalid_input_start);
426 $date_value = $this->getStart()->get(
IL_CAL_FKT_DATE, $out_format, $ilUser->getTimeZone());
428 $tpl->setVariable(
'DATEPICKER_START_VALUE', $date_value);
430 $date_value = $this->prepareInvalidInputAsValue($this->invalid_input_end);
433 $date_value = $this->getEnd()->get(
IL_CAL_FKT_DATE, $out_format, $ilUser->getTimeZone());
435 $tpl->setVariable(
'DATEPICKER_END_VALUE', $date_value);
437 if ($this->getRequired()) {
438 $tpl->setVariable(
"START_REQUIRED",
"required=\"required\"");
439 $tpl->setVariable(
"END_REQUIRED",
"required=\"required\"");
447 $timestamp = strtotime(htmlspecialchars($invalid_input));
451 return date($this->getDatetimeFormatForInput(),
$timestamp);
457 $html = $this->render();
466 return $this->render();
472 'start' => $this->getStart() ? $this->getStart()->
get(
IL_CAL_UNIX) :
null,
473 'end' => $this->getEnd() ? $this->getEnd()->
get(
IL_CAL_UNIX) :
null
485 if (is_array($value)) {
493 if ($this->invalid_input_start ||
494 $this->invalid_input_end) {
498 return ((!$this->getStart() || $this->getStart()->isNull()) &&
499 (!$this->getEnd() || $this->getEnd()->isNull()));
504 return $this->allowOpenIntervals;
509 $this->allowOpenIntervals = $allowOpenInterval;
514 return $this->getFieldId() .
"[start]";
519 return $this->getFieldId() .
"[start]";
foreach($mandatory_scripts as $file) $timestamp
setVariable($variable, $value='')
Sets a variable value.
static parseIncomingDate($value, bool $add_time=false)
Try to parse incoming value to date object.
@classDescription Date and time handling
static _after(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc