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 8/** 9* Calendar blocks, displayed in different contexts, e.g. groups and courses 10* 11* @author Alex Killing <alex.killing@gmx.de> 12* @version $Id$ 13* 14* @ilCtrl_IsCalledBy ilCalendarBlockGUI: ilColumnGUI 15* @ilCtrl_Calls ilCalendarBlockGUI: ilCalendarAppointmentGUI, ilCalendarMonthGUI, ilCalendarWeekGUI, ilCalendarDayGUI 16* @ilCtrl_Calls ilCalendarBlockGUI: ilConsultationHoursGUI, ilCalendarAppointmentPresentationGUI 17* 18* @ingroup ServicesCalendar 19*/ 20class ilCalendarBlockGUI extends ilBlockGUI 21{ 22 /** 23 * @var ilCtrl|null 24 */ 25 public $ctrl = null; 26 protected $mode; 27 protected $display_mode; 28 29 public static $block_type = "cal"; 30 public static $st_data; 31 32 /** 33 * @var ilTabsGUI 34 */ 35 protected $tabs; 36 37 /** 38 * @var 39 */ 40 protected $obj_data_cache; 41 42 protected $parent_gui = "ilcolumngui"; 43 44 /** 45 * @var \ILIAS\DI\UIServices 46 */ 47 protected $ui; 48 49 protected $force_month_view = false; 50 51 /** 52 * Constructor 53 * @param boolean skip initialisation (is called by derived PDCalendarBlockGUI class) 54 */ 55 public function __construct() 56 { 57 global $DIC; 58 59 parent::__construct(); 60 61 $this->tabs = $DIC->tabs(); 62 $this->obj_data_cache = $DIC["ilObjDataCache"]; 63 $this->ui = $DIC->ui(); 64 65 $lng = $this->lng; 66 $ilCtrl = $this->ctrl; 67 $tpl = $this->main_tpl; 68 $ilUser = $this->user; 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 112 $this->settings = ilCalendarSettings::_getInstance(); 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 123 /** 124 * Show weeks column 125 * @param 126 * @return 127 */ 128 public function getShowWeeksColumn() 129 { 130 return ($this->settings->getShowWeeks() && $this->user_settings->getShowWeeks()); 131 } 132 133 /** 134 * @inheritdoc 135 */ 136 public function getBlockType() : string 137 { 138 return self::$block_type; 139 } 140 141 /** 142 * @inheritdoc 143 */ 144 protected function isRepositoryObject() : bool 145 { 146 return false; 147 } 148 149 /** 150 * Set parent gui 151 * @param $a_val 152 */ 153 public function setParentGUI($a_val) 154 { 155 $this->parent_gui = $a_val; 156 } 157 158 /** 159 * Get parent gui 160 * @return 161 */ 162 public function getParentGUI() 163 { 164 return $this->parent_gui; 165 } 166 167 /** 168 * Set force month view 169 * @param bool $a_val force month view 170 */ 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 180 /** 181 * Get force month view 182 * @return bool force month view 183 */ 184 public function getForceMonthView() 185 { 186 return $this->force_month_view; 187 } 188 189 /** 190 * Get Screen Mode for current command. 191 */ 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 217 /** 218 * execute command 219 */ 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 261 /** 262 * Set EnableEdit. 263 * @param boolean $a_enable_edit Edit mode on/off 264 */ 265 public function setEnableEdit($a_enable_edit = 0) 266 { 267 $this->enable_edit = $a_enable_edit; 268 } 269 270 /** 271 * Get EnableEdit. 272 * @return boolean Edit mode on/off 273 */ 274 public function getEnableEdit() 275 { 276 return $this->enable_edit; 277 } 278 279 /** 280 * Fill data section 281 */ 282 public function fillDataSection() 283 { 284 if ($this->display_mode != "mmon") { 285 $this->setRowTemplate("tpl.pd_event_list.html", "Services/Calendar"); 286 287 ilBlockGUI::fillDataSection(); 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 301 /** 302 * Get target gui class path (for presenting the calendar) 303 * @param 304 * @return 305 */ 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 325 /** 326 * Add mini version of monthly overview 327 * (Maybe extracted to another class, if used in pd calendar tab 328 */ 329 public function addMiniMonth($a_tpl, $a_include_view_ctrl = false) 330 { 331 $lng = $this->lng; 332 $ilCtrl = $this->ctrl; 333 $ilUser = $this->user; 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; 362 foreach (ilCalendarUtil::_buildMonthDayList( 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 458 /** 459 * Get view control 460 * @return \ILIAS\UI\Component\ViewControl\Section 461 */ 462 protected function getViewControl() : \ILIAS\UI\Component\ViewControl\Section 463 { 464 $ui = $this->ui; 465 $lng = $this->lng; 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 510 /** 511 * Get bloch HTML code. 512 */ 513 public function getHTML() 514 { 515 $this->initCategories(); 516 $lng = $this->lng; 517 $ilCtrl = $this->ctrl; 518 $ilObjDataCache = $this->obj_data_cache; 519 $user = $this->user; 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 626 /** 627 * Get overview. 628 */ 629 public function getOverview() 630 { 631 $lng = $this->lng; 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 647 /** 648 * init categories 649 * @access protected 650 * @param 651 * @return 652 */ 653 protected function initCategories() 654 { 655 $this->mode = ilCalendarCategories::MODE_REPOSITORY; 656 $cats = \ilCalendarCategories::_getInstance(); 657 if ($this->getForceMonthView()) { 658 // old comment: in full container calendar presentation (allows selection of other calendars) 659 } elseif (!$cats->getMode()) { 660 $cats->initialize( 661 \ilCalendarCategories::MODE_REPOSITORY_CONTAINER_ONLY, 662 (int) $_GET['ref_id'], 663 true 664 ); 665 } 666 } 667 668 /** 669 * @param 670 * @return 671 */ 672 protected function setSubTabs() 673 { 674 $ilTabs = $this->tabs; 675 676 $ilTabs->clearSubTabs(); 677 } 678 679 /** 680 * Set seed 681 */ 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 697 /** 698 * Return to upper context 699 */ 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 ); 720 $this->tpl->parseCurrentBlock(); 721 } 722 // end-patch ch 723 724 if ($this->tpl->blockExists("block_footer")) { 725 $this->tpl->setCurrentBlock("block_footer"); 726 $this->tpl->parseCurrentBlock(); 727 } 728 } 729 730 public function initCommands() 731 { 732 $ilCtrl = $this->ctrl; 733 $lng = $this->lng; 734 735 if (!$this->getForceMonthView()) { 736 // @todo: set checked on ($this->display_mode != 'mmon') 737 $this->addBlockCommand( 738 $ilCtrl->getLinkTarget($this, "setPdModeEvents"), 739 $lng->txt("cal_upcoming_events_header"), 740 $ilCtrl->getLinkTarget($this, "setPdModeEvents", "", true) 741 ); 742 743 // @todo: set checked on ($this->display_mode == 'mmon') 744 $this->addBlockCommand( 745 $ilCtrl->getLinkTarget($this, "setPdModeMonth"), 746 $lng->txt("app_month"), 747 $ilCtrl->getLinkTarget($this, "setPdModeMonth", "", true) 748 ); 749 750 if ($this->getRepositoryMode()) { 751 #23921 752 $ilCtrl->setParameterByClass('ilcalendarpresentationgui', 'seed', ''); 753 $this->addBlockCommand( 754 $ilCtrl->getLinkTargetByClass($this->getTargetGUIClassPath(), ""), 755 $lng->txt("cal_open_calendar") 756 ); 757 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 public function setPdModeEvents() 769 { 770 $ilCtrl = $this->ctrl; 771 $ilUser = $this->user; 772 773 $ilUser->writePref("il_pd_cal_mode", "evt"); 774 $this->display_mode = "evt"; 775 $this->setPresentation(self::PRES_SEC_LIST); 776 if ($ilCtrl->isAsynch()) { 777 echo $this->getHTML(); 778 exit; 779 } else { 780 $ilCtrl->redirectByClass("ildashboardgui", "show"); 781 } 782 } 783 784 public function setPdModeMonth() 785 { 786 $ilCtrl = $this->ctrl; 787 $ilUser = $this->user; 788 789 $ilUser->writePref("il_pd_cal_mode", "mmon"); 790 $this->display_mode = "mmon"; 791 $this->setPresentation(self::PRES_SEC_LEG); 792 if ($ilCtrl->isAsynch()) { 793 echo $this->getHTML(); 794 exit; 795 } else { 796 $ilCtrl->redirectByClass("ildashboardgui", "show"); 797 } 798 } 799 800 /** 801 * Get events 802 * @param 803 * @return 804 */ 805 public function getEvents() 806 { 807 $seed = new ilDate(date('Y-m-d', time()), IL_CAL_DATE); 808 809 include_once('./Services/Calendar/classes/class.ilCalendarSchedule.php'); 810 $schedule = new ilCalendarSchedule($seed, ilCalendarSchedule::TYPE_PD_UPCOMING); 811 $schedule->addSubitemCalendars(true); // #12007 812 $schedule->setEventsLimit(20); 813 $schedule->calculate(); 814 $ev = $schedule->getScheduledEvents(); // #13809 815 return ($ev); 816 } 817 818 public function getData() 819 { 820 $lng = $this->lng; 821 $ui = $this->ui; 822 823 $f = $ui->factory(); 824 825 $events = $this->getEvents(); 826 827 $data = array(); 828 if (sizeof($events)) { 829 foreach ($events as $item) { 830 $this->ctrl->setParameter($this, "app_id", $item["event"]->getEntryId()); 831 $this->ctrl->setParameter($this, 'dt', $item['dstart']); 832 $url = $this->ctrl->getLinkTarget($this, "getModalForApp", "", true, false); 833 $this->ctrl->setParameter($this, "app_id", $_GET["app_id"]); 834 $this->ctrl->setParameter($this, "dt", $_GET["dt"]); 835 $modal = $f->modal()->roundtrip('', [])->withAsyncRenderUrl($url); 836 837 $dates = $this->getDatesForItem($item); 838 839 $comps = [$f->button()->shy($item["event"]->getPresentationTitle(), "")->withOnClick($modal->getShowSignal()), $modal]; 840 $renderer = $ui->renderer(); 841 $shy = $renderer->render($comps); 842 843 $data[] = array( 844 "date" => ilDatePresentation::formatPeriod($dates["start"], $dates["end"]), 845 "title" => $item["event"]->getPresentationTitle(), 846 "url" => "#", 847 "shy_button" => $shy 848 ); 849 } 850 $this->setEnableNumInfo(true); 851 } else { 852 $data = []; 853 /*$data[] = array( 854 "date" => $lng->txt("msg_no_search_result"), 855 "title" => "", 856 "url" => "" 857 ); */ 858 859 $this->setEnableNumInfo(false); 860 } 861 862 return $data; 863 } 864 865 /** 866 * Get start/end date for item 867 * @param array $item item 868 * @return array 869 */ 870 public function getDatesForItem($item) 871 { 872 $start = $item["dstart"]; 873 $end = $item["dend"]; 874 if ($item["fullday"]) { 875 $start = new ilDate($start, IL_CAL_UNIX); 876 $end = new ilDate($end, IL_CAL_UNIX); 877 } else { 878 $start = new ilDateTime($start, IL_CAL_UNIX); 879 $end = new ilDateTime($end, IL_CAL_UNIX); 880 } 881 return array("start" => $start, "end" => $end); 882 } 883 884 /** 885 * Get modal for appointment (see similar code in ilCalendarAgendaListGUI) 886 * todo use all this methods from ilcalendarviewgui.php 887 */ 888 public function getModalForApp() 889 { 890 $this->initCategories(); 891 $ui = $this->ui; 892 $ilCtrl = $this->ctrl; 893 894 $f = $ui->factory(); 895 $r = $ui->renderer(); 896 897 // @todo: this needs optimization 898 $events = $this->getEvents(); 899 foreach ($events as $item) { 900 if ($item["event"]->getEntryId() == (int) $_GET["app_id"] && $item['dstart'] == (int) $_GET['dt']) { 901 $dates = $this->getDatesForItem($item); 902 903 // content of modal 904 include_once("./Services/Calendar/classes/class.ilCalendarAppointmentPresentationGUI.php"); 905 $next_gui = ilCalendarAppointmentPresentationGUI::_getInstance($this->seed, $item); 906 $content = $ilCtrl->getHTML($next_gui); 907 908 $modal = $f->modal()->roundtrip(ilDatePresentation::formatPeriod($dates["start"], $dates["end"]), $f->legacy($content)); 909 echo $r->renderAsync($modal); 910 } 911 } 912 exit(); 913 } 914 915 // 916 // New rendering 917 // 918 919 protected $new_rendering = true; 920 921 /** 922 * @inheritdoc 923 */ 924 protected function getViewControls() : array 925 { 926 if ($this->getPresentation() == self::PRES_SEC_LEG) { 927 return [$this->getViewControl()]; 928 } 929 return parent::getViewControls(); 930 } 931 932 /** 933 * @inheritdoc 934 */ 935 protected function getLegacyContent() : string 936 { 937 $tpl = new ilTemplate( 938 "tpl.calendar_block.html", 939 true, 940 true, 941 "Services/Calendar" 942 ); 943 944 $this->addMiniMonth($tpl); 945 946 $panel_tpl = new \ilTemplate( 947 'tpl.cal_block_panel.html', 948 true, 949 true, 950 'Services/Calendar' 951 ); 952 953 $this->addConsultationHourButtons($panel_tpl); 954 $this->addSubscriptionButton($panel_tpl); 955 956 return $tpl->get().$panel_tpl->get(); 957 } 958 959 /** 960 * @inheritdoc 961 */ 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 972 /** 973 * No item entry 974 * @return string 975 */ 976 protected function getNoItemFoundContent() : string 977 { 978 return $this->lng->txt("cal_no_events_block"); 979 } 980 981 982 /** 983 * Add consultation hour buttons 984 */ 985 protected function addConsultationHourButtons(ilTemplate $panel_template) : void 986 { 987 global $DIC; 988 989 $user = $DIC->user(); 990 991 if (!$this->getRepositoryMode()) { 992 return; 993 } 994 995 $links = \ilConsultationHourUtils::getConsultationHourLinksForRepositoryObject( 996 (int) $_GET['ref_id'], 997 (int) $user->getId(), 998 $this->getTargetGUIClassPath() 999 ); 1000 $counter = 0; 1001 foreach ($links as $link) { 1002 $ui_factory = $DIC->ui()->factory(); 1003 $ui_renderer = $DIC->ui()->renderer(); 1004 1005 $link_button = $ui_factory->button()->shy( 1006 $link['txt'], 1007 $link['link'] 1008 ); 1009 if ($counter) { 1010 $panel_template->touchBlock('consultation_hour_buttons_multi'); 1011 } 1012 $panel_template->setCurrentBlock('consultation_hour_buttons'); 1013 $panel_template->setVariable('SHY_BUTTON', $ui_renderer->render([$link_button])); 1014 $panel_template->parseCurrentBlock(); 1015 $counter++; 1016 } 1017 } 1018 1019 /** 1020 * Add subscription button 1021 */ 1022 protected function addSubscriptionButton(ilTemplate $panel_template) : void 1023 { 1024 global $DIC; 1025 1026 $lng = $DIC->language(); 1027 1028 $ui_factory = $DIC->ui()->factory(); 1029 $ui_renderer = $DIC->ui()->renderer(); 1030 1031 $gui_path = $this->getTargetGUIClassPath(); 1032 $gui_path[] = strtolower(\ilCalendarSubscriptionGUI::class); 1033 $url = $this->ctrl->getLinkTargetByClass($gui_path, 'getModalForSubscription', "", true, false); 1034 1035 $roundtrip_modal = $ui_factory->modal()->roundtrip('', [])->withAsyncRenderUrl($url); 1036 1037 $standard_button = $ui_factory->button()->standard($lng->txt('btn_ical'), '')->withOnClick( 1038 $roundtrip_modal->getShowSignal() 1039 ); 1040 $components = [ 1041 $roundtrip_modal, 1042 $standard_button 1043 ]; 1044 1045 $presentation = $ui_renderer->render($components); 1046 1047 $panel_template->setCurrentBlock('subscription_buttons'); 1048 $panel_template->setVariable('SUBSCRIPTION_BUTTON', $presentation); 1049 $panel_template->parseCurrentBlock(); 1050 } 1051} 1052