ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCalendarBlockGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("Services/Block/classes/class.ilBlockGUI.php");
6include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
7
21{
25 public $ctrl = null;
26 protected $mode;
27 protected $display_mode;
28
29 public static $block_type = "cal";
30 public static $st_data;
31
35 protected $tabs;
36
40 protected $obj_data_cache;
41
42 protected $parent_gui = "ilcolumngui";
43
47 protected $ui;
48
49 protected $force_month_view = false;
50
55 public function __construct()
56 {
57 global $DIC;
58
60
61 $this->tabs = $DIC->tabs();
62 $this->obj_data_cache = $DIC["ilObjDataCache"];
63 $this->ui = $DIC->ui();
64
66 $ilCtrl = $this->ctrl;
69 $ilHelp = $DIC["ilHelp"];
70
71 $lng->loadLanguageModule("dateplaner");
72 $ilHelp->addHelpSection("cal_block");
73
74 include_once("./Services/News/classes/class.ilNewsItem.php");
75
76 $ilCtrl->saveParameter($this, 'bkid');
77
78 $this->setBlockId($ilCtrl->getContextObjId());
79
80 $this->setLimit(5); // @todo: needed?
81
82 $this->setEnableNumInfo(false);
83
84 $title = $lng->txt("calendar");
85
86 $this->setTitle($title);
87 $this->allow_moving = false;
88
89 include_once('Services/Calendar/classes/class.ilDate.php');
90 include_once('Services/Calendar/classes/class.ilCalendarUserSettings.php');
91
92 $seed_str = "";
93 if ((!isset($_GET["seed"]) || $_GET["seed"] == "") &&
94 isset($_SESSION["il_cal_block_" . $this->getBlockType() . "_" . $this->getBlockId() . "_seed"])) {
95 $seed_str = $_SESSION["il_cal_block_" . $this->getBlockType() . "_" . $this->getBlockId() . "_seed"];
96 } elseif (isset($_GET["seed"])) {
97 $seed_str = $_GET["seed"];
98 }
99
100 if (isset($_GET["seed"]) && $_GET["seed"] != "") {
101 $_SESSION["il_cal_block_" . $this->getBlockType() . "_" . $this->getBlockId() . "_seed"]
102 = $_GET["seed"];
103 }
104
105 if ($seed_str == "") {
106 $now = new \ilDate(time(), IL_CAL_UNIX);
107 $this->seed = new \ilDate($now->get(IL_CAL_DATE), IL_CAL_DATE);
108 } else {
109 $this->seed = new ilDate($seed_str, IL_CAL_DATE); // @todo: check this
110 }
111
113 $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
114
115 $mode = $ilUser->getPref("il_pd_cal_mode");
116 $this->display_mode = $mode ? $mode : "mmon";
117
118 if ($this->display_mode !== "mmon") {
119 $this->setPresentation(self::PRES_SEC_LIST);
120 }
121 }
122
128 public function getShowWeeksColumn()
129 {
130 return ($this->settings->getShowWeeks() && $this->user_settings->getShowWeeks());
131 }
132
136 public function getBlockType() : string
137 {
138 return self::$block_type;
139 }
140
144 protected function isRepositoryObject() : bool
145 {
146 return false;
147 }
148
153 public function setParentGUI($a_val)
154 {
155 $this->parent_gui = $a_val;
156 }
157
162 public function getParentGUI()
163 {
164 return $this->parent_gui;
165 }
166
171 public function setForceMonthView($a_val)
172 {
173 $this->force_month_view = $a_val;
174 if ($a_val) {
175 $this->display_mode = "mmon";
176 $this->setPresentation(self::PRES_SEC_LEG);
177 }
178 }
179
184 public function getForceMonthView()
185 {
187 }
188
192 public static function getScreenMode()
193 {
194 global $DIC;
195
196 $ilCtrl = $DIC->ctrl();
197
198 $cmd_class = $ilCtrl->getCmdClass();
199
200 if ($cmd_class == "ilcalendarappointmentgui" ||
201 $cmd_class == "ilconsultationhoursgui" ||
202 $_GET['cmd'] == 'showCalendarSubscription') {
203 return IL_SCREEN_CENTER;
204 }
205
206 switch ($ilCtrl->getCmd()) {
207 case "kkk":
208 // return IL_SCREEN_CENTER;
209 // return IL_SCREEN_FULL;
210
211 default:
212 //return IL_SCREEN_SIDE;
213 break;
214 }
215 }
216
220 public function executeCommand()
221 {
222 $ilCtrl = $this->ctrl;
223 $ilTabs = $this->tabs;
224
225 $next_class = $ilCtrl->getNextClass();
226 $cmd = $ilCtrl->getCmd("getHTML");
227
228 $this->setSubTabs();
229
230 switch ($next_class) {
231 case "ilcalendarappointmentgui":
232 include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
233 $app_gui = new ilCalendarAppointmentGUI($this->seed, $this->seed);
234 $ilCtrl->forwardCommand($app_gui);
235 break;
236
237 case "ilconsultationhoursgui":
238 include_once('./Services/Calendar/classes/ConsultationHours/class.ilConsultationHoursGUI.php');
239 $hours = new ilConsultationHoursGUI($this->seed);
240 $ilCtrl->forwardCommand($hours);
241 break;
242
243 case "ilcalendarappointmentpresentationgui":
244 $this->initCategories();
245 $presentation = ilCalendarAppointmentPresentationGUI::_getInstance($this->seed, $this->appointment);
246 $ilCtrl->forwardCommand($presentation);
247 break;
248
249 case "ilcalendarmonthgui":
250 $ilTabs->setSubTabActive('app_month');
251 include_once('./Services/Calendar/classes/class.ilCalendarMonthGUI.php');
252 $month_gui = new ilCalendarMonthGUI($this->seed);
253 $ilCtrl->forwardCommand($month_gui);
254 break;
255
256 default:
257 return $this->$cmd();
258 }
259 }
260
265 public function setEnableEdit($a_enable_edit = 0)
266 {
267 $this->enable_edit = $a_enable_edit;
268 }
269
274 public function getEnableEdit()
275 {
276 return $this->enable_edit;
277 }
278
282 public function fillDataSection()
283 {
284 if ($this->display_mode != "mmon") {
285 $this->setRowTemplate("tpl.pd_event_list.html", "Services/Calendar");
286
288 } else {
289 $tpl = new ilTemplate(
290 "tpl.calendar_block.html",
291 true,
292 true,
293 "Services/Calendar"
294 );
295
296 $this->addMiniMonth($tpl, true);
297 $this->setDataSection($tpl->get());
298 }
299 }
300
306 public function getTargetGUIClassPath()
307 {
308 $target_class = array();
309 if (!$this->getRepositoryMode()) {
310 $target_class = array("ildashboardgui", "ilcalendarpresentationgui");
311 } else {
312 switch (ilObject::_lookupType((int) $_GET["ref_id"], true)) {
313 case "crs":
314 $target_class = array("ilobjcoursegui", "ilcalendarpresentationgui");
315 break;
316
317 case "grp":
318 $target_class = array("ilobjgroupgui", "ilcalendarpresentationgui");
319 break;
320 }
321 }
322 return $target_class;
323 }
324
329 public function addMiniMonth($a_tpl, $a_include_view_ctrl = false)
330 {
332 $ilCtrl = $this->ctrl;
334 $ui = $this->ui;
335
336 // weekdays
337 include_once('Services/Calendar/classes/class.ilCalendarUtil.php');
338 if ($this->getShowWeeksColumn()) {
339 $a_tpl->setCurrentBlock('month_header_col');
340 $a_tpl->setVariable('TXT_WEEKDAY', $lng->txt("cal_week_abbrev"));
341 $a_tpl->parseCurrentBlock();
342 }
343 for ($i = (int) $this->user_settings->getWeekStart(); $i < (7 + (int) $this->user_settings->getWeekStart()); $i++) {
344 $a_tpl->setCurrentBlock('month_header_col');
345 $a_tpl->setVariable('TXT_WEEKDAY', ilCalendarUtil::_numericDayToString($i, false));
346 $a_tpl->parseCurrentBlock();
347 }
348
349 if (isset($_GET["bkid"])) {
350 $user_id = $_GET["bkid"];
351 $disable_empty = true;
352 } else {
353 $user_id = $ilUser->getId();
354 $disable_empty = false;
355 }
356 include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
357 $this->scheduler = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_MONTH, $user_id);
358 $this->scheduler->addSubitemCalendars(true);
359 $this->scheduler->calculate();
360
361 $counter = 0;
363 $this->seed->get(IL_CAL_FKT_DATE, 'm'),
364 $this->seed->get(IL_CAL_FKT_DATE, 'Y'),
365 $this->user_settings->getWeekStart()
366 )->get() as $date) {
367 $counter++;
368
369 $events = $this->scheduler->getByDay($date, $ilUser->getTimeZone());
370 $has_events = (bool) count($events);
371 if ($has_events || !$disable_empty) {
372 $a_tpl->setCurrentBlock('month_col_link');
373 } else {
374 $a_tpl->setCurrentBlock('month_col_no_link');
375 }
376
377 if ($disable_empty) {
378 if (!$has_events) {
379 $a_tpl->setVariable('DAY_CLASS', 'calminiinactive');
380 } else {
381 $week_has_events = true;
382 include_once 'Services/Booking/classes/class.ilBookingEntry.php';
383 foreach ($events as $event) {
384 $booking = new ilBookingEntry($event['event']->getContextId());
385 if ($booking->hasBooked($event['event']->getEntryId())) {
386 $a_tpl->setVariable('DAY_CLASS', 'calminiapp');
387 break;
388 }
389 }
390 }
391 } elseif ($has_events) {
392 $week_has_events = true;
393 $a_tpl->setVariable('DAY_CLASS', 'calminiapp');
394 }
395
396 $day = $date->get(IL_CAL_FKT_DATE, 'j');
397 $month = $date->get(IL_CAL_FKT_DATE, 'n');
398
399 $month_day = $day;
400
401 $ilCtrl->setParameterByClass(end($this->getTargetGUIClassPath()), 'seed', $date->get(IL_CAL_DATE));
402 if ($agenda_view_type = (int) $_GET['cal_agenda_per']) {
403 $ilCtrl->setParameterByClass(end($this->getTargetGUIClassPath()), "cal_agenda_per", $agenda_view_type);
404 }
405 $a_tpl->setVariable('OPEN_DAY_VIEW', $ilCtrl->getLinkTargetByClass($this->getTargetGUIClassPath(), ''));
406
407 $a_tpl->setVariable('MONTH_DAY', $month_day);
408
409 $a_tpl->parseCurrentBlock();
410
411 $a_tpl->setCurrentBlock('month_col');
412
413 include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
414 if (ilCalendarUtil::_isToday($date)) {
415 $a_tpl->setVariable('TD_CLASS', 'calminitoday');
416 }
417 #elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
418 #{
419 # $a_tpl->setVariable('TD_CLASS','calmininow');
420 #}
421 elseif (ilDateTime::_equals($date, $this->seed, IL_CAL_MONTH)) {
422 $a_tpl->setVariable('TD_CLASS', 'calministd');
423 } elseif (ilDateTime::_before($date, $this->seed, IL_CAL_MONTH)) {
424 $a_tpl->setVariable('TD_CLASS', 'calminiprev');
425 } else {
426 $a_tpl->setVariable('TD_CLASS', 'calmininext');
427 }
428
429 $a_tpl->parseCurrentBlock();
430
431 if ($counter and !($counter % 7)) {
432 if ($this->getShowWeeksColumn()) {
433 $a_tpl->setCurrentBlock('week');
434 $a_tpl->setVariable(
435 'WEEK',
436 $date->get(IL_CAL_FKT_DATE, 'W')
437 );
438 $a_tpl->parseCurrentBlock();
439 }
440
441 $a_tpl->setCurrentBlock('month_row');
442 //$a_tpl->setVariable('TD_CLASS','calminiweek');
443 $a_tpl->parseCurrentBlock();
444
445 $week_has_events = false;
446 }
447 }
448 $a_tpl->setCurrentBlock('mini_month');
449 //$a_tpl->setVariable('TXT_MONTH_OVERVIEW', $lng->txt("cal_month_overview"));
450
451 if ($a_include_view_ctrl) {
452 $a_tpl->setVariable("VIEW_CTRL_SECTION", $ui->renderer()->render($this->getViewControl()));
453 }
454
455 $a_tpl->parseCurrentBlock();
456 }
457
462 protected function getViewControl() : \ILIAS\UI\Component\ViewControl\Section
463 {
464 $ui = $this->ui;
466 $ilCtrl = $this->ctrl;
467
468 $first_of_month = substr($this->seed->get(IL_CAL_DATE), 0, 7) . "-01";
469 $myseed = new ilDate($first_of_month, IL_CAL_DATE);
470
471 $myseed->increment(ilDateTime::MONTH, -1);
472 $ilCtrl->setParameter($this, 'seed', $myseed->get(IL_CAL_DATE));
473
474 $prev_link = $ilCtrl->getLinkTarget($this, "setSeed", "", true);
475
476 $myseed->increment(ilDateTime::MONTH, 2);
477 $ilCtrl->setParameter($this, 'seed', $myseed->get(IL_CAL_DATE));
478 $next_link = $ilCtrl->getLinkTarget($this, "setSeed", "", true);
479
480 $ilCtrl->setParameter($this, 'seed', "");
481
482 $blockgui = $this;
483
484 // view control
485 // ... previous button
486 $b1 = $ui->factory()->button()->standard($lng->txt("previous"), "#")->withOnLoadCode(function ($id) use ($prev_link, $blockgui) {
487 return
488 "$('#" . $id . "').click(function() { ilBlockJSHandler('block_" . $blockgui->getBlockType() .
489 "_" . $blockgui->getBlockId() . "','" . $prev_link . "'); return false;});";
490 });
491
492 // ... month button
493 $ilCtrl->clearParameterByClass("ilcalendarblockgui", 'seed');
494 $month_link = $ilCtrl->getLinkTarget($this, "setSeed", "", true, false);
495 $seed_parts = explode("-", $this->seed->get(IL_CAL_DATE));
496 $b2 = $ui->factory()->button()->month($seed_parts[1] . "-" . $seed_parts[0])->withOnLoadCode(function ($id) use ($month_link, $blockgui) {
497 return "$('#" . $id . "').on('il.ui.button.month.changed', function(el, id, month) { var m = month.split('-'); ilBlockJSHandler('block_" . $blockgui->getBlockType() .
498 "_" . $blockgui->getBlockId() . "','" . $month_link . "' + '&seed=' + m[1] + '-' + m[0] + '-01'); return false;});";
499 });
500 // ... next button
501 $b3 = $ui->factory()->button()->standard($lng->txt("next"), "#")->withOnLoadCode(function ($id) use ($next_link, $blockgui) {
502 return
503 "$('#" . $id . "').click(function() { ilBlockJSHandler('block_" . $blockgui->getBlockType() .
504 "_" . $blockgui->getBlockId() . "','" . $next_link . "'); return false;});";
505 });
506
507 return $ui->factory()->viewControl()->section($b1, $b2, $b3);
508 }
509
513 public function getHTML()
514 {
515 $this->initCategories();
517 $ilCtrl = $this->ctrl;
518 $ilObjDataCache = $this->obj_data_cache;
520
521 if ($this->mode == ilCalendarCategories::MODE_REPOSITORY) {
522 if (!isset($_GET["bkid"])) {
523 include_once "Modules/Course/classes/class.ilCourseParticipants.php";
524 $obj_id = $ilObjDataCache->lookupObjId((int) $_GET['ref_id']);
525 $participants = ilCourseParticipants::_getInstanceByObjId($obj_id);
526 $users = array_unique(array_merge($participants->getTutors(), $participants->getAdmins()));
527 //$users = $participants->getParticipants();
528 include_once 'Services/Booking/classes/class.ilBookingEntry.php';
529 $users = ilBookingEntry::lookupBookableUsersForObject($obj_id, $users);
530 foreach ($users as $user_id) {
531 if (!isset($_GET["bkid"])) {
532 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
533 $now = new ilDateTime(time(), IL_CAL_UNIX);
534
535 // default to last booking entry
536 $appointments = ilConsultationHourAppointments::getAppointments($user_id);
537 $next_app = end($appointments);
538 reset($appointments);
539
540 foreach ($appointments as $entry) {
541 // find next entry
542 if (ilDateTime::_before($entry->getStart(), $now, IL_CAL_DAY)) {
543 continue;
544 }
545 include_once 'Services/Booking/classes/class.ilBookingEntry.php';
546 $booking_entry = new ilBookingEntry($entry->getContextId());
547 if (!in_array($obj_id, $booking_entry->getTargetObjIds())) {
548 continue;
549 }
550
551 if (!$booking_entry->isAppointmentBookableForUser($entry->getEntryId(), $user->getId())) {
552 continue;
553 }
554 $next_app = $entry;
555 break;
556 }
557
558 /*
559 $ilCtrl->setParameter($this, "bkid", $user_id);
560 if($next_app)
561 {
562 $ilCtrl->setParameter(
563 $this,
564 'seed',
565 (string) $next_app->getStart()->get(IL_CAL_DATE)
566 );
567 }*/
568
569 //$ilCtrl->setParameterByClass(end($this->getTargetGUIClassPath()), "bkid", $user_id);
570
571 $ilCtrl->setParameterByClass(end($this->getTargetGUIClassPath()), "ch_user_id", $user_id);
572
573 if ($next_app) {
574 // this does not work correctly
575 /*$ilCtrl->setParameterByClass(
576 end($this->getTargetGUIClassPath()),
577 'seed',
578 (string) $next_app->getStart()->get(IL_CAL_DATE)
579 );*/
580 }
581
582 if (!$this->getForceMonthView()) {
583 $this->cal_footer[] = array(
584 'link' => $ilCtrl->getLinkTargetByClass($this->getTargetGUIClassPath(), 'selectCHCalendarOfUser'),
585 'txt' => str_replace("%1", ilObjUser::_lookupFullname($user_id), $lng->txt("cal_consultation_hours_for_user"))
586 );
587 }
588 $ilCtrl->setParameterByClass(end($this->getTargetGUIClassPath()), "ch_user_id", "");
589 $ilCtrl->setParameterByClass(end($this->getTargetGUIClassPath()), "bkid", $_GET["bkid"]);
590 $ilCtrl->setParameterByClass(end($this->getTargetGUIClassPath()), "seed", $_GET["seed"]);
591 }
592 }
593 $ilCtrl->setParameter($this, "bkid", "");
594 $ilCtrl->setParameter($this, 'seed', '');
595 } else {
596 $ilCtrl->setParameter($this, "bkid", "");
597 $this->addBlockCommand(
598 $ilCtrl->getLinkTarget($this),
599 $lng->txt("back")
600 );
601 $ilCtrl->setParameter($this, "bkid", (int) $_GET["bkid"]);
602 }
603 }
604
605 if ($this->getProperty("settings") == true) {
606 $this->addBlockCommand(
607 $ilCtrl->getLinkTarget($this, "editSettings"),
608 $lng->txt("settings")
609 );
610 }
611
612 $ilCtrl->setParameterByClass($this->getParentGUI(), "seed", isset($_GET["seed"]) ? $_GET["seed"] : "");
613 $ret = parent::getHTML();
614 $ilCtrl->setParameterByClass($this->getParentGUI(), "seed", "");
615
616 // workaround to include asynch code from ui only one time, see #20853
617 if ($ilCtrl->isAsynch()) {
618 global $DIC;
619 $f = $DIC->ui()->factory()->legacy("");
620 $ret .= $DIC->ui()->renderer()->renderAsync($f);
621 }
622
623 return $ret;
624 }
625
629 public function getOverview()
630 {
632 $ilCtrl = $this->ctrl;
633
634 include_once('./Services/Calendar/classes/class.ilCalendarSchedule.php');
635 $schedule = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_INBOX);
636 $events = $schedule->getChangedEvents(true);
637
638 $ilCtrl->setParameterByClass('ilcalendarinboxgui', 'changed', 1);
639 $link = '<a href=' . $ilCtrl->getLinkTargetByClass('ilcalendarinboxgui', '') . '>';
640 $ilCtrl->setParameterByClass('ilcalendarinboxgui', 'changed', '');
641 $text = '<div class="small">' . ((int) count($events)) . " " . $lng->txt("cal_changed_events_header") . "</div>";
642 $end_link = '</a>';
643
644 return $link . $text . $end_link;
645 }
646
653 protected function initCategories()
654 {
657 if ($this->getForceMonthView()) {
658 // old comment: in full container calendar presentation (allows selection of other calendars)
659 } elseif (!$cats->getMode()) {
660 $cats->initialize(
662 (int) $_GET['ref_id'],
663 true
664 );
665 }
666 }
667
672 protected function setSubTabs()
673 {
674 $ilTabs = $this->tabs;
675
676 $ilTabs->clearSubTabs();
677 }
678
682 public function setSeed()
683 {
684 $ilCtrl = $this->ctrl;
685
686 //$ilUser->writePref("il_pd_bkm_mode", 'flat');
687 $_SESSION["il_cal_block_" . $this->getBlockType() . "_" . $this->getBlockId() . "_seed"] =
688 $_GET["seed"];
689 if ($ilCtrl->isAsynch()) {
690 echo $this->getHTML();
691 exit;
692 } else {
693 $this->returnToUpperContext();
694 }
695 }
696
700 public function returnToUpperContext()
701 {
702 $ilCtrl = $this->ctrl;
703
704 $ilCtrl->returnToParent($this);
705 }
706
707 public function fillFooter()
708 {
709 // @todo: check this
710 return;
711
712 // begin-patch ch
713 foreach ((array) $this->cal_footer as $link_info) {
714 $this->tpl->setCurrentBlock('data_section');
715 $this->tpl->setVariable(
716 'DATA',
717 sprintf('<a href="%s">%s</a>', $link_info['link'], $link_info['txt'])
718 );
719 $this->tpl->parseCurrentBlock();
720 }
721 // end-patch ch
722
723 if ($this->tpl->blockExists("block_footer")) {
724 $this->tpl->setCurrentBlock("block_footer");
725 $this->tpl->parseCurrentBlock();
726 }
727 }
728
729 public function initCommands()
730 {
731 $ilCtrl = $this->ctrl;
733
734 if (!$this->getForceMonthView()) {
735 // @todo: set checked on ($this->display_mode != 'mmon')
736 $this->addBlockCommand(
737 $ilCtrl->getLinkTarget($this, "setPdModeEvents"),
738 $lng->txt("cal_upcoming_events_header"),
739 $ilCtrl->getLinkTarget($this, "setPdModeEvents", "", true)
740 );
741
742 // @todo: set checked on ($this->display_mode == 'mmon')
743 $this->addBlockCommand(
744 $ilCtrl->getLinkTarget($this, "setPdModeMonth"),
745 $lng->txt("app_month"),
746 $ilCtrl->getLinkTarget($this, "setPdModeMonth", "", true)
747 );
748
749 if ($this->getRepositoryMode()) {
750 #23921
751 $ilCtrl->setParameterByClass('ilcalendarpresentationgui', 'seed', '');
752 $this->addBlockCommand(
753 $ilCtrl->getLinkTargetByClass($this->getTargetGUIClassPath(), ""),
754 $lng->txt("cal_open_calendar")
755 );
756
757 if ($this->access->checkAccess('edit_event', '', (int) $_GET['ref_id'])) {
758 $ilCtrl->setParameter($this, "add_mode", "");
759 $this->addBlockCommand(
760 $ilCtrl->getLinkTargetByClass("ilCalendarAppointmentGUI", "add"),
761 $lng->txt("add_appointment")
762 );
763 $ilCtrl->setParameter($this, "add_mode", "");
764 }
765 }
766 }
767 }
768
769 public function setPdModeEvents()
770 {
771 $ilCtrl = $this->ctrl;
773
774 $ilUser->writePref("il_pd_cal_mode", "evt");
775 $this->display_mode = "evt";
776 $this->setPresentation(self::PRES_SEC_LIST);
777 if ($ilCtrl->isAsynch()) {
778 echo $this->getHTML();
779 exit;
780 } else {
781 $ilCtrl->redirectByClass("ildashboardgui", "show");
782 }
783 }
784
785 public function setPdModeMonth()
786 {
787 $ilCtrl = $this->ctrl;
789
790 $ilUser->writePref("il_pd_cal_mode", "mmon");
791 $this->display_mode = "mmon";
792 $this->setPresentation(self::PRES_SEC_LEG);
793 if ($ilCtrl->isAsynch()) {
794 echo $this->getHTML();
795 exit;
796 } else {
797 $ilCtrl->redirectByClass("ildashboardgui", "show");
798 }
799 }
800
806 public function getEvents()
807 {
808 $seed = new ilDate(date('Y-m-d', time()), IL_CAL_DATE);
809
810 include_once('./Services/Calendar/classes/class.ilCalendarSchedule.php');
812 $schedule->addSubitemCalendars(true); // #12007
813 $schedule->setEventsLimit(20);
814 $schedule->calculate();
815 $ev = $schedule->getScheduledEvents(); // #13809
816 return ($ev);
817 }
818
819 public function getData()
820 {
822 $ui = $this->ui;
823
824 $f = $ui->factory();
825
826 $events = $this->getEvents();
827
828 $data = array();
829 if (sizeof($events)) {
830 foreach ($events as $item) {
831 $this->ctrl->setParameter($this, "app_id", $item["event"]->getEntryId());
832 $this->ctrl->setParameter($this, 'dt', $item['dstart']);
833 $url = $this->ctrl->getLinkTarget($this, "getModalForApp", "", true, false);
834 $this->ctrl->setParameter($this, "app_id", $_GET["app_id"]);
835 $this->ctrl->setParameter($this, "dt", $_GET["dt"]);
836 $modal = $f->modal()->roundtrip('', [])->withAsyncRenderUrl($url);
837
838 $dates = $this->getDatesForItem($item);
839
840 $comps = [$f->button()->shy($item["event"]->getPresentationTitle(), "")->withOnClick($modal->getShowSignal()), $modal];
841 $renderer = $ui->renderer();
842 $shy = $renderer->render($comps);
843
844 $data[] = array(
845 "date" => ilDatePresentation::formatPeriod($dates["start"], $dates["end"]),
846 "title" => $item["event"]->getPresentationTitle(),
847 "url" => "#",
848 "shy_button" => $shy
849 );
850 }
851 $this->setEnableNumInfo(true);
852 } else {
853 $data = [];
854 /*$data[] = array(
855 "date" => $lng->txt("msg_no_search_result"),
856 "title" => "",
857 "url" => ""
858 ); */
859
860 $this->setEnableNumInfo(false);
861 }
862
863 return $data;
864 }
865
871 public function getDatesForItem($item)
872 {
873 $start = $item["dstart"];
874 $end = $item["dend"];
875 if ($item["fullday"]) {
876 $start = new ilDate($start, IL_CAL_UNIX);
877 $end = new ilDate($end, IL_CAL_UNIX);
878 } else {
879 $start = new ilDateTime($start, IL_CAL_UNIX);
880 $end = new ilDateTime($end, IL_CAL_UNIX);
881 }
882 return array("start" => $start, "end" => $end);
883 }
884
889 public function getModalForApp()
890 {
891 $this->initCategories();
892 $ui = $this->ui;
893 $ilCtrl = $this->ctrl;
894
895 $f = $ui->factory();
896 $r = $ui->renderer();
897
898 // @todo: this needs optimization
899 $events = $this->getEvents();
900 foreach ($events as $item) {
901 if ($item["event"]->getEntryId() == (int) $_GET["app_id"] && $item['dstart'] == (int) $_GET['dt']) {
902 $dates = $this->getDatesForItem($item);
903
904 // content of modal
905 include_once("./Services/Calendar/classes/class.ilCalendarAppointmentPresentationGUI.php");
906 $next_gui = ilCalendarAppointmentPresentationGUI::_getInstance($this->seed, $item);
907 $content = $ilCtrl->getHTML($next_gui);
908
909 $modal = $f->modal()->roundtrip(ilDatePresentation::formatPeriod($dates["start"], $dates["end"]), $f->legacy($content));
910 echo $r->renderAsync($modal);
911 }
912 }
913 exit();
914 }
915
916 //
917 // New rendering
918 //
919
920 protected $new_rendering = true;
921
925 protected function getViewControls() : array
926 {
927 if ($this->getPresentation() == self::PRES_SEC_LEG) {
928 return [$this->getViewControl()];
929 }
931 }
932
936 protected function getLegacyContent() : string
937 {
938 $tpl = new ilTemplate(
939 "tpl.calendar_block.html",
940 true,
941 true,
942 "Services/Calendar"
943 );
944
945 $this->addMiniMonth($tpl);
946
947 $panel_tpl = new \ilTemplate(
948 'tpl.cal_block_panel.html',
949 true,
950 true,
951 'Services/Calendar'
952 );
953
954 $this->addSubscriptionButton($panel_tpl);
955
956 return $tpl->get() . $panel_tpl->get();
957 }
958
962 protected function getListItemForData(array $data) : \ILIAS\UI\Component\Item\Item
963 {
964 $factory = $this->ui->factory();
965 if (isset($data["shy_button"])) {
966 return $factory->item()->standard($data["shy_button"])->withDescription($data["date"]);
967 } else {
968 return $factory->item()->standard($data["date"]);
969 }
970 }
971
976 protected function getNoItemFoundContent() : string
977 {
978 return $this->lng->txt("cal_no_events_block");
979 }
980
984 protected function addSubscriptionButton(ilTemplate $panel_template) : void
985 {
986 global $DIC;
987
988 $lng = $DIC->language();
989
990 $ui_factory = $DIC->ui()->factory();
991 $ui_renderer = $DIC->ui()->renderer();
992
993 $gui_path = $this->getTargetGUIClassPath();
994 $gui_path[] = strtolower(\ilCalendarSubscriptionGUI::class);
995 $url = $this->ctrl->getLinkTargetByClass($gui_path, 'getModalForSubscription', "", true, false);
996
997 $roundtrip_modal = $ui_factory->modal()->roundtrip('', [])->withAsyncRenderUrl($url);
998
999 $standard_button = $ui_factory->button()->standard($lng->txt('btn_ical'), '')->withOnClick(
1000 $roundtrip_modal->getShowSignal()
1001 );
1002 $components = [
1003 $roundtrip_modal,
1004 $standard_button
1005 ];
1006
1007 $presentation = $ui_renderer->render($components);
1008
1009 $panel_template->setCurrentBlock('subscription_buttons');
1010 $panel_template->setVariable('SUBSCRIPTION_BUTTON', $presentation);
1011 $panel_template->parseCurrentBlock();
1012 }
1013}
$_GET["client_id"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:615
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.
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
setLimit($a_limit)
Set Limit.
getBlockId()
Get Block Id.
getRepositoryMode()
Get RepositoryMode.
setPresentation(int $type)
Set presentation.
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
fillDataSection()
Standard implementation for row based data.
addBlockCommand(string $a_href, string $a_text, string $a_onclick="")
Add Block Command.
getProperty($a_property)
setTitle($a_title)
Set Title.
getPresentation()
Get presentation type.
setBlockId($a_block_id=0)
Set Block Id.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
Booking definition.
static lookupBookableUsersForObject($a_obj_id, $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, $a_app)
get singleton instance
Calendar blocks, displayed in different contexts, e.g.
setParentGUI($a_val)
Set parent gui.
setEnableEdit($a_enable_edit=0)
Set EnableEdit.
initCategories()
init categories @access protected
addMiniMonth($a_tpl, $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.bool
getDatesForItem($item)
Get start/end date for item.
addSubscriptionButton(ilTemplate $panel_template)
Add subscription button.
fillDataSection()
Fill data section.
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.
getViewControl()
Get view control.
static getScreenMode()
Get Screen Mode for current command.
returnToUpperContext()
Return to upper context.
getViewControls()
Get view controls.array
getLegacyContent()
Get legacy content.string
getTargetGUIClassPath()
Get target gui class path (for presenting the calendar)
getForceMonthView()
Get force month view.
setForceMonthView($a_val)
Set force month view.
static _getInstance($a_usr_id=0)
get singleton instance
Represents a list of calendar appointments (including recurring events) for a specific user in a give...
static _getInstance()
get singleton instance
static _getInstanceByUserId($a_user_id)
get singleton instance
static _isToday($date)
check if a date is today
static _numericDayToString($a_day, $a_long=true)
get
static _buildMonthDayList($a_month, $a_year, $weekstart)
Build a month day list.
static getAppointments($a_user_id)
Get all appointments.
Consultation hours editor.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
@classDescription Date and time handling
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Class for single dates.
static _lookupFullname($a_user_id)
Lookup Full Name.
static _lookupType($a_id, $a_reference=false)
lookup object type
special template class to simplify handling of ITX/PEAR
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt @access public.
setCurrentBlock($part="DEFAULT")
Überladene Funktion, die sich hier lokal noch den aktuellen Block merkt.
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
exit
Definition: login.php:29
$factory
Definition: metadata.php:58
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$ret
Definition: parser.php:6
$url
settings()
Definition: settings.php:2
ui()
Definition: ui.php:5