ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilCalendarDayGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29{
30 protected array $seed_info = [];
32 protected int $num_appointments = 1;
33 protected string $timezone = 'UTC';
35
36 public function __construct(ilDate $seed_date)
37 {
39 }
40
41 public function initialize(int $a_calendar_presentation_type): void
42 {
43 global $DIC;
44
45 parent::initialize($a_calendar_presentation_type);
46 $this->seed_info = (array) $this->seed->get(IL_CAL_FKT_GETDATE);
47 $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
48 $this->app_colors = new ilCalendarAppointmentColors($this->user->getId());
49 if ($this->user->getTimeZone()) {
50 $this->timezone = $this->user->getTimeZone();
51 }
52 }
53
54 public function executeCommand(): void
55 {
56 $next_class = $this->ctrl->getNextClass();
57 switch ($next_class) {
58 case "ilcalendarappointmentpresentationgui":
59 $this->ctrl->setReturn($this, "");
60 $this->logger->debug("-ExecCommand - representation of ilDate: this->seed->get(IL_CAL_DATE) = " . $this->seed->get(IL_CAL_DATE));
61 $gui = ilCalendarAppointmentPresentationGUI::_getInstance($this->seed, (array) $this->getCurrentApp());
62 $this->ctrl->forwardCommand($gui);
63 break;
64 case 'ilcalendarappointmentgui':
65 $this->ctrl->setReturn($this, '');
66 $this->tabs_gui->setSubTabActive((string) ilSession::get('cal_last_tab'));
67
68 // initial date for new calendar appointments
69 $idate = new ilDate($this->initInitialDateFromQuery(), IL_CAL_DATE);
70 $app = new ilCalendarAppointmentGUI($this->seed, $idate, $this->initAppointmentIdFromQuery());
71 $this->ctrl->forwardCommand($app);
72 break;
73
74 default:
75 $cmd = $this->ctrl->getCmd("show");
76 $this->$cmd();
77 $this->main_tpl->setContent($this->tpl->get());
78 break;
79 }
80 }
81
86 protected function show(): void
87 {
88 // config
89 $raster = 15;
90 if ($this->user_settings->getDayStart()) {
91 // push starting point to last "slot" of hour BEFORE morning aggregation
92 $morning_aggr = ($this->user_settings->getDayStart() - 1) * 60 + (60 - $raster);
93 } else {
94 $morning_aggr = 0;
95 }
96 $evening_aggr = $this->user_settings->getDayEnd() * 60;
97
98 $this->tpl = new ilTemplate('tpl.day_view.html', true, true, 'components/ILIAS/Calendar');
99
100 $bkid = $this->initBookingUserFromQuery();
101 if ($bkid) {
102 $user_id = $bkid;
103 $no_add = true;
104 } elseif ($this->user->getId() == ANONYMOUS_USER_ID) {
105 $user_id = $this->user->getId();
106 $no_add = true;
107 } else {
108 $user_id = $this->user->getId();
109 $no_add = false;
110 }
111 $scheduler = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_DAY, $user_id);
112 $scheduler->addSubitemCalendars(true);
113 $scheduler->calculate();
114 $daily_apps = $scheduler->getByDay($this->seed, $this->timezone);
115
116 //display the download files button.
117 if (count($daily_apps)) {
118 $this->view_with_appointments = true;
119 }
120
121 $hours = $this->parseInfoIntoRaster(
122 $daily_apps,
123 $morning_aggr,
124 $evening_aggr,
125 $raster
126 );
127
128 $colspan = $this->calculateColspan($hours);
129
130 $navigation = new ilCalendarHeaderNavigationGUI($this, $this->seed, ilDateTime::DAY);
131 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
132
133 if (!$no_add) {
134 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
135 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $this->seed->get(IL_CAL_DATE));
136 $new_app_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'add');
137
138 $this->tpl->setCurrentBlock("new_app1");
139 $this->tpl->setVariable(
140 'H_NEW_APP_GLYPH',
141 $this->ui_renderer->render(
142 $this->ui_factory->button()->shy(
143 '',
144 $new_app_url,
145 )->withSymbol($this->ui_factory->symbol()->glyph()->add())
146 )
147 );
148 $this->tpl->parseCurrentBlock();
149
150 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
151 }
152
153 $this->tpl->setVariable('NAVIGATION', $navigation->getHTML());
154
155 $this->tpl->setVariable(
156 'HEADER_DATE',
157 $this->seed_info['mday'] . ' ' . ilCalendarUtil::_numericMonthToString($this->seed_info['mon'], false)
158 );
159 $this->tpl->setVariable(
160 'HEADER_DAY',
161 ilCalendarUtil::_numericDayToString((int) $this->seed_info['wday'], true)
162 );
163 $this->tpl->setVariable('HCOLSPAN', $colspan - 1);
164
165 $this->tpl->setVariable('TXT_TIME', $this->lng->txt("time"));
166
167 // show fullday events
168 foreach ($daily_apps as $event) {
169 if ($event['fullday']) {
170 $this->showFulldayAppointment($event);
171 }
172 }
173 $this->tpl->setCurrentBlock('fullday_apps');
174 $this->tpl->setVariable('TXT_F_DAY', $this->lng->txt("cal_all_day"));
175 $this->tpl->setVariable('COLSPAN', $colspan - 1);
176 $this->tpl->parseCurrentBlock();
177
178 // parse the hour rows
179 foreach ($hours as $numeric => $hour) {
180 if (!($numeric % 60) || ($numeric == $morning_aggr && $morning_aggr) ||
181 ($numeric == $evening_aggr && $evening_aggr)) {
182 if (!$no_add) {
183 $this->tpl->setCurrentBlock("new_app2");
184 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
185 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
186 $this->ctrl->setParameterByClass(
187 'ilcalendarappointmentgui',
188 'idate',
189 $this->seed->get(IL_CAL_DATE)
190 );
191 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'hour', floor($numeric / 60));
192 $this->tpl->setVariable(
193 'NEW_APP_GLYPH',
194 $this->ui_renderer->render(
195 $this->ui_factory->button()->shy(
196 '',
197 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'add')
198 )->withSymbol($this->ui_factory->symbol()->glyph()->add())
199 )
200 );
201 $this->tpl->parseCurrentBlock();
202 }
203
204 // aggregation rows
205 if (($numeric == $morning_aggr && $morning_aggr) ||
206 ($numeric == $evening_aggr && $evening_aggr)) {
207 $this->tpl->setVariable('TIME_ROWSPAN', 1);
208 } // rastered hour
209 else {
210 $this->tpl->setVariable('TIME_ROWSPAN', 60 / $raster);
211 }
212
213 $this->tpl->setCurrentBlock('time_txt');
214
215 $this->tpl->setVariable('TIME', $hour['txt']);
216 $this->tpl->parseCurrentBlock();
217 }
218
219 foreach ($hour['apps_start'] as $app) {
220 $this->showAppointment($app);
221 }
222
223 for ($i = ($colspan - 1); $i > $hour['apps_num']; $i--) {
224 $this->tpl->setCurrentBlock('empty_cell');
225 $this->tpl->setVariable('EMPTY_WIDTH', (100 / ($colspan - 1)) . '%');
226
227 // last "slot" of hour needs border
228 if ($numeric % 60 == 60 - $raster ||
229 ($numeric == $morning_aggr && $morning_aggr) ||
230 ($numeric == $evening_aggr && $evening_aggr)) {
231 $this->tpl->setVariable('EMPTY_STYLE', ' calempty_border');
232 }
233
234 $this->tpl->parseCurrentBlock();
235 }
236
237 $this->tpl->touchBlock('time_row');
238 }
239 }
240
241 protected function showFulldayAppointment(array $a_app): void
242 {
243 $event_tpl = new ilTemplate('tpl.day_event_view.html', true, true, 'components/ILIAS/Calendar');
244
245 $event_tpl->setCurrentBlock('fullday_app');
246
247 $content = $this->getAppointmentShyButton($a_app['event'], (string) $a_app['dstart'], "");
248
249 $event_tpl->setVariable('EVENT_CONTENT', $content);
250
251 $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
252 $event_tpl->setVariable('F_APP_BGCOLOR', $color);
253 $event_tpl->setVariable('F_APP_FONTCOLOR', ilCalendarUtil::calculateFontColor($color));
254
255 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
256 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
257 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
258 $event_tpl->setVariable(
259 'F_APP_EDIT_LINK',
260 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit')
261 );
262
263 if ($event_html_by_plugin = $this->getContentByPlugins(
264 $a_app['event'],
265 $a_app['dstart'],
266 $content,
267 $event_tpl
268 )) {
269 $body_html = $event_html_by_plugin;
270 } else {
271 $event_tpl->parseCurrentBlock();
272 $body_html = $event_tpl->get();
273 }
274
275 $this->tpl->setCurrentBlock("content_fd");
276 $this->tpl->setVariable("CONTENT_EVENT", $body_html);
277 $this->tpl->parseCurrentBlock();
278 $this->num_appointments++;
279 }
280
281 protected function showAppointment(array $a_app): void
282 {
283 $event_tpl = new ilTemplate('tpl.day_event_view.html', true, true, 'components/ILIAS/Calendar');
284 $event_tpl->setCurrentBlock('app');
285 $this->tpl->setVariable('APP_ROWSPAN', $a_app['rowspan']);
286 $time = '';
287 switch ($this->user_settings->getTimeFormat()) {
289 $time = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE, 'H:i', $this->timezone);
290 break;
291
293 $time = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE, 'h:ia', $this->timezone);
294 break;
295 }
296
297 $shy = $this->getAppointmentShyButton($a_app['event'], (string) $a_app['dstart'], "");
298
299 $title = $shy;
300 $content = ($time != "") ? $time . " " . $title : $title;
301 $event_tpl->setVariable('EVENT_CONTENT', $content);
302
303 $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
304 $event_tpl->setVariable('APP_BGCOLOR', $color);
305 $event_tpl->setVariable('APP_COLOR', ilCalendarUtil::calculateFontColor($color));
306 $event_tpl->setVariable('APP_ADD_STYLES', $a_app['event']->getPresentationStyle());
307
308 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
309 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
310 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
311 $event_tpl->setVariable('APP_EDIT_LINK', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit'));
312
313 if ($event_html_by_plugin = $this->getContentByPlugins(
314 $a_app['event'],
315 $a_app['dstart'],
316 $content,
317 $event_tpl
318 )) {
319 $event_html = $event_html_by_plugin;
320 } else {
321 $event_tpl->parseCurrentBlock();
322 $event_html = $event_tpl->get();
323 }
324
325 $this->tpl->setCurrentBlock("event_nfd");
326 $this->tpl->setVariable("CONTENT_EVENT_NFD", $event_html);
327 $this->tpl->parseCurrentBlock();
328
329 $this->num_appointments++;
330 }
331
335 protected function parseInfoIntoRaster(array $daily_apps, int $morning_aggr, int $evening_aggr, int $raster): array
336 {
337 $hours = array();
338 for ($i = $morning_aggr; $i <= $evening_aggr; $i += $raster) {
339 $hours[$i]['apps_start'] = array();
340 $hours[$i]['apps_num'] = 0;
341
342 switch ($this->user_settings->getTimeFormat()) {
344 if ($morning_aggr > 0 && $i == $morning_aggr) {
345 $hours[$i]['txt'] = sprintf('%02d:00', 0) . ' - ' .
346 sprintf('%02d:00', ceil(($i + 1) / 60));
347 } else {
348 if (!isset($hours[$i]['txt'])) {
349 $hours[$i]['txt'] = sprintf('%02d:%02d', floor($i / 60), $i % 60);
350 } else {
351 $hours[$i]['txt'] .= sprintf('%02d:%02d', floor($i / 60), $i % 60);
352 }
353 }
354 if ($evening_aggr < 23 * 60 && $i == $evening_aggr) {
355 if (!isset($hours[$i]['txt'])) {
356 $hours[$i]['txt'] = ' - ' . sprintf('%02d:00', 0);
357 } else {
358 $hours[$i]['txt'] .= ' - ' . sprintf('%02d:00', 0);
359 }
360 }
361 break;
362
364 $this->logger->notice('Morning: ' . $morning_aggr . ' and $i:' . $i);
365 if ($morning_aggr > 0 && $i == $morning_aggr) {
366 $hours[$i]['txt'] =
367 date('h a', mktime(0, 0, 0, 1, 1, 2000)) . ' - ' .
368 date('h a', mktime($this->user_settings->getDayStart(), 0, 0, 1, 1, 2000));
369 } else {
370 $hours[$i]['txt'] = date('h a', mktime((int) floor($i / 60), $i % 60, 0, 1, 1, 2000));
371 }
372 if ($evening_aggr < 23 * 60 && $i == $evening_aggr) {
373 if (!isset($hours[$i]['txt'])) {
374 $hours[$i]['txt'] = ' - ' . date('h a', mktime(0, 0, 0, 1, 1, 2000));
375 } else {
376 $hours[$i]['txt'] .= ' - ' . date('h a', mktime(0, 0, 0, 1, 1, 2000));
377 }
378 }
379 break;
380 }
381 }
382
383 foreach ($daily_apps as $app) {
384 // fullday appointment are not relavant
385 if ($app['fullday']) {
386 continue;
387 }
388 // start hour for this day
389 #21132 #21636
390 if ($app['start_info']['mday'] != $this->seed_info['mday']) {
391 $start = 0;
392 } else {
393 $start = $app['start_info']['hours'] * 60 + $app['start_info']['minutes'];
394 }
395 #21636
396
397 // end hour for this day
398 #21132
399 if ($app['end_info']['mday'] != $this->seed_info['mday']) {
400 $end = 23 * 60;
401 } elseif ($app['start_info']['hours'] == $app['end_info']['hours']) {
402 $end = $start + $raster;
403 } else {
404 $end = $app['end_info']['hours'] * 60 + $app['end_info']['minutes'];
405 }
406
407 if ($start < $morning_aggr) {
408 $start = $morning_aggr;
409 }
410 if ($end <= $morning_aggr) {
411 $end = $morning_aggr + $raster;
412 }
413 if ($start > $evening_aggr) {
414 $start = $evening_aggr;
415 }
416 if ($end > $evening_aggr + $raster) {
417 $end = $evening_aggr + $raster;
418 }
419 if ($end <= $start) {
420 $end = $start + $raster;
421 }
422
423 // map start and end to raster
424 $start = floor($start / $raster) * $raster;
425 $end = ceil($end / $raster) * $raster;
426
427 $first = true;
428 for ($i = $start; $i < $end; $i += $raster) {
429 if ($first) {
430 $app['rowspan'] = ceil(($end - $start) / $raster);
431 $hours[$i]['apps_start'][] = $app;
432 $first = false;
433 }
434 $hours[$i]['apps_num']++;
435 }
436 }
437 return $hours;
438 }
439
440 protected function calculateColspan(array $hours): int
441 {
442 $colspan = 1;
443 foreach ($hours as $hour) {
444 $colspan = max($colspan, $hour['apps_num'] + 1);
445 }
446 return max($colspan, 2);
447 }
448}
const IL_CAL_FKT_GETDATE
const IL_CAL_DATE
const IL_CAL_FKT_DATE
Administrate calendar appointments.
static _getInstance(ilDate $seed, array $a_app)
get singleton instance
Presentation day view.
showFulldayAppointment(array $a_app)
__construct(ilDate $seed_date)
show()
fill data section @access protected
ilCalendarUserSettings $user_settings
initialize(int $a_calendar_presentation_type)
parseInfoIntoRaster(array $daily_apps, int $morning_aggr, int $evening_aggr, int $raster)
calculate overlapping hours
ilCalendarAppointmentColors $app_colors
calculateColspan(array $hours)
Represents a list of calendar appointments (including recurring events) for a specific user in a give...
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 _numericMonthToString(int $a_month, bool $a_long=true, ?ilLanguage $lng=null)
numeric month to string
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)
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
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26