ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCalendarBlockGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Refinery\Factory as RefineryFactory;
23use ILIAS\HTTP\Services as HttpServices;
24
34{
35 protected array $cal_footer = [];
36 protected ?ilCalendarSchedule $scheduler = null;
37 protected RefineryFactory $refinery;
38 protected HttpServices $http;
40 protected string $display_mode = '';
41 protected ilLogger $logger;
42
43 public static string $block_type = "cal";
44
45 protected ilTabsGUI $tabs;
47 protected ilHelpGUI $help;
48
49
50 protected ilDate $seed;
53
54 protected string $parent_gui = ilColumnGUI::class;
55 protected bool $force_month_view = false;
56
58 protected array $modals = [];
59
64 public function __construct()
65 {
66 global $DIC;
67
69
70 $this->logger = $DIC->logger()->cal();
71 $this->tabs = $DIC->tabs();
72 $this->obj_data_cache = $DIC["ilObjDataCache"];
73 $this->ui = $DIC->ui();
74 $this->help = $DIC->help();
75 $this->http = $DIC->http();
76 $this->refinery = $DIC->refinery();
77
78 $this->lng->loadLanguageModule("dateplaner");
79 $this->help->addHelpSection("cal_block");
80
81 $this->ctrl->saveParameter($this, 'bkid');
82 $this->setBlockId((string) $this->ctrl->getContextObjId());
83 $this->setLimit(5); // @todo: needed?
84 $this->setEnableNumInfo(false);
85 $title = $this->lng->txt("calendar");
86 $this->setTitle($title);
87 $this->allow_moving = false;
88
89 $params = $DIC->http()->request()->getQueryParams();
90 $this->requested_cal_agenda_per = (int) ($params['cal_agenda_per'] ?? null);
91
92 $seed_str = $this->initSeedFromQuery();
93 if (!strlen($seed_str) && ilSession::has("il_cal_block_" . $this->getBlockType() . "_" . $this->getBlockId() . "_seed")) {
94 $seed_str = ilSession::get("il_cal_block_" . $this->getBlockType() . "_" . $this->getBlockId() . "_seed");
95 } elseif (strlen($seed_str)) {
96 ilSession::set("il_cal_block_" . $this->getBlockType() . "_" . $this->getBlockId() . "_seed", $seed_str);
97 } else {
98 $seed_str = date('Y-m-d', time());
99 }
100 $this->seed = new ilDate($seed_str, IL_CAL_DATE);
102 $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($DIC->user()->getId());
103
104 $mode = $this->user->getPref("il_pd_cal_mode");
105 $this->display_mode = $mode ?: "mmon";
106
107 if ($this->display_mode !== "mmon") {
108 $this->setPresentation(self::PRES_SEC_LIST);
109 }
110 }
111
112 protected function initBookingUserFromQuery(): int
113 {
114 if ($this->http->wrapper()->query()->has('bkid')) {
115 return $this->http->wrapper()->query()->retrieve(
116 'bkid',
117 $this->refinery->kindlyTo()->int()
118 );
119 }
120 return 0;
121 }
122
123 protected function initSeedFromQuery(): string
124 {
125 if ($this->http->wrapper()->query()->has('seed')) {
126 return $this->http->wrapper()->query()->retrieve(
127 'seed',
128 $this->refinery->kindlyTo()->string()
129 );
130 }
131 return '';
132 }
133
134 protected function initAppointmentIdFromQuery(): int
135 {
136 if ($this->http->wrapper()->query()->has('app_id')) {
137 return $this->http->wrapper()->query()->retrieve(
138 'app_id',
139 $this->refinery->kindlyTo()->int()
140 );
141 }
142 return 0;
143 }
144
145 protected function initInitialDateQuery(): int
146 {
147 if ($this->http->wrapper()->query()->has('dt')) {
148 return $this->http->wrapper()->query()->retrieve(
149 'dt',
150 $this->refinery->kindlyTo()->int()
151 );
152 }
153 return 0;
154 }
155
159 public function getShowWeeksColumn(): bool
160 {
161 return ($this->settings->getShowWeeks() && $this->user_settings->getShowWeeks());
162 }
163
167 public function getBlockType(): string
168 {
169 return self::$block_type;
170 }
171
175 protected function isRepositoryObject(): bool
176 {
177 return false;
178 }
179
180 public function setParentGUI(string $a_val): void
181 {
182 $this->parent_gui = $a_val;
183 }
184
185 public function getParentGUI(): string
186 {
187 return $this->parent_gui;
188 }
189
190 public function setForceMonthView(bool $a_val): void
191 {
192 $this->force_month_view = $a_val;
193 if ($a_val) {
194 $this->display_mode = "mmon";
195 $this->setPresentation(self::PRES_SEC_LEG);
196 }
197 }
198
199 public function getForceMonthView(): bool
200 {
202 }
203
207 public static function getScreenMode(): string
208 {
209 global $DIC;
210
211 $ilCtrl = $DIC->ctrl();
212 $cmd_class = $ilCtrl->getCmdClass();
213
214 $cmd = $ilCtrl->getCmd();
215
216 if ($cmd_class == "ilcalendarappointmentgui" ||
217 $cmd_class == "ilconsultationhoursgui" ||
218 $cmd == 'showCalendarSubscription') {
219 return IL_SCREEN_CENTER;
220 }
221 return '';
222 }
223
224 public function executeCommand(): string
225 {
226 $next_class = $this->ctrl->getNextClass();
227 $cmd = $this->ctrl->getCmd("getHTML");
228
229 $this->setSubTabs();
230
231 switch ($next_class) {
232 case "ilcalendarappointmentgui":
233 $this->initCategories();
234 $app_gui = new ilCalendarAppointmentGUI($this->seed, $this->seed);
235 $this->ctrl->forwardCommand($app_gui);
236 break;
237
238 case "ilconsultationhoursgui":
239 $hours = new ilConsultationHoursGUI();
240 $this->ctrl->forwardCommand($hours);
241 break;
242
243 case "ilcalendarappointmentpresentationgui":
244 $this->initCategories();
245
247 if ($app === null) {
248 $this->logger->error(
249 'Invalid appointment ID for ref_id: ' .
250 (string) $this->initAppointmentIdFromQuery() . ' ' .
251 (string) $this->requested_ref_id
252 );
253 return $this->getHTML();
254 }
256 $this->ctrl->forwardCommand($presentation);
257 break;
258
259 case "ilcalendarmonthgui":
260 $this->tabs->setSubTabActive('app_month');
261 $month_gui = new ilCalendarMonthGUI($this->seed);
262 $this->ctrl->forwardCommand($month_gui);
263 break;
264
265 default:
266 return $this->$cmd();
267 }
268 return '';
269 }
270
271 public function getTargetGUIClassPath(): array
272 {
273 $target_class = array();
274 if (!$this->getRepositoryMode()) {
275 $target_class = array("ildashboardgui", "ilcalendarpresentationgui");
276 } else {
277 switch (ilObject::_lookupType((int) $this->requested_ref_id, true)) {
278 case "crs":
279 $target_class = array("ilobjcoursegui", "ilcalendarpresentationgui");
280 break;
281
282 case "grp":
283 $target_class = array("ilobjgroupgui", "ilcalendarpresentationgui");
284 break;
285 }
286 }
287 return $target_class;
288 }
289
294 public function addMiniMonth(ilTemplate $a_tpl, bool $a_include_view_ctrl = false): void
295 {
297 $ilUser = $this->user;
298 $ui = $this->ui;
299
300 // aria label
301 $month = (int) $this->seed->get(IL_CAL_FKT_DATE, 'm');
302 $year = (int) $this->seed->get(IL_CAL_FKT_DATE, 'Y');
303 $a_tpl->setVariable(
304 'MONTH_YEAR_LABEL',
305 ilCalendarUtil::_numericMonthToString($month, false) . ' ' . $year
306 );
307
308 // weekdays
309 if ($this->getShowWeeksColumn()) {
310 $a_tpl->setCurrentBlock('month_header_col');
311 $a_tpl->setVariable('TXT_WEEKDAY', $this->lng->txt("cal_week_abbrev"));
312 $a_tpl->parseCurrentBlock();
313 }
314 for ($i = $this->user_settings->getWeekStart(); $i < (7 + $this->user_settings->getWeekStart()); $i++) {
315 $a_tpl->setCurrentBlock('month_header_col');
316 $a_tpl->setVariable('TXT_WEEKDAY', ilCalendarUtil::_numericDayToString($i, false));
317 $a_tpl->parseCurrentBlock();
318 }
319
320 $bkid = $this->initBookingUserFromQuery();
321 if ($bkid) {
322 $user_id = $bkid;
323 $disable_empty = true;
324 } else {
325 $user_id = $this->user->getId();
326 $disable_empty = false;
327 }
328 $this->scheduler = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_MONTH, $user_id);
329 $this->scheduler->addSubitemCalendars(true);
330 $this->scheduler->calculate();
331
332 $counter = 0;
334 (int) $this->seed->get(IL_CAL_FKT_DATE, 'm'),
335 (int) $this->seed->get(IL_CAL_FKT_DATE, 'Y'),
336 $this->user_settings->getWeekStart()
337 )->get() as $date) {
338 $counter++;
339
340 $events = $this->scheduler->getByDay($date, $this->user->getTimeZone());
341 $has_events = (bool) count($events);
342 if ($has_events || !$disable_empty) {
343 $a_tpl->setCurrentBlock('month_col_link');
344 } else {
345 $a_tpl->setCurrentBlock('month_col_no_link');
346 }
347
348 if ($disable_empty) {
349 if (!$has_events) {
350 $a_tpl->setVariable('DAY_CLASS', 'calminiinactive');
351 } else {
352 $week_has_events = true;
353 foreach ($events as $event) {
354 $booking = new ilBookingEntry($event['event']->getContextId());
355 if ($booking->hasBooked($event['event']->getEntryId())) {
356 $a_tpl->setVariable('DAY_CLASS', 'calminiapp');
357 break;
358 }
359 }
360 }
361 } elseif ($has_events) {
362 $week_has_events = true;
363 $a_tpl->setVariable('DAY_CLASS', 'calminiapp');
364 }
365
366 $day = $date->get(IL_CAL_FKT_DATE, 'j');
367 $month = $date->get(IL_CAL_FKT_DATE, 'n');
368
369 $month_day = $day;
370
371 $path = $this->getTargetGUIClassPath();
372 $last_gui = end($path);
373 $this->ctrl->setParameterByClass($last_gui, 'seed', $date->get(IL_CAL_DATE));
374 if ($agenda_view_type = $this->requested_cal_agenda_per) {
375 $this->ctrl->setParameterByClass($last_gui, "cal_agenda_per", $agenda_view_type);
376 }
377 $a_tpl->setVariable('OPEN_DAY_VIEW', $this->ctrl->getLinkTargetByClass($this->getTargetGUIClassPath(), ''));
378
379 $a_tpl->setVariable('MONTH_DAY', $month_day);
380
381 $a_tpl->parseCurrentBlock();
382
383 $a_tpl->setCurrentBlock('month_col');
384
385 if (ilCalendarUtil::_isToday($date)) {
386 $a_tpl->setVariable('TD_CLASS', 'calminitoday');
387 } elseif (ilDateTime::_equals($date, $this->seed, IL_CAL_MONTH)) {
388 $a_tpl->setVariable('TD_CLASS', 'calministd');
389 } elseif (ilDateTime::_before($date, $this->seed, IL_CAL_MONTH)) {
390 $a_tpl->setVariable('TD_CLASS', 'calminiprev');
391 } else {
392 $a_tpl->setVariable('TD_CLASS', 'calmininext');
393 }
394
395 $a_tpl->parseCurrentBlock();
396
397 if ($counter and !($counter % 7)) {
398 if ($this->getShowWeeksColumn()) {
399 $a_tpl->setCurrentBlock('week');
400 $a_tpl->setVariable(
401 'WEEK',
402 $date->get(IL_CAL_FKT_DATE, 'W')
403 );
404 $a_tpl->parseCurrentBlock();
405 }
406
407 $a_tpl->setCurrentBlock('month_row');
408 $a_tpl->parseCurrentBlock();
409
410 $week_has_events = false;
411 }
412 }
413 $a_tpl->setCurrentBlock('mini_month');
414 if ($a_include_view_ctrl) {
415 $a_tpl->setVariable("VIEW_CTRL_SECTION", $ui->renderer()->render($this->getViewControl()));
416 }
417
418 $a_tpl->parseCurrentBlock();
419 }
420
421 protected function getViewControl(): Section
422 {
423 $ui = $this->ui;
425
426 $first_of_month = substr($this->seed->get(IL_CAL_DATE), 0, 7) . "-01";
427 $myseed = new ilDate($first_of_month, IL_CAL_DATE);
428
429 $myseed->increment(ilDateTime::MONTH, -1);
430 $this->ctrl->setParameter($this, 'seed', $myseed->get(IL_CAL_DATE));
431
432 $prev_link = $this->ctrl->getLinkTarget($this, "setSeed", "", true);
433
434 $myseed->increment(ilDateTime::MONTH, 2);
435 $this->ctrl->setParameter($this, 'seed', $myseed->get(IL_CAL_DATE));
436 $next_link = $this->ctrl->getLinkTarget($this, "setSeed", "", true);
437
438 $this->ctrl->setParameter($this, 'seed', "");
439
440 $blockgui = $this;
441
442 // view control
443 // ... previous button
444 $b1 = $ui->factory()->button()->standard($this->lng->txt("previous"), "#")->withOnLoadCode(function ($id) use (
445 $prev_link,
446 $blockgui
447 ) {
448 return
449 "$('#" . $id . "').click(function() { ilBlockJSHandler('block_" . $blockgui->getBlockType() .
450 "_" . $blockgui->getBlockId() . "','" . $prev_link . "'); return false;});";
451 });
452
453 // ... month button
454 $this->ctrl->clearParameterByClass("ilcalendarblockgui", 'seed');
455 $month_link = $this->ctrl->getLinkTarget($this, "setSeed", "", true, false);
456 $seed_parts = explode("-", $this->seed->get(IL_CAL_DATE));
457 $b2 = $ui->factory()->button()->month($seed_parts[1] . "-" . $seed_parts[0])->withOnLoadCode(function ($id) use (
458 $month_link,
459 $blockgui
460 ) {
461 return "$('#" . $id . "').on('il.ui.button.month.changed', function(el, id, month) { var m = month.split('-'); ilBlockJSHandler('block_" . $blockgui->getBlockType() .
462 "_" . $blockgui->getBlockId() . "','" . $month_link . "' + '&seed=' + m[1] + '-' + m[0] + '-01'); return false;});";
463 });
464 // ... next button
465 $b3 = $ui->factory()->button()->standard($this->lng->txt("next"), "#")->withOnLoadCode(function ($id) use (
466 $next_link,
467 $blockgui
468 ) {
469 return
470 "$('#" . $id . "').click(function() { ilBlockJSHandler('block_" . $blockgui->getBlockType() .
471 "_" . $blockgui->getBlockId() . "','" . $next_link . "'); return false;});";
472 });
473
474 return $ui->factory()->viewControl()->section($b1, $b2, $b3);
475 }
476
480 public function getHTML(): string
481 {
482 $this->initCategories();
484 $ilObjDataCache = $this->obj_data_cache;
486
487 if ($this->mode == ilCalendarCategories::MODE_REPOSITORY) {
488 $bkid = $this->initBookingUserFromQuery();
489 if (!$bkid) {
490 $obj_id = $ilObjDataCache->lookupObjId((int) $this->requested_ref_id);
491 $participants = ilCourseParticipants::_getInstanceByObjId($obj_id);
492 $users = array_unique(array_merge($participants->getTutors(), $participants->getAdmins()));
493 //$users = $participants->getParticipants();
494 $users = ilBookingEntry::lookupBookableUsersForObject([$obj_id], $users);
495 foreach ($users as $user_id) {
496 $now = new ilDateTime(time(), IL_CAL_UNIX);
497
498 // default to last booking entry
500 $next_app = end($appointments);
501 reset($appointments);
502
503 foreach ($appointments as $entry) {
504 // find next entry
505 if (ilDateTime::_before($entry->getStart(), $now, IL_CAL_DAY)) {
506 continue;
507 }
508 $booking_entry = new ilBookingEntry($entry->getContextId());
509 if (!in_array($obj_id, $booking_entry->getTargetObjIds())) {
510 continue;
511 }
512
513 if (!$booking_entry->isAppointmentBookableForUser($entry->getEntryId(), $user->getId())) {
514 continue;
515 }
516 $next_app = $entry;
517 break;
518 }
519
520 $path = $this->getTargetGUIClassPath();
521 $this->ctrl->setParameterByClass(end($path), "ch_user_id", $user_id);
522
523 if (!$this->getForceMonthView()) {
524 $this->cal_footer[] = array(
525 'link' => $this->ctrl->getLinkTargetByClass(
526 $this->getTargetGUIClassPath(),
527 'selectCHCalendarOfUser'
528 ),
529 'txt' => str_replace(
530 "%1",
532 $this->lng->txt("cal_consultation_hours_for_user")
533 )
534 );
535 }
536 $path = $this->getTargetGUIClassPath();
537 $last_gui = end($path);
538 $this->ctrl->setParameterByClass($last_gui, "ch_user_id", "");
539 $this->ctrl->setParameterByClass($last_gui, "bkid", $bkid);
540 $this->ctrl->setParameterByClass($last_gui, "seed", $this->seed->get(IL_CAL_DATE));
541 }
542 $this->ctrl->setParameter($this, "bkid", "");
543 $this->ctrl->setParameter($this, 'seed', '');
544 } else {
545 $this->ctrl->setParameter($this, "bkid", "");
546 $this->addBlockCommand(
547 $this->ctrl->getLinkTarget($this),
548 $this->lng->txt("back")
549 );
550 $this->ctrl->setParameter($this, "bkid", $this->initBookingUserFromQuery());
551 }
552 }
553
554 if ($this->getProperty("settings")) {
555 $this->addBlockCommand(
556 $this->ctrl->getLinkTarget($this, "editSettings"),
557 $this->lng->txt("settings")
558 );
559 }
560
561 $this->ctrl->setParameterByClass($this->getParentGUI(), "seed", $this->seed->get(IL_CAL_DATE));
562 $ret = parent::getHTML();
563 $this->ctrl->setParameterByClass($this->getParentGUI(), "seed", "");
564
565 // workaround to include asynch code from ui only one time, see #20853
566 if ($this->ctrl->isAsynch()) {
567 $f = $this->ui->factory()->legacy()->content("");
568 $ret .= $this->ui->renderer()->renderAsync($f);
569 }
570 if (count($this->modals) > 0) {
571 if ($this->ctrl->isAsynch()) {
572 $ret .= $this->ui->renderer()->renderAsync($this->modals);
573 } else {
574 $ret .= $this->ui->renderer()->render($this->modals);
575 }
576 }
577 return $ret;
578 }
579
580 public function getOverview(): string
581 {
583
584 $schedule = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_INBOX);
585 $events = $schedule->getChangedEvents(true);
586
587 $this->ctrl->setParameterByClass('ilcalendarinboxgui', 'changed', 1);
588 $link = '<a href=' . $this->ctrl->getLinkTargetByClass('ilcalendarinboxgui', '') . '>';
589 $this->ctrl->setParameterByClass('ilcalendarinboxgui', 'changed', '');
590 $text = '<div class="small">' . (count($events)) . " " . $this->lng->txt("cal_changed_events_header") . "</div>";
591 $end_link = '</a>';
592
593 return $link . $text . $end_link;
594 }
595
596 protected function initCategories(): void
597 {
600 if ($this->getForceMonthView()) {
601 // old comment: in full container calendar presentation (allows selection of other calendars)
602 } elseif (!$cats->getMode()) {
603 $cats->initialize(
605 (int) $this->requested_ref_id,
606 true
607 );
608 }
609 }
610
611 protected function setSubTabs(): void
612 {
613 $this->tabs->clearSubTabs();
614 }
615
616 public function setSeed(): void
617 {
619 "il_cal_block_" . $this->getBlockType() . "_" . $this->getBlockId() . "_seed",
620 $this->initSeedFromQuery()
621 );
622 if ($this->ctrl->isAsynch()) {
623 echo $this->getHTML();
624 exit;
625 } else {
626 $this->returnToUpperContext();
627 }
628 }
629
630 public function returnToUpperContext(): void
631 {
632 $this->ctrl->returnToParent($this);
633 }
634
635 protected function initCommands(): void
636 {
638
639 if (!$this->getForceMonthView()) {
640 // @todo: set checked on ($this->display_mode != 'mmon')
641 $this->addBlockCommand(
642 $this->ctrl->getLinkTarget($this, "setPdModeEvents"),
643 $this->lng->txt("cal_upcoming_events_header"),
644 ""
645 // see #35777 $this->ctrl->getLinkTarget($this, "setPdModeEvents", "", true)
646 );
647
648 // @todo: set checked on ($this->display_mode == 'mmon')
649 $this->addBlockCommand(
650 $this->ctrl->getLinkTarget($this, "setPdModeMonth"),
651 $this->lng->txt("app_month"),
652 $this->ctrl->getLinkTarget($this, "setPdModeMonth", "", true)
653 );
654
655 if ($this->getRepositoryMode()) {
656 #23921
657 $this->ctrl->setParameterByClass('ilcalendarpresentationgui', 'seed', '');
658 $this->addBlockCommand(
659 $this->ctrl->getLinkTargetByClass($this->getTargetGUIClassPath(), ""),
660 $this->lng->txt("cal_open_calendar")
661 );
662
663 if ($this->access->checkAccess('edit_event', '', (int) $this->requested_ref_id)) {
664 $this->ctrl->setParameter($this, "add_mode", "");
665 $this->addBlockCommand(
666 $this->ctrl->getLinkTargetByClass("ilCalendarAppointmentGUI", "add"),
667 $this->lng->txt("add_appointment")
668 );
669 $this->ctrl->setParameter($this, "add_mode", "");
670 }
671 }
672 }
673 }
674
675 public function setPdModeEvents(): void
676 {
677 $ilUser = $this->user;
678
679 $this->user->writePref("il_pd_cal_mode", "evt");
680 $this->display_mode = "evt";
681 $this->setPresentation(self::PRES_SEC_LIST);
682 if ($this->ctrl->isAsynch()) {
683 echo $this->getHTML();
684 exit;
685 } else {
686 $this->ctrl->returnToParent($this);
687 }
688 }
689
690 public function setPdModeMonth(): void
691 {
692 $ilUser = $this->user;
693
694 $this->user->writePref("il_pd_cal_mode", "mmon");
695 $this->display_mode = "mmon";
696 $this->setPresentation(self::PRES_SEC_LEG);
697 if ($this->ctrl->isAsynch()) {
698 echo $this->getHTML();
699 exit;
700 } else {
701 $this->ctrl->redirectByClass("ildashboardgui", "show");
702 }
703 }
704
705 public function getEventByAppointmentId(int $a_appointment_id): ?array
706 {
707 foreach ($this->getEvents() as $event) {
708 if (
709 array_key_exists('event', $event) &&
710 $event['event'] instanceof ilCalendarEntry &&
711 $event['event']->getEntryId() === $a_appointment_id
712 ) {
713 return $event;
714 }
715 }
716 return null;
717 }
718
719 public function getEvents(): array
720 {
721 $seed = new ilDate(date('Y-m-d', time()), IL_CAL_DATE);
722
724 $schedule->addSubitemCalendars(true); // #12007
725 $schedule->setEventsLimit(20);
726 $schedule->calculate();
727 // #13809
728 return $schedule->getScheduledEvents();
729 }
730
731 public function getData(): array
732 {
734 $ui = $this->ui;
735
736 $f = $ui->factory();
737
738 $events = $this->getEvents();
739
740 $data = array();
741 if (sizeof($events)) {
742 foreach ($events as $item) {
743 $this->ctrl->setParameter($this, "app_id", $item["event"]->getEntryId());
744 $this->ctrl->setParameter($this, 'dt', $item['dstart']);
745 $url = $this->ctrl->getLinkTarget($this, "getModalForApp", "", true, false);
746 $this->ctrl->setParameter($this, "app_id", $this->initAppointmentIdFromQuery());
747 $this->ctrl->setParameter($this, "dt", $this->initInitialDateQuery());
748 $modal = $f->modal()->roundtrip('', [])->withAsyncRenderUrl($url);
749
750 $dates = $this->getDatesForItem($item);
751
752 $shy = $f->button()->shy(
753 $item["event"]->getPresentationTitle(),
754 ""
755 )->withOnClick($modal->getShowSignal());
756
757 $data[] = array(
758 "date" => ilDatePresentation::formatPeriod($dates["start"], $dates["end"]),
759 "title" => $item["event"]->getPresentationTitle(),
760 "url" => "#",
761 "shy_button" => $shy,
762 "modal" => $modal
763 );
764 }
765 $this->setEnableNumInfo(true);
766 } else {
767 $data = [];
768 /*$data[] = array(
769 "date" => $lng->txt("msg_no_search_result"),
770 "title" => "",
771 "url" => ""
772 ); */
773
774 $this->setEnableNumInfo(false);
775 }
776
777 return $data;
778 }
779
785 public function getDatesForItem(array $item): array
786 {
787 $start = $item["dstart"];
788 $end = $item["dend"];
789 if ($item["fullday"]) {
790 $start = new ilDate($start, IL_CAL_UNIX);
791 $end = new ilDate($end, IL_CAL_UNIX);
792 } else {
793 $start = new ilDateTime($start, IL_CAL_UNIX);
794 $end = new ilDateTime($end, IL_CAL_UNIX);
795 }
796 return array("start" => $start, "end" => $end);
797 }
798
803 public function getModalForApp()
804 {
805 $this->initCategories();
806 $ui = $this->ui;
807
808 $f = $ui->factory();
809 $r = $ui->renderer();
810
811 // @todo: this needs optimization
812 $events = $this->getEvents();
813 foreach ($events as $item) {
814 if ($item["event"]->getEntryId() == $this->initAppointmentIdFromQuery() && $item['dstart'] == $this->initInitialDateQuery()) {
815 $dates = $this->getDatesForItem($item);
816
817 // content of modal
818 $next_gui = ilCalendarAppointmentPresentationGUI::_getInstance($this->seed, $item);
819 $content = $this->ctrl->getHTML($next_gui);
820
821 $modal = $f->modal()->roundtrip(
822 ilDatePresentation::formatPeriod($dates["start"], $dates["end"]),
823 $f->legacy()->content($content)
824 );
825 echo $r->renderAsync($modal);
826 }
827 }
828 exit();
829 }
830
831 public function getViewControlsForPanel(): array
832 {
833 if ($this->getPresentation() == self::PRES_SEC_LEG) {
834 return [$this->getViewControl()];
835 }
836 return parent::getViewControlsForPanel();
837 }
838
842 protected function getLegacyContent(): string
843 {
844 $tpl = new ilTemplate(
845 "tpl.calendar_block.html",
846 true,
847 true,
848 "components/ILIAS/Calendar"
849 );
850
851 $this->addMiniMonth($tpl);
852
853 $panel_tpl = new \ilTemplate(
854 'tpl.cal_block_panel.html',
855 true,
856 true,
857 'components/ILIAS/Calendar'
858 );
859
860 $this->addSubscriptionButton($panel_tpl);
861
862 return $tpl->get() . $panel_tpl->get();
863 }
864
868 protected function getListItemForData(array $data): ?\ILIAS\UI\Component\Item\Item
869 {
870 $factory = $this->ui->factory();
871 if (isset($data["modal"])) {
872 $this->modals[] = $data["modal"];
873 }
874 if (isset($data["shy_button"])) {
875 return $factory->item()->standard($data["shy_button"])->withDescription($data["date"]);
876 } else {
877 return $factory->item()->standard($data["date"]);
878 }
879 }
880
885 public function getNoItemFoundContent(): string
886 {
887 return $this->lng->txt("cal_no_events_block");
888 }
889
893 protected function addSubscriptionButton(ilTemplate $panel_template): void
894 {
895 global $DIC;
896
897 $ui_factory = $DIC->ui()->factory();
898 $ui_renderer = $DIC->ui()->renderer();
899
900 $gui_path = $this->getTargetGUIClassPath();
901 $gui_path[] = strtolower(\ilCalendarSubscriptionGUI::class);
902 $url = $this->ctrl->getLinkTargetByClass($gui_path, 'getModalForSubscription', "", true, false);
903
904 $roundtrip_modal = $ui_factory->modal()->roundtrip('', [])->withAsyncRenderUrl($url);
905
906 $standard_button = $ui_factory->button()->standard($this->lng->txt('btn_ical'), '')->withOnClick(
907 $roundtrip_modal->getShowSignal()
908 );
909 $components = [
910 $roundtrip_modal,
911 $standard_button
912 ];
913
914 $presentation = $ui_renderer->render($components);
915
916 $panel_template->setCurrentBlock('subscription_buttons');
917 $panel_template->setVariable('SUBSCRIPTION_BUTTON', $presentation);
918 $panel_template->parseCurrentBlock();
919 }
920}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$components
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
const IL_SCREEN_CENTER
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_MONTH
const IL_CAL_FKT_DATE
const IL_CAL_DAY
This class represents a block method of a block.
ilLanguage $lng
Factory $factory
setTitle(string $a_title)
setPresentation(int $type)
ilTemplate $tpl
getProperty(string $a_property)
addBlockCommand(string $a_href, string $a_text, string $a_onclick="", ?RoundTrip $modal=null)
ilObjUser $user
setBlockId(string $a_block_id="0")
setLimit(int $a_limit)
ILIAS DI UIServices $ui
setEnableNumInfo(bool $a_enablenuminfo)
Booking definition.
static lookupBookableUsersForObject(array $a_obj_id, array $a_user_ids)
Consultation hours are offered if 1) consultation hour owner is admin or tutor and no object assignme...
Administrate calendar appointments.
static _getInstance(ilDate $seed, array $a_app)
get singleton instance
Calendar blocks, displayed in different contexts, e.g.
ilCalendarSettings $settings
ilObjectDataCache $obj_data_cache
addMiniMonth(ilTemplate $a_tpl, bool $a_include_view_ctrl=false)
Add mini version of monthly overview (Maybe extracted to another class, if used in pd calendar tab.
getNoItemFoundContent()
No item entry.
isRepositoryObject()
Returns whether block has a corresponding repository object.
getEventByAppointmentId(int $a_appointment_id)
addSubscriptionButton(ilTemplate $panel_template)
Add subscription button.
getModalForApp()
Get modal for appointment (see similar code in ilCalendarAgendaListGUI) todo use all this methods fro...
getShowWeeksColumn()
Show weeks column.
getListItemForData(array $data)
Get list item for data array.null|\ILIAS\UI\Component\Item\Item
getHTML()
Get bloch HTML code.
getDatesForItem(array $item)
Get start/end date for item.
ilCalendarUserSettings $user_settings
static getScreenMode()
Get Screen Mode for current command.
ilCalendarSchedule $scheduler
getLegacyContent()
Get legacy content.string
static _getInstance($a_usr_id=0)
get singleton instance
Model for a calendar entry.
Represents a list of calendar appointments (including recurring events) for a specific user in a give...
Stores all calendar relevant settings.
static _getInstanceByUserId(int $a_user_id)
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)
static getAppointments(int $a_user_id)
Get all appointments.
Consultation hours editor.
static _getInstanceByObjId(int $a_obj_id)
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.
@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.
Help GUI class.
Component logger with individual log levels by component id.
static _lookupFullname(int $a_user_id)
class ilObjectDataCache
static _lookupType(int $id, bool $reference=false)
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
static has($a_var)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
get(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
Returns a block with all replacements done.
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
exit
This describes a Section Control.
Definition: Section.php:30
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
$path
Definition: ltiservices.php:30
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68
$counter