ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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($this->ui_factory->symbol()->glyph()->add($new_app_url))
142 );
143 $this->tpl->parseCurrentBlock();
144
145 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
146 }
147
148 $this->tpl->setVariable('NAVIGATION', $navigation->getHTML());
149
150 $this->tpl->setVariable(
151 'HEADER_DATE',
152 $this->seed_info['mday'] . ' ' . ilCalendarUtil::_numericMonthToString($this->seed_info['mon'], false)
153 );
154 $this->tpl->setVariable(
155 'HEADER_DAY',
156 ilCalendarUtil::_numericDayToString((int) $this->seed_info['wday'], true)
157 );
158 $this->tpl->setVariable('HCOLSPAN', $colspan - 1);
159
160 $this->tpl->setVariable('TXT_TIME', $this->lng->txt("time"));
161
162 // show fullday events
163 foreach ($daily_apps as $event) {
164 if ($event['fullday']) {
165 $this->showFulldayAppointment($event);
166 }
167 }
168 $this->tpl->setCurrentBlock('fullday_apps');
169 $this->tpl->setVariable('TXT_F_DAY', $this->lng->txt("cal_all_day"));
170 $this->tpl->setVariable('COLSPAN', $colspan - 1);
171 $this->tpl->parseCurrentBlock();
172
173 // parse the hour rows
174 foreach ($hours as $numeric => $hour) {
175 if (!($numeric % 60) || ($numeric == $morning_aggr && $morning_aggr) ||
176 ($numeric == $evening_aggr && $evening_aggr)) {
177 if (!$no_add) {
178 $this->tpl->setCurrentBlock("new_app2");
179 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
180 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
181 $this->ctrl->setParameterByClass(
182 'ilcalendarappointmentgui',
183 'idate',
184 $this->seed->get(IL_CAL_DATE)
185 );
186 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'hour', floor($numeric / 60));
187 $this->tpl->setVariable(
188 'NEW_APP_GLYPH',
189 $this->ui_renderer->render($this->ui_factory->symbol()->glyph()->add(
190 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'add')
191 ))
192 );
193 $this->tpl->parseCurrentBlock();
194 }
195
196 // aggregation rows
197 if (($numeric == $morning_aggr && $morning_aggr) ||
198 ($numeric == $evening_aggr && $evening_aggr)) {
199 $this->tpl->setVariable('TIME_ROWSPAN', 1);
200 } // rastered hour
201 else {
202 $this->tpl->setVariable('TIME_ROWSPAN', 60 / $raster);
203 }
204
205 $this->tpl->setCurrentBlock('time_txt');
206
207 $this->tpl->setVariable('TIME', $hour['txt']);
208 $this->tpl->parseCurrentBlock();
209 }
210
211 foreach ($hour['apps_start'] as $app) {
212 $this->showAppointment($app);
213 }
214
215 for ($i = ($colspan - 1); $i > $hour['apps_num']; $i--) {
216 $this->tpl->setCurrentBlock('empty_cell');
217 $this->tpl->setVariable('EMPTY_WIDTH', (100 / ($colspan - 1)) . '%');
218
219 // last "slot" of hour needs border
220 if ($numeric % 60 == 60 - $raster ||
221 ($numeric == $morning_aggr && $morning_aggr) ||
222 ($numeric == $evening_aggr && $evening_aggr)) {
223 $this->tpl->setVariable('EMPTY_STYLE', ' calempty_border');
224 }
225
226 $this->tpl->parseCurrentBlock();
227 }
228
229 $this->tpl->touchBlock('time_row');
230 }
231 }
232
233 protected function showFulldayAppointment(array $a_app): void
234 {
235 $event_tpl = new ilTemplate('tpl.day_event_view.html', true, true, 'components/ILIAS/Calendar');
236
237 $event_tpl->setCurrentBlock('fullday_app');
238
239 $content = $this->getAppointmentShyButton($a_app['event'], (string) $a_app['dstart'], "");
240
241 $event_tpl->setVariable('EVENT_CONTENT', $content);
242
243 $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
244 $event_tpl->setVariable('F_APP_BGCOLOR', $color);
245 $event_tpl->setVariable('F_APP_FONTCOLOR', ilCalendarUtil::calculateFontColor($color));
246
247 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
248 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
249 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
250 $event_tpl->setVariable(
251 'F_APP_EDIT_LINK',
252 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit')
253 );
254
255 if ($event_html_by_plugin = $this->getContentByPlugins(
256 $a_app['event'],
257 $a_app['dstart'],
258 $content,
259 $event_tpl
260 )) {
261 $body_html = $event_html_by_plugin;
262 } else {
263 $event_tpl->parseCurrentBlock();
264 $body_html = $event_tpl->get();
265 }
266
267 $this->tpl->setCurrentBlock("content_fd");
268 $this->tpl->setVariable("CONTENT_EVENT", $body_html);
269 $this->tpl->parseCurrentBlock();
270 $this->num_appointments++;
271 }
272
273 protected function showAppointment(array $a_app): void
274 {
275 $event_tpl = new ilTemplate('tpl.day_event_view.html', true, true, 'components/ILIAS/Calendar');
276 $event_tpl->setCurrentBlock('app');
277 $this->tpl->setVariable('APP_ROWSPAN', $a_app['rowspan']);
278 $time = '';
279 switch ($this->user_settings->getTimeFormat()) {
281 $time = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE, 'H:i', $this->timezone);
282 break;
283
285 $time = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE, 'h:ia', $this->timezone);
286 break;
287 }
288
289 $shy = $this->getAppointmentShyButton($a_app['event'], (string) $a_app['dstart'], "");
290
291 $title = $shy;
292 $content = ($time != "") ? $time . " " . $title : $title;
293 $event_tpl->setVariable('EVENT_CONTENT', $content);
294
295 $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
296 $event_tpl->setVariable('APP_BGCOLOR', $color);
297 $event_tpl->setVariable('APP_COLOR', ilCalendarUtil::calculateFontColor($color));
298 $event_tpl->setVariable('APP_ADD_STYLES', $a_app['event']->getPresentationStyle());
299
300 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
301 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
302 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
303 $event_tpl->setVariable('APP_EDIT_LINK', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit'));
304
305 if ($event_html_by_plugin = $this->getContentByPlugins(
306 $a_app['event'],
307 $a_app['dstart'],
308 $content,
309 $event_tpl
310 )) {
311 $event_html = $event_html_by_plugin;
312 } else {
313 $event_tpl->parseCurrentBlock();
314 $event_html = $event_tpl->get();
315 }
316
317 $this->tpl->setCurrentBlock("event_nfd");
318 $this->tpl->setVariable("CONTENT_EVENT_NFD", $event_html);
319 $this->tpl->parseCurrentBlock();
320
321 $this->num_appointments++;
322 }
323
327 protected function parseInfoIntoRaster(array $daily_apps, int $morning_aggr, int $evening_aggr, int $raster): array
328 {
329 $hours = array();
330 for ($i = $morning_aggr; $i <= $evening_aggr; $i += $raster) {
331 $hours[$i]['apps_start'] = array();
332 $hours[$i]['apps_num'] = 0;
333
334 switch ($this->user_settings->getTimeFormat()) {
336 if ($morning_aggr > 0 && $i == $morning_aggr) {
337 $hours[$i]['txt'] = sprintf('%02d:00', 0) . ' - ' .
338 sprintf('%02d:00', ceil(($i + 1) / 60));
339 } else {
340 if (!isset($hours[$i]['txt'])) {
341 $hours[$i]['txt'] = sprintf('%02d:%02d', floor($i / 60), $i % 60);
342 } else {
343 $hours[$i]['txt'] .= sprintf('%02d:%02d', floor($i / 60), $i % 60);
344 }
345 }
346 if ($evening_aggr < 23 * 60 && $i == $evening_aggr) {
347 if (!isset($hours[$i]['txt'])) {
348 $hours[$i]['txt'] = ' - ' . sprintf('%02d:00', 0);
349 } else {
350 $hours[$i]['txt'] .= ' - ' . sprintf('%02d:00', 0);
351 }
352 }
353 break;
354
356 $this->logger->notice('Morning: ' . $morning_aggr . ' and $i:' . $i);
357 if ($morning_aggr > 0 && $i == $morning_aggr) {
358 $hours[$i]['txt'] =
359 date('h a', mktime(0, 0, 0, 1, 1, 2000)) . ' - ' .
360 date('h a', mktime($this->user_settings->getDayStart(), 0, 0, 1, 1, 2000));
361 } else {
362 $hours[$i]['txt'] = date('h a', mktime((int) floor($i / 60), $i % 60, 0, 1, 1, 2000));
363 }
364 if ($evening_aggr < 23 * 60 && $i == $evening_aggr) {
365 if (!isset($hours[$i]['txt'])) {
366 $hours[$i]['txt'] = ' - ' . date('h a', mktime(0, 0, 0, 1, 1, 2000));
367 } else {
368 $hours[$i]['txt'] .= ' - ' . date('h a', mktime(0, 0, 0, 1, 1, 2000));
369 }
370 }
371 break;
372 }
373 }
374
375 foreach ($daily_apps as $app) {
376 // fullday appointment are not relavant
377 if ($app['fullday']) {
378 continue;
379 }
380 // start hour for this day
381 #21132 #21636
382 if ($app['start_info']['mday'] != $this->seed_info['mday']) {
383 $start = 0;
384 } else {
385 $start = $app['start_info']['hours'] * 60 + $app['start_info']['minutes'];
386 }
387 #21636
388
389 // end hour for this day
390 #21132
391 if ($app['end_info']['mday'] != $this->seed_info['mday']) {
392 $end = 23 * 60;
393 } elseif ($app['start_info']['hours'] == $app['end_info']['hours']) {
394 $end = $start + $raster;
395 } else {
396 $end = $app['end_info']['hours'] * 60 + $app['end_info']['minutes'];
397 }
398
399 if ($start < $morning_aggr) {
400 $start = $morning_aggr;
401 }
402 if ($end <= $morning_aggr) {
403 $end = $morning_aggr + $raster;
404 }
405 if ($start > $evening_aggr) {
406 $start = $evening_aggr;
407 }
408 if ($end > $evening_aggr + $raster) {
409 $end = $evening_aggr + $raster;
410 }
411 if ($end <= $start) {
412 $end = $start + $raster;
413 }
414
415 // map start and end to raster
416 $start = floor($start / $raster) * $raster;
417 $end = ceil($end / $raster) * $raster;
418
419 $first = true;
420 for ($i = $start; $i < $end; $i += $raster) {
421 if ($first) {
422 $app['rowspan'] = ceil(($end - $start) / $raster);
423 $hours[$i]['apps_start'][] = $app;
424 $first = false;
425 }
426 $hours[$i]['apps_num']++;
427 }
428 }
429 return $hours;
430 }
431
432 protected function calculateColspan(array $hours): int
433 {
434 $colspan = 1;
435 foreach ($hours as $hour) {
436 $colspan = max($colspan, $hour['apps_num'] + 1);
437 }
438 return max($colspan, 2);
439 }
440}
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