ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCalendarBlockGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
34 {
35  protected array $cal_footer = [];
36  protected ?ilCalendarSchedule $scheduler = null;
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 fillDataSection(): void
272  {
273  if ($this->display_mode != "mmon") {
274  $this->setRowTemplate("tpl.pd_event_list.html", "Services/Calendar");
275 
277  } else {
278  $tpl = new ilTemplate(
279  "tpl.calendar_block.html",
280  true,
281  true,
282  "Services/Calendar"
283  );
284 
285  $this->addMiniMonth($tpl, true);
286  $this->setDataSection($tpl->get());
287  }
288  }
289 
290  public function getTargetGUIClassPath(): array
291  {
292  $target_class = array();
293  if (!$this->getRepositoryMode()) {
294  $target_class = array("ildashboardgui", "ilcalendarpresentationgui");
295  } else {
296  switch (ilObject::_lookupType((int) $this->requested_ref_id, true)) {
297  case "crs":
298  $target_class = array("ilobjcoursegui", "ilcalendarpresentationgui");
299  break;
300 
301  case "grp":
302  $target_class = array("ilobjgroupgui", "ilcalendarpresentationgui");
303  break;
304  }
305  }
306  return $target_class;
307  }
308 
313  public function addMiniMonth(ilTemplate $a_tpl, bool $a_include_view_ctrl = false): void
314  {
315  $lng = $this->lng;
317  $ui = $this->ui;
318 
319  // weekdays
320  if ($this->getShowWeeksColumn()) {
321  $a_tpl->setCurrentBlock('month_header_col');
322  $a_tpl->setVariable('TXT_WEEKDAY', $this->lng->txt("cal_week_abbrev"));
323  $a_tpl->parseCurrentBlock();
324  }
325  for ($i = $this->user_settings->getWeekStart(); $i < (7 + $this->user_settings->getWeekStart()); $i++) {
326  $a_tpl->setCurrentBlock('month_header_col');
327  $a_tpl->setVariable('TXT_WEEKDAY', ilCalendarUtil::_numericDayToString($i, false));
328  $a_tpl->parseCurrentBlock();
329  }
330 
331  $bkid = $this->initBookingUserFromQuery();
332  if ($bkid) {
333  $user_id = $bkid;
334  $disable_empty = true;
335  } else {
336  $user_id = $this->user->getId();
337  $disable_empty = false;
338  }
339  $this->scheduler = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_MONTH, $user_id);
340  $this->scheduler->addSubitemCalendars(true);
341  $this->scheduler->calculate();
342 
343  $counter = 0;
345  (int) $this->seed->get(IL_CAL_FKT_DATE, 'm'),
346  (int) $this->seed->get(IL_CAL_FKT_DATE, 'Y'),
347  $this->user_settings->getWeekStart()
348  )->get() as $date) {
349  $counter++;
350 
351  $events = $this->scheduler->getByDay($date, $this->user->getTimeZone());
352  $has_events = (bool) count($events);
353  if ($has_events || !$disable_empty) {
354  $a_tpl->setCurrentBlock('month_col_link');
355  } else {
356  $a_tpl->setCurrentBlock('month_col_no_link');
357  }
358 
359  if ($disable_empty) {
360  if (!$has_events) {
361  $a_tpl->setVariable('DAY_CLASS', 'calminiinactive');
362  } else {
363  $week_has_events = true;
364  foreach ($events as $event) {
365  $booking = new ilBookingEntry($event['event']->getContextId());
366  if ($booking->hasBooked($event['event']->getEntryId())) {
367  $a_tpl->setVariable('DAY_CLASS', 'calminiapp');
368  break;
369  }
370  }
371  }
372  } elseif ($has_events) {
373  $week_has_events = true;
374  $a_tpl->setVariable('DAY_CLASS', 'calminiapp');
375  }
376 
377  $day = $date->get(IL_CAL_FKT_DATE, 'j');
378  $month = $date->get(IL_CAL_FKT_DATE, 'n');
379 
380  $month_day = $day;
381 
382  $path = $this->getTargetGUIClassPath();
383  $last_gui = end($path);
384  $this->ctrl->setParameterByClass($last_gui, 'seed', $date->get(IL_CAL_DATE));
385  if ($agenda_view_type = $this->requested_cal_agenda_per) {
386  $this->ctrl->setParameterByClass($last_gui, "cal_agenda_per", $agenda_view_type);
387  }
388  $a_tpl->setVariable('OPEN_DAY_VIEW', $this->ctrl->getLinkTargetByClass($this->getTargetGUIClassPath(), ''));
389 
390  $a_tpl->setVariable('MONTH_DAY', $month_day);
391 
392  $a_tpl->parseCurrentBlock();
393 
394  $a_tpl->setCurrentBlock('month_col');
395 
396  if (ilCalendarUtil::_isToday($date)) {
397  $a_tpl->setVariable('TD_CLASS', 'calminitoday');
398  } elseif (ilDateTime::_equals($date, $this->seed, IL_CAL_MONTH)) {
399  $a_tpl->setVariable('TD_CLASS', 'calministd');
400  } elseif (ilDateTime::_before($date, $this->seed, IL_CAL_MONTH)) {
401  $a_tpl->setVariable('TD_CLASS', 'calminiprev');
402  } else {
403  $a_tpl->setVariable('TD_CLASS', 'calmininext');
404  }
405 
406  $a_tpl->parseCurrentBlock();
407 
408  if ($counter and !($counter % 7)) {
409  if ($this->getShowWeeksColumn()) {
410  $a_tpl->setCurrentBlock('week');
411  $a_tpl->setVariable(
412  'WEEK',
413  $date->get(IL_CAL_FKT_DATE, 'W')
414  );
415  $a_tpl->parseCurrentBlock();
416  }
417 
418  $a_tpl->setCurrentBlock('month_row');
419  $a_tpl->parseCurrentBlock();
420 
421  $week_has_events = false;
422  }
423  }
424  $a_tpl->setCurrentBlock('mini_month');
425  if ($a_include_view_ctrl) {
426  $a_tpl->setVariable("VIEW_CTRL_SECTION", $ui->renderer()->render($this->getViewControl()));
427  }
428 
429  $a_tpl->parseCurrentBlock();
430  }
431 
432  protected function getViewControl(): Section
433  {
434  $ui = $this->ui;
435  $lng = $this->lng;
436 
437  $first_of_month = substr($this->seed->get(IL_CAL_DATE), 0, 7) . "-01";
438  $myseed = new ilDate($first_of_month, IL_CAL_DATE);
439 
440  $myseed->increment(ilDateTime::MONTH, -1);
441  $this->ctrl->setParameter($this, 'seed', $myseed->get(IL_CAL_DATE));
442 
443  $prev_link = $this->ctrl->getLinkTarget($this, "setSeed", "", true);
444 
445  $myseed->increment(ilDateTime::MONTH, 2);
446  $this->ctrl->setParameter($this, 'seed', $myseed->get(IL_CAL_DATE));
447  $next_link = $this->ctrl->getLinkTarget($this, "setSeed", "", true);
448 
449  $this->ctrl->setParameter($this, 'seed', "");
450 
451  $blockgui = $this;
452 
453  // view control
454  // ... previous button
455  $b1 = $ui->factory()->button()->standard($this->lng->txt("previous"), "#")->withOnLoadCode(function ($id) use (
456  $prev_link,
457  $blockgui
458  ) {
459  return
460  "$('#" . $id . "').click(function() { ilBlockJSHandler('block_" . $blockgui->getBlockType() .
461  "_" . $blockgui->getBlockId() . "','" . $prev_link . "'); return false;});";
462  });
463 
464  // ... month button
465  $this->ctrl->clearParameterByClass("ilcalendarblockgui", 'seed');
466  $month_link = $this->ctrl->getLinkTarget($this, "setSeed", "", true, false);
467  $seed_parts = explode("-", $this->seed->get(IL_CAL_DATE));
468  $b2 = $ui->factory()->button()->month($seed_parts[1] . "-" . $seed_parts[0])->withOnLoadCode(function ($id) use (
469  $month_link,
470  $blockgui
471  ) {
472  return "$('#" . $id . "').on('il.ui.button.month.changed', function(el, id, month) { var m = month.split('-'); ilBlockJSHandler('block_" . $blockgui->getBlockType() .
473  "_" . $blockgui->getBlockId() . "','" . $month_link . "' + '&seed=' + m[1] + '-' + m[0] + '-01'); return false;});";
474  });
475  // ... next button
476  $b3 = $ui->factory()->button()->standard($this->lng->txt("next"), "#")->withOnLoadCode(function ($id) use (
477  $next_link,
478  $blockgui
479  ) {
480  return
481  "$('#" . $id . "').click(function() { ilBlockJSHandler('block_" . $blockgui->getBlockType() .
482  "_" . $blockgui->getBlockId() . "','" . $next_link . "'); return false;});";
483  });
484 
485  return $ui->factory()->viewControl()->section($b1, $b2, $b3);
486  }
487 
491  public function getHTML(): string
492  {
493  $this->initCategories();
494  $lng = $this->lng;
495  $ilObjDataCache = $this->obj_data_cache;
496  $user = $this->user;
497 
498  if ($this->mode == ilCalendarCategories::MODE_REPOSITORY) {
499  $bkid = $this->initBookingUserFromQuery();
500  if (!$bkid) {
501  $obj_id = $ilObjDataCache->lookupObjId((int) $this->requested_ref_id);
502  $participants = ilCourseParticipants::_getInstanceByObjId($obj_id);
503  $users = array_unique(array_merge($participants->getTutors(), $participants->getAdmins()));
504  //$users = $participants->getParticipants();
505  $users = ilBookingEntry::lookupBookableUsersForObject([$obj_id], $users);
506  foreach ($users as $user_id) {
507  $now = new ilDateTime(time(), IL_CAL_UNIX);
508 
509  // default to last booking entry
510  $appointments = ilConsultationHourAppointments::getAppointments($user_id);
511  $next_app = end($appointments);
512  reset($appointments);
513 
514  foreach ($appointments as $entry) {
515  // find next entry
516  if (ilDateTime::_before($entry->getStart(), $now, IL_CAL_DAY)) {
517  continue;
518  }
519  $booking_entry = new ilBookingEntry($entry->getContextId());
520  if (!in_array($obj_id, $booking_entry->getTargetObjIds())) {
521  continue;
522  }
523 
524  if (!$booking_entry->isAppointmentBookableForUser($entry->getEntryId(), $user->getId())) {
525  continue;
526  }
527  $next_app = $entry;
528  break;
529  }
530 
531  $path = $this->getTargetGUIClassPath();
532  $this->ctrl->setParameterByClass(end($path), "ch_user_id", $user_id);
533 
534  if (!$this->getForceMonthView()) {
535  $this->cal_footer[] = array(
536  'link' => $this->ctrl->getLinkTargetByClass(
537  $this->getTargetGUIClassPath(),
538  'selectCHCalendarOfUser'
539  ),
540  'txt' => str_replace(
541  "%1",
542  ilObjUser::_lookupFullname($user_id),
543  $this->lng->txt("cal_consultation_hours_for_user")
544  )
545  );
546  }
547  $path = $this->getTargetGUIClassPath();
548  $last_gui = end($path);
549  $this->ctrl->setParameterByClass($last_gui, "ch_user_id", "");
550  $this->ctrl->setParameterByClass($last_gui, "bkid", $bkid);
551  $this->ctrl->setParameterByClass($last_gui, "seed", $this->seed->get(IL_CAL_DATE));
552  }
553  $this->ctrl->setParameter($this, "bkid", "");
554  $this->ctrl->setParameter($this, 'seed', '');
555  } else {
556  $this->ctrl->setParameter($this, "bkid", "");
557  $this->addBlockCommand(
558  $this->ctrl->getLinkTarget($this),
559  $this->lng->txt("back")
560  );
561  $this->ctrl->setParameter($this, "bkid", $this->initBookingUserFromQuery());
562  }
563  }
564 
565  if ($this->getProperty("settings")) {
566  $this->addBlockCommand(
567  $this->ctrl->getLinkTarget($this, "editSettings"),
568  $this->lng->txt("settings")
569  );
570  }
571 
572  $this->ctrl->setParameterByClass($this->getParentGUI(), "seed", $this->seed->get(IL_CAL_DATE));
573  $ret = parent::getHTML();
574  $this->ctrl->setParameterByClass($this->getParentGUI(), "seed", "");
575 
576  // workaround to include asynch code from ui only one time, see #20853
577  if ($this->ctrl->isAsynch()) {
578  $f = $this->ui->factory()->legacy("");
579  $ret .= $this->ui->renderer()->renderAsync($f);
580  }
581  if (count($this->modals) > 0) {
582  if ($this->ctrl->isAsynch()) {
583  $ret .= $this->ui->renderer()->renderAsync($this->modals);
584  } else {
585  $ret .= $this->ui->renderer()->render($this->modals);
586  }
587  }
588  return $ret;
589  }
590 
591  public function getOverview(): string
592  {
593  $lng = $this->lng;
594 
595  $schedule = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_INBOX);
596  $events = $schedule->getChangedEvents(true);
597 
598  $this->ctrl->setParameterByClass('ilcalendarinboxgui', 'changed', 1);
599  $link = '<a href=' . $this->ctrl->getLinkTargetByClass('ilcalendarinboxgui', '') . '>';
600  $this->ctrl->setParameterByClass('ilcalendarinboxgui', 'changed', '');
601  $text = '<div class="small">' . (count($events)) . " " . $this->lng->txt("cal_changed_events_header") . "</div>";
602  $end_link = '</a>';
603 
604  return $link . $text . $end_link;
605  }
606 
607  protected function initCategories(): void
608  {
611  if ($this->getForceMonthView()) {
612  // old comment: in full container calendar presentation (allows selection of other calendars)
613  } elseif (!$cats->getMode()) {
614  $cats->initialize(
616  (int) $this->requested_ref_id,
617  true
618  );
619  }
620  }
621 
622  protected function setSubTabs(): void
623  {
624  $this->tabs->clearSubTabs();
625  }
626 
627  public function setSeed(): void
628  {
630  "il_cal_block_" . $this->getBlockType() . "_" . $this->getBlockId() . "_seed",
631  $this->initSeedFromQuery()
632  );
633  if ($this->ctrl->isAsynch()) {
634  echo $this->getHTML();
635  exit;
636  } else {
637  $this->returnToUpperContext();
638  }
639  }
640 
641  public function returnToUpperContext(): void
642  {
643  $this->ctrl->returnToParent($this);
644  }
645 
646  protected function initCommands(): void
647  {
648  $lng = $this->lng;
649 
650  if (!$this->getForceMonthView()) {
651  // @todo: set checked on ($this->display_mode != 'mmon')
652  $this->addBlockCommand(
653  $this->ctrl->getLinkTarget($this, "setPdModeEvents"),
654  $this->lng->txt("cal_upcoming_events_header"),
655  ""
656  // see #35777 $this->ctrl->getLinkTarget($this, "setPdModeEvents", "", true)
657  );
658 
659  // @todo: set checked on ($this->display_mode == 'mmon')
660  $this->addBlockCommand(
661  $this->ctrl->getLinkTarget($this, "setPdModeMonth"),
662  $this->lng->txt("app_month"),
663  $this->ctrl->getLinkTarget($this, "setPdModeMonth", "", true)
664  );
665 
666  if ($this->getRepositoryMode()) {
667  #23921
668  $this->ctrl->setParameterByClass('ilcalendarpresentationgui', 'seed', '');
669  $this->addBlockCommand(
670  $this->ctrl->getLinkTargetByClass($this->getTargetGUIClassPath(), ""),
671  $this->lng->txt("cal_open_calendar")
672  );
673 
674  if ($this->access->checkAccess('edit_event', '', (int) $this->requested_ref_id)) {
675  $this->ctrl->setParameter($this, "add_mode", "");
676  $this->addBlockCommand(
677  $this->ctrl->getLinkTargetByClass("ilCalendarAppointmentGUI", "add"),
678  $this->lng->txt("add_appointment")
679  );
680  $this->ctrl->setParameter($this, "add_mode", "");
681  }
682  }
683  }
684  }
685 
686  public function setPdModeEvents(): void
687  {
689 
690  $this->user->writePref("il_pd_cal_mode", "evt");
691  $this->display_mode = "evt";
692  $this->setPresentation(self::PRES_SEC_LIST);
693  if ($this->ctrl->isAsynch()) {
694  echo $this->getHTML();
695  exit;
696  } else {
697  $this->ctrl->returnToParent($this);
698  }
699  }
700 
701  public function setPdModeMonth(): void
702  {
704 
705  $this->user->writePref("il_pd_cal_mode", "mmon");
706  $this->display_mode = "mmon";
707  $this->setPresentation(self::PRES_SEC_LEG);
708  if ($this->ctrl->isAsynch()) {
709  echo $this->getHTML();
710  exit;
711  } else {
712  $this->ctrl->redirectByClass("ildashboardgui", "show");
713  }
714  }
715 
716  public function getEventByAppointmentId(int $a_appointment_id): ?array
717  {
718  foreach ($this->getEvents() as $event) {
719  if (
720  array_key_exists('event', $event) &&
721  $event['event'] instanceof ilCalendarEntry &&
722  $event['event']->getEntryId() === $a_appointment_id
723  ) {
724  return $event;
725  }
726  }
727  return null;
728  }
729 
730  public function getEvents(): array
731  {
732  $seed = new ilDate(date('Y-m-d', time()), IL_CAL_DATE);
733 
735  $schedule->addSubitemCalendars(true); // #12007
736  $schedule->setEventsLimit(20);
737  $schedule->calculate();
738  // #13809
739  return $schedule->getScheduledEvents();
740  }
741 
742  public function getData(): array
743  {
744  $lng = $this->lng;
745  $ui = $this->ui;
746 
747  $f = $ui->factory();
748 
749  $events = $this->getEvents();
750 
751  $data = array();
752  if (sizeof($events)) {
753  foreach ($events as $item) {
754  $this->ctrl->setParameter($this, "app_id", $item["event"]->getEntryId());
755  $this->ctrl->setParameter($this, 'dt', $item['dstart']);
756  $url = $this->ctrl->getLinkTarget($this, "getModalForApp", "", true, false);
757  $this->ctrl->setParameter($this, "app_id", $this->initAppointmentIdFromQuery());
758  $this->ctrl->setParameter($this, "dt", $this->initInitialDateQuery());
759  $modal = $f->modal()->roundtrip('', [])->withAsyncRenderUrl($url);
760 
761  $dates = $this->getDatesForItem($item);
762 
763  $shy = $f->button()->shy(
764  $item["event"]->getPresentationTitle(),
765  ""
766  )->withOnClick($modal->getShowSignal());
767 
768  $data[] = array(
769  "date" => ilDatePresentation::formatPeriod($dates["start"], $dates["end"]),
770  "title" => $item["event"]->getPresentationTitle(),
771  "url" => "#",
772  "shy_button" => $shy,
773  "modal" => $modal
774  );
775  }
776  $this->setEnableNumInfo(true);
777  } else {
778  $data = [];
779  /*$data[] = array(
780  "date" => $lng->txt("msg_no_search_result"),
781  "title" => "",
782  "url" => ""
783  ); */
784 
785  $this->setEnableNumInfo(false);
786  }
787 
788  return $data;
789  }
790 
796  public function getDatesForItem(array $item): array
797  {
798  $start = $item["dstart"];
799  $end = $item["dend"];
800  if ($item["fullday"]) {
801  $start = new ilDate($start, IL_CAL_UNIX);
802  $end = new ilDate($end, IL_CAL_UNIX);
803  } else {
804  $start = new ilDateTime($start, IL_CAL_UNIX);
805  $end = new ilDateTime($end, IL_CAL_UNIX);
806  }
807  return array("start" => $start, "end" => $end);
808  }
809 
814  public function getModalForApp()
815  {
816  $this->initCategories();
817  $ui = $this->ui;
818 
819  $f = $ui->factory();
820  $r = $ui->renderer();
821 
822  // @todo: this needs optimization
823  $events = $this->getEvents();
824  foreach ($events as $item) {
825  if ($item["event"]->getEntryId() == $this->initAppointmentIdFromQuery() && $item['dstart'] == $this->initInitialDateQuery()) {
826  $dates = $this->getDatesForItem($item);
827 
828  // content of modal
829  $next_gui = ilCalendarAppointmentPresentationGUI::_getInstance($this->seed, $item);
830  $content = $this->ctrl->getHTML($next_gui);
831 
832  $modal = $f->modal()->roundtrip(
833  ilDatePresentation::formatPeriod($dates["start"], $dates["end"]),
834  $f->legacy($content)
835  );
836  echo $r->renderAsync($modal);
837  }
838  }
839  exit();
840  }
841 
842  //
843  // New rendering
844  //
845 
846  protected bool $new_rendering = true;
847 
851  protected function getViewControls(): array
852  {
853  if ($this->getPresentation() == self::PRES_SEC_LEG) {
854  return [$this->getViewControl()];
855  }
856  return parent::getViewControls();
857  }
858 
862  protected function getLegacyContent(): string
863  {
864  $tpl = new ilTemplate(
865  "tpl.calendar_block.html",
866  true,
867  true,
868  "Services/Calendar"
869  );
870 
871  $this->addMiniMonth($tpl);
872 
873  $panel_tpl = new \ilTemplate(
874  'tpl.cal_block_panel.html',
875  true,
876  true,
877  'Services/Calendar'
878  );
879 
880  $this->addSubscriptionButton($panel_tpl);
881 
882  return $tpl->get() . $panel_tpl->get();
883  }
884 
888  protected function getListItemForData(array $data): ?\ILIAS\UI\Component\Item\Item
889  {
890  $factory = $this->ui->factory();
891  if (isset($data["modal"])) {
892  $this->modals[] = $data["modal"];
893  }
894  if (isset($data["shy_button"])) {
895  return $factory->item()->standard($data["shy_button"])->withDescription($data["date"]);
896  } else {
897  return $factory->item()->standard($data["date"]);
898  }
899  }
900 
905  public function getNoItemFoundContent(): string
906  {
907  return $this->lng->txt("cal_no_events_block");
908  }
909 
913  protected function addSubscriptionButton(ilTemplate $panel_template): void
914  {
915  global $DIC;
916 
917  $ui_factory = $DIC->ui()->factory();
918  $ui_renderer = $DIC->ui()->renderer();
919 
920  $gui_path = $this->getTargetGUIClassPath();
921  $gui_path[] = strtolower(\ilCalendarSubscriptionGUI::class);
922  $url = $this->ctrl->getLinkTargetByClass($gui_path, 'getModalForSubscription', "", true, false);
923 
924  $roundtrip_modal = $ui_factory->modal()->roundtrip('', [])->withAsyncRenderUrl($url);
925 
926  $standard_button = $ui_factory->button()->standard($this->lng->txt('btn_ical'), '')->withOnClick(
927  $roundtrip_modal->getShowSignal()
928  );
929  $components = [
930  $roundtrip_modal,
931  $standard_button
932  ];
933 
934  $presentation = $ui_renderer->render($components);
935 
936  $panel_template->setCurrentBlock('subscription_buttons');
937  $panel_template->setVariable('SUBSCRIPTION_BUTTON', $presentation);
938  $panel_template->parseCurrentBlock();
939  }
940 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static _getInstance(ilDate $seed, array $a_app)
get singleton instance
$app
Definition: cli.php:39
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static get(string $a_var)
ilCalendarUserSettings $user_settings
ilCalendarSettings $settings
ilObjUser $user
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exit
Definition: login.php:28
ILIAS DI UIServices $ui
Class Factory.
getDatesForItem(array $item)
Get start/end date for item.
static _buildMonthDayList(int $a_month, int $a_year, int $weekstart)
Build a month day list.
get(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilLanguage $lng
getShowWeeksColumn()
Show weeks column.
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.
static _lookupFullname(int $a_user_id)
static getScreenMode()
Get Screen Mode for current command.
setLimit(int $a_limit)
setBlockId(string $a_block_id="0")
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
setDataSection(string $a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
Class ChatMainBarProvider .
setEnableNumInfo(bool $a_enablenuminfo)
Help GUI class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_MONTH
getNoItemFoundContent()
No item entry.
getEventByAppointmentId(int $a_appointment_id)
const IL_CAL_UNIX
getModalForApp()
Get modal for appointment (see similar code in ilCalendarAgendaListGUI) todo use all this methods fro...
getHTML()
Get bloch HTML code.
$path
Definition: ltiservices.php:32
static _getInstanceByUserId(int $a_user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
setRowTemplate(string $a_rowtemplatename, string $a_rowtemplatedir="")
Set Row Template Name.
const IL_CAL_DAY
ilObjectDataCache $obj_data_cache
static http()
Fetches the global http state from ILIAS.
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
ilTemplate $tpl
static _getInstanceByObjId(int $a_obj_id)
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...
ilCalendarSchedule $scheduler
const IL_CAL_FKT_DATE
static has($a_var)
const IL_SCREEN_CENTER
static _numericDayToString(int $a_day, bool $a_long=true)
static _getInstance($a_usr_id=0)
get singleton instance
static getAppointments(int $a_user_id)
Get all appointments.
addSubscriptionButton(ilTemplate $panel_template)
Add subscription button.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
const IL_CAL_DATE
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false)
Format a period of two dates Shows: 14.
This describes a Section Control.
Definition: Section.php:29
Administrate calendar appointments.
Calendar blocks, displayed in different contexts, e.g.
__construct(Container $dic, ilPlugin $plugin)
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...
$ilUser
Definition: imgupload.php:34
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setTitle(string $a_title)
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
This class represents a block method of a block.
$url
addBlockCommand(string $a_href, string $a_text, string $a_onclick="")
static _lookupType(int $id, bool $reference=false)
fillDataSection()
Standard implementation for row based data.
getProperty(string $a_property)
setPresentation(int $type)
static set(string $a_var, $a_val)
Set a value.
$factory
Definition: metadata.php:75
static _isToday(ilDateTime $date)
$i
Definition: metadata.php:41
Represents a list of calendar appointments (including recurring events) for a specific user in a give...