ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCalendarCategories.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29{
30 public const MODE_UNDEFINED = 0;
31 public const MODE_REPOSITORY = 2; // course/group full calendar view (allows to select other calendars)
32 public const MODE_REMOTE_ACCESS = 3;
35 public const MODE_MANAGE = 6;
36 public const MODE_CONSULTATION = 7;
38 public const MODE_REMOTE_SELECTED = 9;
39 public const MODE_REPOSITORY_CONTAINER_ONLY = 10; // course/group content view (side block, focus on course/group appointments only)
40 public const MODE_SINGLE_CALENDAR = 11;
41
42 protected static ?ilCalendarCategories $instance = null;
43 protected ilDBInterface $db;
44 protected ilLogger $logger;
46 protected ilObjUser $user;
47 protected ilLanguage $lng;
50 protected ilTree $tree;
51
52 protected int $user_id = 0;
53 protected int $mode = self::MODE_UNDEFINED;
54
55 protected array $categories = array();
56 protected array $categories_info = array();
57 protected array $subitem_categories = array();
58
59 protected int $root_ref_id = 0;
60 protected int $root_obj_id = 0;
61
62 protected int $ch_user_id = 0;
63 protected int $target_ref_id = 0;
64
68 public function __construct(int $a_usr_id = 0)
69 {
70 global $DIC;
71
72 $this->user = $DIC->user();
73 $this->db = $DIC->database();
74 $this->logger = $DIC->logger()->cal();
75 $this->lng = $DIC->language();
76 $this->rbacsystem = $DIC->rbac()->system();
77 $this->access = $DIC->access();
78 $this->user_id = $a_usr_id;
79 $this->tree = $DIC->repositoryTree();
80 if (!$this->user_id) {
81 $this->user_id = $this->user->getId();
82 }
83 $this->fav_rep = new ilFavouritesDBRepository();
84 }
85
89 public static function _getInstance($a_usr_id = 0): ilCalendarCategories
90 {
91 if (self::$instance) {
92 return self::$instance;
93 }
94 return self::$instance = new ilCalendarCategories($a_usr_id);
95 }
96
100 public static function lookupRemoteCalendars(): array
101 {
102 global $DIC;
103
104 $db = $DIC->database();
105
106 $query = 'SELECT cat_id FROM cal_categories ' .
107 'WHERE loc_type = ' . $db->quote(ilCalendarCategory::LTYPE_REMOTE);
108 $res = $db->query($query);
109 $remote = [];
110 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
111 $remote[] = new ilCalendarCategory((int) $row->cat_id);
112 }
113 return $remote;
114 }
115
119 public static function _lookupCategoryIdByObjId(int $a_obj_id): int
120 {
121 global $DIC;
122
123 $ilDB = $DIC->database();
124 $query = "SELECT cat_id FROM cal_categories " .
125 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
126 "AND type = " . $ilDB->quote(ilCalendarCategory::TYPE_OBJ, 'integer') . " ";
127
128 $res = $ilDB->query($query);
129 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
130 return (int) $row->cat_id;
131 }
132 return 0;
133 }
134
138 public static function _isOwner(int $a_usr_id, int $a_cal_id): bool
139 {
140 global $DIC;
141
142 $ilDB = $DIC['ilDB'];
143
144 $query = "SELECT * FROM cal_categories " .
145 "WHERE cat_id = " . $ilDB->quote($a_cal_id, 'integer') . " " .
146 "AND obj_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
147 "AND type = " . $ilDB->quote(ilCalendarCategory::TYPE_USR, 'integer') . " ";
148 $res = $ilDB->query($query);
149 return (bool) $res->numRows();
150 }
151
155 public static function deletePDItemsCache(int $a_usr_id): void
156 {
157 ilCalendarCache::getInstance()->deleteByAdditionalKeys(
158 $a_usr_id,
159 self::MODE_PERSONAL_DESKTOP_ITEMS,
160 'categories'
161 );
162 }
163
167 public static function deleteRepositoryCache(int $a_usr_id): void
168 {
169 ilCalendarCache::getInstance()->deleteByAdditionalKeys(
170 $a_usr_id,
171 self::MODE_REPOSITORY,
172 'categories'
173 );
174 }
175
179 final protected function sleep(): string
180 {
181 return serialize(
182 array(
183 'categories' => $this->categories,
184 'categories_info' => $this->categories_info,
185 'subitem_categories' => $this->subitem_categories
186 )
187 );
188 }
189
193 protected function wakeup(string $a_ser): void
194 {
195 $info = unserialize($a_ser);
196
197 $this->categories = $info['categories'];
198 $this->categories_info = $info['categories_info'];
199 $this->subitem_categories = $info['subitem_categories'];
200 }
201
205 public function setCHUserId(int $a_user_id): void
206 {
207 $this->ch_user_id = $a_user_id;
208 }
209
210 public function getCHUserId(): int
211 {
212 return $this->ch_user_id;
213 }
214
215 protected function setMode(int $a_mode): void
216 {
217 $this->mode = $a_mode;
218 }
219
220 public function getMode(): int
221 {
222 return $this->mode;
223 }
224
225 protected function setTargetRefId(int $a_ref_id): void
226 {
227 $this->target_ref_id = $a_ref_id;
228 }
229
230 public function getTargetRefId(): int
231 {
233 }
234
235 public function setSourceRefId(int $a_val): void
236 {
237 $this->root_ref_id = $a_val;
238 }
239
242 public function getsourcerefid(): int
243 {
244 return $this->root_ref_id;
245 }
246
250 public function initialize(
251 int $a_mode,
252 int $a_source_ref_id = 0,
253 bool $a_use_cache = false,
254 int $a_cat_id = 0
255 ): void {
256 if ($this->getMode() != 0) {
257 throw new ilCalCategoriesInitializedMultipleException("ilCalendarCategories is initialized multiple times for user " . $this->user_id . ".");
258 }
259
260 $this->setMode($a_mode);
261
262 // see comments in https://mantis.ilias.de/view.php?id=25254
263 if ($a_use_cache && $this->getMode() != self::MODE_REPOSITORY_CONTAINER_ONLY) {
264 // Read categories from cache
265 if ($cats = ilCalendarCache::getInstance()->getEntry($this->user_id . ':' . $a_mode . ':categories:' . $a_source_ref_id)) {
266 if ($this->getMode() != self::MODE_REPOSITORY &&
267 $this->getMode() != self::MODE_CONSULTATION &&
268 $this->getMode() != self::MODE_PORTFOLIO_CONSULTATION) {
269 $this->wakeup($cats);
270 return;
271 }
272 }
273 }
274
275 switch ($this->getMode()) {
278 $this->readPDCalendars();
279 } else {
281 }
282 break;
283
285 $this->readSelectedCalendar($a_source_ref_id);
286 break;
287
289 $this->readPDCalendars();
290 break;
291
294 break;
295
297 $this->root_ref_id = $a_source_ref_id;
298 $this->root_obj_id = ilObject::_lookupObjId($this->root_ref_id);
299 $this->readReposCalendars();
300 break;
301
303 $this->root_ref_id = $a_source_ref_id;
304 $this->root_obj_id = ilObject::_lookupObjId($this->root_ref_id);
305 $this->readReposCalendars(true);
306 break;
307
309 $this->readPDCalendars();
311 break;
312
314 #$this->readPrivateCalendars();
315 $this->setTargetRefId($a_source_ref_id);
316 $this->readConsultationHoursCalendar($a_source_ref_id);
317 break;
318
321 break;
322
324 $this->readSingleCalendar($a_cat_id);
325 break;
326 }
327
328 if ($a_use_cache) {
329 if ($this->getMode() != self::MODE_REPOSITORY &&
330 $this->getMode() != self::MODE_CONSULTATION &&
331 $this->getMode() != self::MODE_PORTFOLIO_CONSULTATION) {
332 // Store in cache
333 ilCalendarCache::getInstance()->storeEntry(
334 $this->user_id . ':' . $a_mode . ':categories:' . $a_source_ref_id,
335 $this->sleep(),
336 $this->user_id,
337 $a_mode,
338 'categories'
339 );
340 }
341 }
342 }
343
344 public function getCategoryInfo(int $a_cat_id): array
345 {
346 if (isset($this->categories_info[$a_cat_id])) {
347 return $this->categories_info[$a_cat_id];
348 }
349
350 if (in_array($a_cat_id, $this->subitem_categories)) {
351 foreach ($this->categories as $cat_id) {
352 if (in_array($a_cat_id, $this->categories_info[$cat_id]['subitem_ids'])) {
353 return $this->categories_info[$cat_id];
354 }
355 }
356 }
357 return [];
358 }
359
360 public function getCategoriesInfo(): array
361 {
362 return $this->categories_info ?: array();
363 }
364
365 public function getCategories(bool $a_include_subitem_calendars = false): array
366 {
367 if ($a_include_subitem_calendars) {
368 return array_merge($this->categories, $this->subitem_categories);
369 }
370
371 return $this->categories ?: array();
372 }
373
374 public function getSubitemCategories(int $a_cat_id): array
375 {
376 if (!isset($this->categories_info[$a_cat_id]['subitem_ids'])) {
377 return array($a_cat_id);
378 }
379 return array_merge((array) $this->categories_info[$a_cat_id]['subitem_ids'], array($a_cat_id));
380 }
381
382 public function prepareCategoriesOfUserForSelection(): array
383 {
384 $has_personal_calendar = false;
385 $cats = [];
386 foreach ($this->categories_info as $info) {
387 if ($info['obj_type'] == 'sess' || $info['obj_type'] == 'exc') {
388 continue;
389 }
390
391 if (($info['remote'] ?? 0) == ilCalendarCategory::LTYPE_REMOTE) {
392 continue;
393 }
394
395 if ($info['type'] == ilCalendarCategory::TYPE_USR and $info['editable']) {
396 $has_personal_calendar = true;
397 }
398
399 if ($info['editable']) {
400 $cats[$info['cat_id']] = $info['title'];
401 }
402 }
403 // If there
404 if (!$has_personal_calendar) {
405 $cats[0] = $this->lng->txt('cal_default_calendar');
406 }
407 return $cats;
408 }
409
414 public function getNotificationCalendars(): array
415 {
416 $not = array();
417 foreach ($this->categories_info as $info) {
418 if ($info['type'] == ilCalendarCategory::TYPE_OBJ and $info['editable']) {
419 if (ilObject::_lookupType($info['obj_id']) == 'crs' or ilObject::_lookupType($info['obj_id']) == 'grp') {
420 $not[] = (int) $info['cat_id'];
421 }
422 }
423 }
424 return $not;
425 }
426
430 public function isEditable(int $a_cat_id): bool
431 {
432 return isset($this->categories_info[$a_cat_id]['editable']) && $this->categories_info[$a_cat_id]['editable'];
433 }
434
438 public function isVisible($a_cat_id): bool
439 {
440 return in_array($a_cat_id, $this->categories) || in_array($a_cat_id, $this->subitem_categories);
441 }
442
446 protected function readPDCalendars(): void
447 {
448 $this->readPublicCalendars();
449 $this->readPrivateCalendars();
450 $this->readConsultationHoursCalendar();
451 $this->readBookingCalendar();
452
453 $this->readSelectedCategories(ilParticipants::_getMembershipByType($this->user_id, ['crs']));
454 $this->readSelectedCategories(ilParticipants::_getMembershipByType($this->user_id, ['grp']));
455 $this->readSelectedCategories(
456 $this->lookupRelevantTalkSeriesIds(),
457 0,
458 false
459 );
460
461 $this->addSubitemCalendars();
462 }
463
467 protected function readSelectedCalendar(int $a_cal_id): void
468 {
469 $cat = new ilCalendarCategory($a_cal_id);
470 if ($cat->getType() == ilCalendarCategory::TYPE_OBJ) {
471 $this->readSelectedCategories(array($cat->getObjId()));
472 $this->addSubitemCalendars();
473 } else {
474 $this->categories[] = $a_cal_id;
475 }
476 }
477
478 protected function readSelectedItemCalendars(): void
479 {
480 $this->readPublicCalendars();
481 $this->readPrivateCalendars();
482 $this->readConsultationHoursCalendar();
483 $this->readBookingCalendar();
484
485 $obj_ids = array();
486
487 $courses = array();
488 $groups = array();
489 $sessions = array();
490 $exercises = array();
491 foreach ($this->fav_rep->getFavouritesOfUser(
492 $this->user->getId(),
493 array('crs', 'grp', 'sess', 'exc')
494 ) as $item) {
495 if ($this->access->checkAccess('read', '', $item['ref_id'])) {
496 switch ($item['type']) {
497 case 'crs':
498 $courses[] = $item['obj_id'];
499 break;
500
501 case 'sess':
502 $sessions[] = $item['obj_id'];
503 break;
504
505 case 'grp':
506 $groups[] = $item['obj_id'];
507 break;
508
509 case 'exc':
510 $exercises[] = $item['obj_id'];
511 break;
512 }
513 }
514 }
515 $this->readSelectedCategories($courses);
516 $this->readSelectedCategories($sessions);
517 $this->readSelectedCategories($groups);
518 $this->readSelectedCategories($exercises);
519 $this->readSelectedCategories(
520 $this->lookupRelevantTalkSeriesIds(),
521 0,
522 false
523 );
524
525 $this->addSubitemCalendars();
526 }
527
531 protected function readReposCalendars($a_container_only = false): void
532 {
533 if (!$a_container_only) {
534 $this->readPublicCalendars();
535 $this->readPrivateCalendars();
536 //$this->readConsultationHoursCalendar($this->root_ref_id);
537 $this->readAllConsultationHoursCalendarOfContainer($this->root_ref_id);
538 }
539
540 #$query = "SELECT ref_id,obd.obj_id obj_id FROM tree t1 ".
541 # "JOIN object_reference obr ON t1.child = obr.ref_id ".
542 # "JOIN object_data obd ON obd.obj_id = obr.obj_id ".
543 # "WHERE t1.lft >= (SELECT lft FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
544 # "AND t1.lft <= (SELECT rgt FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
545 # "AND ".$ilDB->in('type',array('crs','grp','sess'),false,'text')." ".
546 # "AND tree = 1";
547
548 // alternative 1: do not aggregate items of current course
549 if (false) { //
550 $subtree_query = $GLOBALS['DIC']['tree']->getSubTreeQuery(
551 $this->root_ref_id,
552 array('object_reference.ref_id', 'object_data.obj_id'),
553 array('crs', 'grp', 'sess', 'exc')
554 );
555
556 $res = $this->db->query($subtree_query);
557 $obj_ids = array();
558 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
559 if ($this->tree->isDeleted((int) $row->ref_id)) {
560 continue;
561 }
562
563 $obj_type = ilObject::_lookupType((int) $row->obj_id);
564 if ($obj_type == 'crs' or $obj_type == 'grp') {
565 //Added for calendar revision --> https://goo.gl/CXGTRF
566 //In 5.2-trunk, the booking pools did not appear in the marginal calendar.
567 $this->readBookingCalendar();
568 // Check for global/local activation
569 if (!ilCalendarSettings::_getInstance()->lookupCalendarActivated((int) $row->obj_id)) {
570 continue;
571 }
572 }
573 if ($this->access->checkAccess('read', '', (int) $row->ref_id)) {
574 $obj_ids[] = (int) $row->obj_id;
575 }
576 }
577 $this->readSelectedCategories($obj_ids, $this->root_ref_id);
578 } else { // alternative 2: aggregate items of current course (discussion with timon 3.8.3017: this is the current preference)
579 $this->readSelectedCategories(array($this->root_obj_id), $this->root_ref_id);
580 }
581
582 if (!$a_container_only) {
583 $this->readSelectedCategories(ilParticipants::_getMembershipByType($this->user_id, ['crs']));
584 $this->readSelectedCategories(ilParticipants::_getMembershipByType($this->user_id, ['grp']));
585 $this->readSelectedCategories(
586 $this->lookupRelevantTalkSeriesIds(),
587 0,
588 false
589 );
590 }
591
592 $this->addSubitemCalendars();
593 }
594
595 public function readSingleCalendar(int $a_cat_id): void
596 {
597 $cat = new ilCalendarCategory($a_cat_id);
598 switch ($cat->getType()) {
600 $this->readSelectedCalendar($a_cat_id);
601 break;
602
604 $this->readPublicCalendars(array($a_cat_id));
605 break;
606
608 $this->readPrivateCalendars(array($a_cat_id));
609 break;
610
612 $this->readConsultationHoursCalendar($this->root_ref_id, $a_cat_id);
613 break;
614
616 $this->readBookingCalendar();
617 break;
618 }
619 }
620
624 protected function readPublicCalendars($cat_ids = null): void
625 {
626 $in = "";
627 if (is_array($cat_ids)) {
628 $in = " AND " . $this->db->in('cat_id', $cat_ids, false, 'integer') . " ";
629 }
630
631 // global categories
632 $query = "SELECT * FROM cal_categories " .
633 "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_GLOBAL, 'integer') . " " . $in .
634 "ORDER BY title ";
635
636 $res = $this->db->query($query);
637 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
638 $this->categories[] = (int) $row->cat_id;
639 $this->categories_info[(int) $row->cat_id]['obj_type'] = '';
640 $this->categories_info[(int) $row->cat_id]['source_ref_id'] = 0;
641 $this->categories_info[(int) $row->cat_id]['obj_id'] = (int) $row->obj_id;
642 $this->categories_info[(int) $row->cat_id]['cat_id'] = (int) $row->cat_id;
643 $this->categories_info[(int) $row->cat_id]['title'] = $row->title;
644 $this->categories_info[(int) $row->cat_id]['color'] = $row->color;
645 $this->categories_info[(int) $row->cat_id]['type'] = (int) $row->type;
646 $this->categories_info[(int) $row->cat_id]['editable'] = $this->rbacsystem->checkAccess(
647 'edit_event',
648 ilCalendarSettings::_getInstance()->getCalendarSettingsId()
649 );
650 $this->categories_info[(int) $row->cat_id]['settings'] = $this->rbacsystem->checkAccess(
651 'write',
652 ilCalendarSettings::_getInstance()->getCalendarSettingsId()
653 );
654 $this->categories_info[(int) $row->cat_id]['accepted'] = false;
655 $this->categories_info[(int) $row->cat_id]['remote'] = (int) $row->loc_type == ilCalendarCategory::LTYPE_REMOTE;
656 }
657 }
658
662 protected function readPrivateCalendars(?array $only_cat_ids = null): void
663 {
664 $cat_ids = [];
665 $in = "";
666 if (is_array($only_cat_ids)) {
667 $in = " AND " . $this->db->in('cat_id', $only_cat_ids, false, 'integer') . " ";
668 }
669
670 // First read private calendars of user
671 $query = "SELECT cat_id FROM cal_categories " .
672 "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " .
673 "AND obj_id = " . $this->db->quote($this->user->getId(), 'integer') . " " . $in;
674 $res = $this->db->query($query);
675 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
676 $cat_ids[] = (int) $row->cat_id;
677 }
678
679 // Read shared calendars
680 $accepted_ids = ilCalendarSharedStatus::getAcceptedCalendars($this->user->getId());
681 if (!$cat_ids = array_merge($cat_ids, $accepted_ids)) {
682 return;
683 }
684 if (is_array($only_cat_ids)) {
685 $cat_ids = array_filter($cat_ids, function ($id) use ($only_cat_ids) {
686 return in_array($id, $only_cat_ids);
687 });
688 }
689 // user categories
690 $query = "SELECT * FROM cal_categories " .
691 "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " .
692 "AND " . $this->db->in('cat_id', $cat_ids, false, 'integer') . " " .
693 "ORDER BY title ";
694
695 $res = $this->db->query($query);
696 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
697 $this->categories[] = (int) $row->cat_id;
698 $this->categories_info[(int) $row->cat_id]['obj_type'] = '';
699 $this->categories_info[(int) $row->cat_id]['source_ref_id'] = 0;
700 $this->categories_info[(int) $row->cat_id]['obj_id'] = (int) $row->obj_id;
701 $this->categories_info[(int) $row->cat_id]['cat_id'] = (int) $row->cat_id;
702 $this->categories_info[(int) $row->cat_id]['title'] = $row->title;
703 $this->categories_info[(int) $row->cat_id]['color'] = $row->color;
704 $this->categories_info[(int) $row->cat_id]['type'] = (int) $row->type;
705
706 if (in_array((int) $row->cat_id, $accepted_ids)) {
707 $shared = new ilCalendarShared((int) $row->cat_id);
708 if ($shared->isEditableForUser($this->user->getId())) {
709 $this->categories_info[(int) $row->cat_id]['editable'] = true;
710 } else {
711 $this->categories_info[(int) $row->cat_id]['editable'] = false;
712 }
713 } else {
714 $this->categories_info[(int) $row->cat_id]['editable'] = true;
715 }
716 if ($this->user->getId() == (int) $row->obj_id) {
717 $this->categories_info[(int) $row->cat_id]['settings'] = true;
718 } else {
719 $this->categories_info[(int) $row->cat_id]['settings'] = false;
720 }
721
722 $this->categories_info[(int) $row->cat_id]['accepted'] = in_array((int) $row->cat_id, $accepted_ids);
723 $this->categories_info[(int) $row->cat_id]['remote'] = ((int) $row->loc_type == ilCalendarCategory::LTYPE_REMOTE);
724 }
725 }
726
730 public function readAllConsultationHoursCalendarOfContainer(int $a_container_ref_id): void
731 {
732 $obj_id = ilObject::_lookupObjId($a_container_ref_id);
733 $participants = ilCourseParticipants::_getInstanceByObjId($obj_id);
734 $users = array_unique(array_merge($participants->getTutors(), $participants->getAdmins()));
735 $users = ilBookingEntry::lookupBookableUsersForObject([$obj_id], $users);
736 $old_ch = $this->getCHUserId();
737 foreach ($users as $user) {
738 $this->setCHUserId($user);
739 $this->readConsultationHoursCalendar($a_container_ref_id);
740 }
741 $this->setCHUserId($old_ch);
742 }
743
747 public function readConsultationHoursCalendar(?int $a_target_ref_id = null, int $a_cat_id = 0): void
748 {
749 if (!$this->getCHUserId()) {
750 $this->setCHUserId($this->user_id);
751 }
752
753 if ($a_target_ref_id) {
754 $target_obj_id = ilObject::_lookupObjId($a_target_ref_id);
755
756 $query = 'SELECT DISTINCT(cc.cat_id) FROM booking_entry be ' .
757 'LEFT JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
758 'JOIN cal_entries ce ON be.booking_id = ce.context_id ' .
759 'JOIN cal_cat_assignments ca ON ce.cal_id = ca.cal_id ' .
760 'JOIN cal_categories cc ON ca.cat_id = cc.cat_id ' .
761 'WHERE ((bo.target_obj_id IS NULL) OR bo.target_obj_id = ' . $this->db->quote(
762 $target_obj_id,
763 'integer'
764 ) . ' ) ';
765
766 // limit only to user if no cat id is given
767 if ($a_cat_id == 0) {
768 $query .= 'AND cc.obj_id = ' . $this->db->quote($this->getCHUserId(), 'integer');
769 }
770
771 $res = $this->db->query($query);
772 $categories = array();
773 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
774 if ($a_cat_id == 0 || (int) $row->cat_id == $a_cat_id) {
775 $categories[] = (int) $row->cat_id;
776 }
777 }
778
779 if ($categories) {
780 $query = 'SELECT * FROM cal_categories ' .
781 'WHERE ' . $this->db->in('cat_id', $categories, false, 'integer');
782 $res = $this->db->query($query);
783 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
784 $this->categories[] = (int) $row->cat_id;
785 $this->categories_info[(int) $row->cat_id]['obj_type'] = '';
786 $this->categories_info[(int) $row->cat_id]['source_ref_id'] = 0;
787 $this->categories_info[(int) $row->cat_id]['obj_id'] = (int) $row->obj_id;
788 $this->categories_info[(int) $row->cat_id]['cat_id'] = (int) $row->cat_id;
789 $this->categories_info[(int) $row->cat_id]['title'] = ilObjUser::_lookupFullname((int) $row->obj_id);
790 $this->categories_info[(int) $row->cat_id]['color'] = $row->color;
791 $this->categories_info[(int) $row->cat_id]['type'] = (int) $row->type;
792 $this->categories_info[(int) $row->cat_id]['editable'] = false;
793 $this->categories_info[(int) $row->cat_id]['settings'] = false;
794 $this->categories_info[(int) $row->cat_id]['accepted'] = false;
795 $this->categories_info[(int) $row->cat_id]['remote'] = false;
796 }
797 }
798 } else { // no category given
799 $filter = ($a_cat_id > 0)
800 ? " AND cat_id = " . $this->db->quote($a_cat_id, "integer")
801 : " AND obj_id = " . $this->db->quote($this->getCHUserId(), 'integer');
802
803 $query = "SELECT * FROM cal_categories cc " .
804 "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_CH, 'integer') . ' ' . $filter;
805 $res = $this->db->query($query);
806 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
807 $this->categories[] = (int) $row->cat_id;
808 $this->categories_info[(int) $row->cat_id]['obj_type'] = '';
809 $this->categories_info[(int) $row->cat_id]['source_ref_id'] = 0;
810 $this->categories_info[(int) $row->cat_id]['obj_id'] = (int) $row->obj_id;
811 $this->categories_info[(int) $row->cat_id]['cat_id'] = (int) $row->cat_id;
812 $this->categories_info[(int) $row->cat_id]['title'] = $row->title;
813 $this->categories_info[(int) $row->cat_id]['color'] = $row->color;
814 $this->categories_info[(int) $row->cat_id]['type'] = (int) $row->type;
815 $this->categories_info[(int) $row->cat_id]['editable'] = false;
816 $this->categories_info[(int) $row->cat_id]['settings'] = false;
817 $this->categories_info[(int) $row->cat_id]['accepted'] = false;
818 $this->categories_info[(int) $row->cat_id]['remote'] = false;
819 }
820 }
821 }
822
826 public function readBookingCalendar(?int $user_id = null): void
827 {
828 if (!$user_id) {
830 }
831
832 $query = "SELECT * FROM cal_categories " .
833 "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_BOOK, 'integer') . ' ' .
834 "AND obj_id = " . $this->db->quote($user_id, 'integer');
835 $res = $this->db->query($query);
836 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
837 $this->categories[] = (int) $row->cat_id;
838 $this->categories_info[(int) $row->cat_id]['source_ref_id'] = 0;
839 $this->categories_info[(int) $row->cat_id]['obj_type'] = '';
840 $this->categories_info[(int) $row->cat_id]['obj_id'] = (int) $row->obj_id;
841 $this->categories_info[(int) $row->cat_id]['cat_id'] = (int) $row->cat_id;
842 $this->categories_info[(int) $row->cat_id]['title'] = $row->title;
843 $this->categories_info[(int) $row->cat_id]['color'] = $row->color;
844 $this->categories_info[(int) $row->cat_id]['type'] = (int) $row->type;
845 $this->categories_info[(int) $row->cat_id]['editable'] = false;
846 $this->categories_info[(int) $row->cat_id]['settings'] = false;
847 $this->categories_info[(int) $row->cat_id]['accepted'] = false;
848 $this->categories_info[(int) $row->cat_id]['remote'] = false;
849 }
850 }
851
852 protected function readSelectedCategories(array $a_obj_ids, int $a_source_ref_id = 0, bool $check_permissions = true): void
853 {
854 if (!count($a_obj_ids)) {
855 return;
856 }
857
858 $query = "SELECT * FROM cal_categories " .
859 "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_OBJ, 'integer') . " " .
860 "AND " . $this->db->in('obj_id', $a_obj_ids, false, 'integer') . " " .
861 "ORDER BY title ";
862
863 $res = $this->db->query($query);
864 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
865 // check activation/deactivation
866 $obj_type = ilObject::_lookupType((int) $row->obj_id);
867 if ($obj_type == 'crs' or $obj_type == 'grp') {
868 if (!ilCalendarSettings::_getInstance()->lookupCalendarActivated((int) $row->obj_id)) {
869 continue;
870 }
871 }
872
873 $editable = false;
874 $exists = false;
875 $settings = false;
876 foreach (ilObject::_getAllReferences((int) $row->obj_id) as $ref_id) {
877 if ($this->access->checkAccess('edit_event', '', $ref_id)) {
878 $settings = true;
879 }
880 if ($this->access->checkAccess('edit_event', '', $ref_id)) {
881 $exists = true;
882 $editable = true;
883 break;
884 } elseif ($this->access->checkAccess('read', '', $ref_id)) {
885 $exists = true;
886 }
887 }
888 if (!$exists && $check_permissions) {
889 continue;
890 }
891 $this->categories_info[(int) $row->cat_id]['editable'] = $editable;
892 $this->categories_info[(int) $row->cat_id]['accepted'] = false;
893 $this->categories_info[(int) $row->cat_id]['settings'] = $settings;
894
895 $this->categories[] = (int) $row->cat_id;
896 $this->categories_info[(int) $row->cat_id]['obj_type'] = ilObject::_lookupType((int) $row->obj_id);
897 $this->categories_info[(int) $row->cat_id]['obj_id'] = (int) $row->obj_id;
898 $this->categories_info[(int) $row->cat_id]['cat_id'] = (int) $row->cat_id;
899 $this->categories_info[(int) $row->cat_id]['color'] = $row->color;
900 #$this->categories_info[$row->cat_id]['title'] = ilObject::_lookupTitle($row->obj_id);
901 $this->categories_info[(int) $row->cat_id]['title'] = $row->title;
902 $this->categories_info[(int) $row->cat_id]['type'] = (int) $row->type;
903 $this->categories_info[(int) $row->cat_id]['remote'] = false;
904 $this->categories_info[(int) $row->cat_id]['source_ref_id'] = $a_source_ref_id;
905 }
906 }
907
912 protected function addSubitemCalendars(): void
913 {
914 $course_ids = array();
915 foreach ($this->categories as $cat_id) {
916 if (isset($this->categories_info[$cat_id]['obj_type']) &&
917 in_array($this->categories_info[$cat_id]['obj_type'], ['crs', 'grp', 'tals'])) {
918 $course_ids[] = $this->categories_info[$cat_id]['obj_id'];
919 }
920 }
921
922 $query = "SELECT od2.obj_id sess_id, od1.obj_id crs_id,cat_id, or2.ref_id sess_ref_id, od2.type FROM object_data od1 " .
923 "JOIN object_reference or1 ON od1.obj_id = or1.obj_id " .
924 "JOIN tree t ON or1.ref_id = t.parent " .
925 "JOIN object_reference or2 ON t.child = or2.ref_id " .
926 "JOIN object_data od2 ON or2.obj_id = od2.obj_id " .
927 "JOIN cal_categories cc ON od2.obj_id = cc.obj_id " .
928 "WHERE " . $this->db->in('od2.type', array('sess', 'exc', 'etal'), false, 'text') .
929 "AND (od1.type = 'crs' OR od1.type = 'grp' OR od1.type = 'tals') " .
930 "AND " . $this->db->in('od1.obj_id', $course_ids, false, 'integer') . ' ' .
931 "AND or2.deleted IS NULL";
932
933 $res = $this->db->query($query);
934 $cat_ids = array();
935 $course_sessions = array();
936 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
937 if ($row->type !== 'etal') {
938 if (
939 !$this->access->checkAccessOfUser($this->user_id, 'read', '', (int) $row->sess_ref_id) ||
940 !$this->access->checkAccessOfUser($this->user_id, 'visible', '', (int) $row->sess_ref_id)
941 ) {
942 continue;
943 }
944 }
945 $cat_ids[] = (int) $row->cat_id;
946 $course_sessions[(int) $row->crs_id][(int) $row->sess_id] = (int) $row->cat_id;
947 $this->subitem_categories[] = (int) $row->cat_id;
948 }
949
950 foreach ($this->categories as $cat_id) {
951 if (
952 (isset($this->categories_info[$cat_id]['obj_type']) &&
953 in_array($this->categories_info[$cat_id]['obj_type'], ['crs', 'grp', 'tals'])) &&
954 isset($this->categories_info[$cat_id]['obj_id']) &&
955 isset($course_sessions[$this->categories_info[$cat_id]['obj_id']]) &&
956 is_array($course_sessions[$this->categories_info[$cat_id]['obj_id']])) {
957 foreach ($course_sessions[$this->categories_info[$cat_id]['obj_id']] as $sess_id => $sess_cat_id) {
958 $this->categories_info[$cat_id]['subitem_ids'][$sess_id] = $sess_cat_id;
959 $this->categories_info[$cat_id]['subitem_obj_ids'][$sess_cat_id] = $sess_id;
960 }
961 } else {
962 $this->categories_info[$cat_id]['subitem_ids'] = array();
963 $this->categories_info[$cat_id]['subitem_obj_ids'] = array();
964 }
965 }
966 }
967
971 protected function lookupRelevantTalkSeriesIds(): array
972 {
973 $repository = new IliasDBEmployeeTalkSeriesRepository($this->user, $this->db);
974 $talks = $repository->findByOwnerAndEmployee();
975 return array_map(function (ilObjEmployeeTalkSeries $item) {
976 return $item->getId();
977 }, $talks);
978 }
979
984 public static function lookupPrivateCategories(int $a_user_id): array
985 {
986 global $DIC;
987
988 $ilDB = $DIC['ilDB'];
989
990 // First read private calendars of user
991 $set = $ilDB->query("SELECT * FROM cal_categories " .
992 "WHERE type = " . $ilDB->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " .
993 "AND obj_id = " . $ilDB->quote($a_user_id, 'integer'));
994 $cats = array();
995
996 while ($rec = $ilDB->fetchAssoc($set)) {
997 $rec['cat_id'] = (int) $rec['cat_id'];
998 $rec['obj_id'] = (int) $rec['obj_id'];
999 $rec['type'] = (int) $rec['type'];
1000 $rec['loc_type'] = (int) $rec['loc_type'];
1001 $cats[] = $rec;
1002 }
1003 return $cats;
1004 }
1005}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
class for calendar categories
readConsultationHoursCalendar(?int $a_target_ref_id=null, int $a_cat_id=0)
Read personal consultation hours calendar.
readSelectedCategories(array $a_obj_ids, int $a_source_ref_id=0, bool $check_permissions=true)
readPDCalendars()
Read categories of user.
static _isOwner(int $a_usr_id, int $a_cal_id)
check if user is owner of a category
getNotificationCalendars()
Get all calendars that allow send of notifications (Editable and course group calendars)
isEditable(int $a_cat_id)
check if category is editable
readBookingCalendar(?int $user_id=null)
Read booking manager calendar.
static lookupPrivateCategories(int $a_user_id)
Lookup private categories of user.
readPrivateCalendars(?array $only_cat_ids=null)
Read private calendars.
initialize(int $a_mode, int $a_source_ref_id=0, bool $a_use_cache=false, int $a_cat_id=0)
initialize visible categories
static deleteRepositoryCache(int $a_usr_id)
Delete cache.
addSubitemCalendars()
Add subitem calendars E.g.
__construct(int $a_usr_id=0)
Singleton instance.
isVisible($a_cat_id)
check if category is visible
sleep()
Serialize categories.
static _lookupCategoryIdByObjId(int $a_obj_id)
lookup category by obj_id
readReposCalendars($a_container_only=false)
Read available repository calendars.
readAllConsultationHoursCalendarOfContainer(int $a_container_ref_id)
Read personal consultation hours calendar of all tutors for a container.
wakeup(string $a_ser)
Load from serialize string.
readPublicCalendars($cat_ids=null)
Read public calendars.
setCHUserId(int $a_user_id)
Set ch user id.
getCategories(bool $a_include_subitem_calendars=false)
static ilCalendarCategories $instance
static _getInstance($a_usr_id=0)
get singleton instance
static deletePDItemsCache(int $a_usr_id)
Delete cache (add remove desktop item)
ilFavouritesDBRepository $fav_rep
readSelectedCalendar(int $a_cal_id)
Read info about selected calendar.
Stores calendar categories.
static getAcceptedCalendars(int $a_usr_id)
Handles shared calendars.
static _getInstanceByObjId(int $a_obj_id)
language handling
Component logger with individual log levels by component id.
User class.
static _lookupFullname(int $a_user_id)
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static _getMembershipByType(int $a_usr_id, array $a_type, bool $a_only_member_role=false)
get membership by type Get course or group membership
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
$info
Definition: entry_point.php:21
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
Interface ilDBInterface.
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
$ref_id
Definition: ltiauth.php:66
$res
Definition: ltiservices.php:69
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54