ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilCalendarMonthGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 protected int $bkid; // booking user
30 protected int $num_appointments = 1;
31 protected array $schedule_filters = array();
32
35 protected string $timezone = 'UTC';
36
37 public function __construct(ilDate $seed_date)
38 {
40 $this->bkid = $this->initBookingUserFromQuery();
41 }
42
43 public function setBkId(int $bkid = 0): void
44 {
45 $this->bkid = $bkid;
46 }
47
48 public function initialize(int $a_calendar_presentation_type): void
49 {
50 parent::initialize($a_calendar_presentation_type);
51 $this->tabs_gui->setSubTabActive('app_month');
52 $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
53 $this->app_colors = new ilCalendarAppointmentColors($this->user->getId());
54 if ($this->user->getTimeZone()) {
55 $this->timezone = $this->user->getTimeZone();
56 }
57 }
58
59 public function executeCommand(): void
60 {
61 $this->ctrl->saveParameter($this, 'seed');
62
63 $next_class = $this->ctrl->getNextClass();
64 switch ($next_class) {
65 case "ilcalendarappointmentpresentationgui":
66 $this->ctrl->setReturn($this, "");
67 $gui = ilCalendarAppointmentPresentationGUI::_getInstance($this->seed, (array) $this->getCurrentApp());
68 $this->ctrl->forwardCommand($gui);
69 break;
70 case 'ilcalendarappointmentgui':
71 $this->ctrl->setReturn($this, '');
72 $this->tabs_gui->setSubTabActive((string) ilSession::get('cal_last_tab'));
73 // initial date for new calendar appointments
74 $idate = new ilDate($this->initInitialDateFromQuery(), IL_CAL_DATE);
75 $app = new ilCalendarAppointmentGUI($this->seed, $idate, $this->initAppointmentIdFromQuery());
76 $this->ctrl->forwardCommand($app);
77 break;
78
79 default:
80 $time = microtime(true);
81 $cmd = $this->ctrl->getCmd("show");
82 $this->$cmd();
83 $this->main_tpl->setContent($this->tpl->get());
84 break;
85 }
86 }
87
91 public function addScheduleFilter(ilCalendarScheduleFilter $a_filter): void
92 {
93 $this->schedule_filters[] = $a_filter;
94 }
95
96 public function show(): void
97 {
98 $this->tpl = new ilTemplate('tpl.month_view.html', true, true, 'components/ILIAS/Calendar');
99
100 $navigation = new ilCalendarHeaderNavigationGUI($this, $this->seed, ilDateTime::MONTH);
101 $this->tpl->setVariable('NAVIGATION', $navigation->getHTML());
102
103 for ($i = $this->user_settings->getWeekStart(); $i < (7 + $this->user_settings->getWeekStart()); $i++) {
104 $this->tpl->setCurrentBlock('month_header_col');
105 $this->tpl->setVariable('TXT_WEEKDAY', ilCalendarUtil::_numericDayToString($i, true));
106 $this->tpl->parseCurrentBlock();
107 }
108
109 if ($this->bkid) {
111 $disable_empty = true;
112 $no_add = true;
113 } else {
114 if ($this->user->getId() == ANONYMOUS_USER_ID) {
115 $user_id = $this->user->getId();
116 $disable_empty = false;
117 $no_add = true;
118 } else {
119 $user_id = $this->user->getId();
120 $disable_empty = false;
121 $no_add = false;
122 }
123 }
124
125 $is_portfolio_embedded = false;
127 $no_add = true;
128 $is_portfolio_embedded = true;
129 }
130 $scheduler = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_MONTH, $user_id);
131 $scheduler->addSubitemCalendars(true);
132 if (sizeof($this->schedule_filters)) {
133 foreach ($this->schedule_filters as $filter) {
134 $scheduler->addFilter($filter);
135 }
136 }
137 $scheduler->calculate();
138
140
141 $counter = 0;
143 (int) $this->seed->get(IL_CAL_FKT_DATE, 'm'),
144 (int) $this->seed->get(IL_CAL_FKT_DATE, 'Y'),
145 $this->user_settings->getWeekStart()
146 )->get() as $date) {
147 $counter++;
148 $has_events = (bool) $this->showEvents($scheduler, $date);
149
150 if (!$this->view_with_appointments && $has_events) {
151 $this->view_with_appointments = true;
152 }
153
154 if (!$no_add) {
155 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
156 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $date->get(IL_CAL_DATE));
157 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
158 $current_hour = (new ilDateTime(time(), IL_CAL_UNIX))->get(IL_CAL_FKT_DATE, 'G', $this->user->getTimeZone());
159 $this->ctrl->setParameterByClass("ilcalendarappointmentgui", "hour", $current_hour);
160 $new_app_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'add');
161
162 $this->tpl->setCurrentBlock("new_app");
163 $this->tpl->setVariable(
164 'NEW_GLYPH',
165 $this->ui_renderer->render(
166 $this->ui_factory->button()->shy(
167 '',
168 $new_app_url
169 )->withSymbol($this->ui_factory->symbol()->glyph()->add())
170 )
171 );
172 $this->tpl->parseCurrentBlock();
173
174 // }
175 }
176
177 $day = (int) $date->get(IL_CAL_FKT_DATE, 'j');
178 $month = (int) $date->get(IL_CAL_FKT_DATE, 'n');
179
180 if ($day == 1) {
181 $month_day = '1 ' . ilCalendarUtil::_numericMonthToString($month, false);
182 } else {
183 $month_day = $day;
184 }
185
186 if (!$is_portfolio_embedded &&
187 (!$disable_empty || $has_events)) {
188 $this->tpl->setCurrentBlock('month_day_link');
189 $this->ctrl->clearParametersByClass('ilcalendardaygui');
190 $this->ctrl->setParameterByClass('ilcalendardaygui', 'seed', $date->get(IL_CAL_DATE));
191 $this->tpl->setVariable('OPEN_DAY_VIEW', $this->ctrl->getLinkTargetByClass('ilcalendardaygui', ''));
192 $this->ctrl->clearParametersByClass('ilcalendardaygui');
193 } else {
194 $this->tpl->setCurrentBlock('month_day_no_link');
195 }
196
197 $this->tpl->setVariable('MONTH_DAY', $month_day);
198
199 $this->tpl->parseCurrentBlock();
200
201 $this->tpl->setCurrentBlock('month_col');
202
203 if (ilCalendarUtil::_isToday($date)) {
204 $this->tpl->setVariable('TD_CLASS', 'caltoday');
205 } elseif (ilDateTime::_equals($date, $this->seed, IL_CAL_MONTH)) {
206 $this->tpl->setVariable('TD_CLASS', 'calstd');
207 } elseif (ilDateTime::_before($date, $this->seed, IL_CAL_MONTH)) {
208 $this->tpl->setVariable('TD_CLASS', 'calprev');
209 } else {
210 $this->tpl->setVariable('TD_CLASS', 'calnext');
211 }
212 $this->tpl->parseCurrentBlock();
213 if ($counter && !($counter % 7)) {
214 $this->tpl->setCurrentBlock('month_row');
215 $this->tpl->parseCurrentBlock();
216 }
217 }
218 }
219
220 public function getHTML(): string
221 {
222 $this->show();
223 return $this->tpl->get();
224 }
225
226 protected function showEvents(ilCalendarSchedule $scheduler, ilDate $date): int
227 {
228 $count = 0;
229 $time = '';
230 foreach ($scheduler->getByDay($date, $this->timezone) as $item) {
231 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
232 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $item['event']->getEntryId());
233
234 $event_tpl = new ilTemplate('tpl.month_event_view.html', true, true, 'components/ILIAS/Calendar');
235
236 if (!$item['event']->isFullDay()) {
237 switch ($this->user_settings->getTimeFormat()) {
239 $time = $item['event']->getStart()->get(IL_CAL_FKT_DATE, 'H:i', $this->timezone);
240 break;
241
243 $time = $item['event']->getStart()->get(IL_CAL_FKT_DATE, 'h:ia', $this->timezone);
244 break;
245 }
246 }
247
248 //plugins can change the modal title.
249 $shy = $this->getAppointmentShyButton($item['event'], (string) $item['dstart'], "");
250 $event_html = ($time != "") ? $time . " " . $shy : $shy;
251 $event_tpl->setCurrentBlock('il_event');
252
253 //Start configuring the default template
254 $event_tpl->setVariable(
255 'EVENT_EDIT_LINK',
256 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit')
257 );
258 $event_tpl->setVariable('EVENT_NUM', $item['event']->getEntryId());
259 $event_tpl->setVariable('EVENT_CONTENT', $event_html);
260 $color = $this->app_colors->getColorByAppointment($item['event']->getEntryId());
261 $event_tpl->setVariable('EVENT_BGCOLOR', $color);
262 $event_tpl->setVariable('EVENT_ADD_STYLES', $item['event']->getPresentationStyle());
263 $event_tpl->setVariable('EVENT_FONTCOLOR', ilCalendarUtil::calculateFontColor($color));
264
265 //plugins can override the previous template variables. The plugin slot parses the current block because
266 //it needs to call the template get method to use the resulting HTML in the replaceContent method.
267 if ($event_html_by_plugin = $this->getContentByPlugins(
268 $item['event'],
269 $item['dstart'],
270 $event_html,
271 $event_tpl
272 )) {
273 $event_body_html = $event_html_by_plugin;
274 } else {
275 $event_tpl->parseCurrentBlock();
276 $event_body_html = $event_tpl->get();
277 }
278
279 $this->tpl->setCurrentBlock("event_nfd");
280 $this->tpl->setVariable("EVENT_CONTENT", $event_body_html);
281 $this->tpl->parseCurrentBlock();
282
283 $this->num_appointments++;
284 $count++;
285 }
286 return $count;
287 }
288}
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_MONTH
const IL_CAL_FKT_DATE
Administrate calendar appointments.
static _getInstance(ilDate $seed, array $a_app)
get singleton instance
static _getInstance($a_usr_id=0)
get singleton instance
initialize(int $a_calendar_presentation_type)
__construct(ilDate $seed_date)
ilCalendarUserSettings $user_settings
addScheduleFilter(ilCalendarScheduleFilter $a_filter)
Add schedule filter.
showEvents(ilCalendarSchedule $scheduler, ilDate $date)
ilCalendarAppointmentColors $app_colors
Represents a list of calendar appointments (including recurring events) for a specific user in a give...
getByDay(ilDate $a_start, string $a_timezone)
static _getInstanceByUserId(int $a_user_id)
static calculateFontColor(string $a_html_color_code)
Calculate best font color from html hex color code.
static _numericDayToString(int $a_day, bool $a_long=true, ?ilLanguage $lng=null)
static _buildMonthDayList(int $a_month, int $a_year, int $weekstart)
Build a month day list.
static _numericMonthToString(int $a_month, bool $a_long=true, ?ilLanguage $lng=null)
numeric month to string
static _isToday(ilDateTime $date)
getAppointmentShyButton(ilCalendarEntry $a_calendar_entry, string $a_dstart, string $a_title_forced="")
getContentByPlugins(ilCalendarEntry $a_cal_entry, int $a_start_date, string $a_content, ilTemplate $a_tpl)
@classDescription Date and time handling
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Class for single dates.
static get(string $a_var)
special template class to simplify handling of ITX/PEAR
const ANONYMOUS_USER_ID
Definition: constants.php:27
Calendar schedule filter interface.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$counter