ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCalendarHeaderNavigationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
25{
26 protected object $cmdClass;
27 protected string $cmd;
28 protected ilDate $seed;
29 protected string $increment = '';
30
31 protected string $html;
32
33 protected ilLanguage $lng;
37 protected ilObjUser $user;
39 protected \ILIAS\DI\UIServices $ui;
40
41 public function __construct(object $cmdClass, ilDate $seed, string $a_increment, string $cmd = '')
42 {
43 global $DIC;
44
45 $this->lng = $DIC->language();
46
47 $this->ctrl = $DIC->ctrl();
48 $this->cmdClass = $cmdClass;
49 $this->seed = clone $seed;
50 $this->increment = $a_increment;
51 $this->cmd = $cmd;
52 $this->toolbar = $DIC->toolbar();
53 $this->ui = $DIC->ui();
54 $this->user = $DIC->user();
55 $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
56 }
57
58 public function getHTML(): string
59 {
60 $today = new ilDateTime(time(), IL_CAL_UNIX, $this->user->getTimeZone());
61 $tpl = new ilTemplate("tpl.navigation_header.html", true, true, "components/ILIAS/Calendar");
62
63 // previous button
64 $contains_today = false;
65 $this->incrementDate(-1);
66 $this->ctrl->setParameterByClass(get_class($this->cmdClass), 'seed', $this->seed->get(IL_CAL_DATE));
67 $b1 = $this->ui->factory()->button()->standard(
68 $this->lng->txt("previous"),
69 $this->ctrl->getLinkTarget($this->cmdClass, $this->cmd)
70 );
71
72 // today button
73 $this->incrementDate(1);
75 switch ($this->increment) {
76 case ilDateTime::DAY:
78 "TXT_TITLE",
79 ilCalendarUtil::_numericDayToString((int) $this->seed->get(IL_CAL_FKT_DATE, 'w')) .
80 ", " . ilDatePresentation::formatDate($this->seed)
81 );
82 if (date("Y-m-d") === $this->seed->get(IL_CAL_FKT_DATE, 'Y-m-d')) {
83 $contains_today = true;
84 }
85 break;
86
89 $this->seed,
90 $this->user_settings->getWeekStart()
91 )->get();
92 $start = current($weekday_list);
93 $end = end($weekday_list);
94 $tpl->setVariable("TXT_TITLE", $this->lng->txt('week') . ' ' . $this->seed->get(IL_CAL_FKT_DATE, 'W') .
95 ", " . ilDatePresentation::formatDate($start) . " - " .
97 $il_date_now = new ilDateTime(ilUtil::now(), IL_CAL_DATETIME);
98 if (ilDate::_within($il_date_now, $start, $end)) {
99 $contains_today = true;
100 }
101 break;
102
105 "TXT_TITLE",
106 $this->lng->txt('month_' . $this->seed->get(IL_CAL_FKT_DATE, 'm') . '_long') .
107 ' ' . $this->seed->get(IL_CAL_FKT_DATE, 'Y')
108 );
109 if ($this->seed->get(IL_CAL_FKT_DATE, 'Y-m') == date("Y-m")) {
110 $contains_today = true;
111 }
112 break;
113 }
115 $this->ctrl->setParameterByClass(
116 get_class($this->cmdClass),
117 'seed',
118 $today->get(IL_CAL_DATE)
119 );
120 if ($contains_today) {
121 $b2 = $this->ui->factory()->button()->standard(
122 $this->lng->txt("today"),
123 $this->ctrl->getLinkTarget($this->cmdClass, $this->cmd)
124 )->withEngagedState(true);
125 } else {
126 $b2 = $this->ui->factory()->button()->standard(
127 $this->lng->txt("today"),
128 $this->ctrl->getLinkTarget($this->cmdClass, $this->cmd)
129 );
130 }
131 // next button
132 $this->incrementDate(1);
133 $this->ctrl->setParameterByClass(get_class($this->cmdClass), 'seed', $this->seed->get(IL_CAL_DATE));
134 $b3 = $this->ui->factory()->button()->standard(
135 $this->lng->txt("next"),
136 $this->ctrl->getLinkTarget($this->cmdClass, $this->cmd)
137 );
138 $this->ctrl->setParameterByClass(get_class($this->cmdClass), 'seed', '');
139 $this->toolbar->addStickyItem($this->ui->factory()->viewControl()->section($b1, $b2, $b3));
140 $this->toolbar->addSeparator();
141
142 return $tpl->get();
143 }
144
145 protected function incrementDate(int $a_count): void
146 {
147 switch ($this->increment) {
149 $day = $this->seed->get(IL_CAL_FKT_DATE, 'j');
150 if ($day > 28) {
151 $this->seed->increment(IL_CAL_DAY, (31 - $day) * -1);
152 }
153 // no break
154 default:
155 $this->seed->increment($this->increment, $a_count);
156 break;
157 }
158 }
159}
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_CAL_FKT_DATE
const IL_CAL_DAY
__construct(object $cmdClass, ilDate $seed, string $a_increment, string $cmd='')
static _getInstanceByUserId(int $a_user_id)
static _numericDayToString(int $a_day, bool $a_long=true, ?ilLanguage $lng=null)
static _buildWeekDayList(ilDate $a_day, int $a_weekstart)
build week day list @access public
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
static _within(ilDateTime $dt, ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check whether an date is within a date duration given by start and end.
Class for single dates.
language handling
User class.
special template class to simplify handling of ITX/PEAR
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static now()
Return current timestamp in Y-m-d H:i:s format.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26