ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilCalendarCategories.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24
35{
36 const MODE_REPOSITORY = 2; // course/group full calendar view (allows to select other calendars)
40 const MODE_MANAGE = 6;
44 const MODE_REPOSITORY_CONTAINER_ONLY = 10; // course/group content view (side block, focus on course/group appointments only)
46
47 protected static $instance = null;
48
49 protected $db;
50
51 protected $user_id;
52
53 protected $mode = 0;
54
55 protected $categories = array();
56 protected $categories_info = array();
57 protected $subitem_categories = array();
58
59 protected $root_ref_id = 0;
60 protected $root_obj_id = 0;
61
62
63 protected $ch_user_id = 0;
64 protected $target_ref_id = 0;
65
69 protected $logger = null;
70
74 protected $fav_rep;
75
83 public function __construct($a_usr_id = 0)
84 {
85 global $DIC;
86
87 $ilUser = $DIC['ilUser'];
88 $ilDB = $DIC['ilDB'];
89
90 $this->logger = $GLOBALS['DIC']->logger()->cal();
91
92 $this->user_id = $a_usr_id;
93 if (!$this->user_id) {
94 $this->user_id = $ilUser->getId();
95 }
96 $this->db = $ilDB;
97
98 $this->fav_rep = new ilFavouritesDBRepository();
99 }
100
109 public static function _getInstance($a_usr_id = 0)
110 {
111 if (self::$instance) {
112 return self::$instance;
113 }
114 return self::$instance = new ilCalendarCategories($a_usr_id);
115 }
116
125 public static function _lookupCategoryIdByObjId($a_obj_id)
126 {
127 global $DIC;
128
129 $ilDB = $DIC['ilDB'];
130
131 $query = "SELECT cat_id FROM cal_categories " .
132 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
133 "AND type = " . $ilDB->quote(ilCalendarCategory::TYPE_OBJ, 'integer') . " ";
134
135 $res = $ilDB->query($query);
136 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
137 return $row->cat_id;
138 }
139 return 0;
140 }
141
142
152 public static function _isOwner($a_usr_id, $a_cal_id)
153 {
154 global $DIC;
155
156 $ilDB = $DIC['ilDB'];
157
158 $query = "SELECT * FROM cal_categories " .
159 "WHERE cat_id = " . $ilDB->quote($a_cal_id, 'integer') . " " .
160 "AND obj_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
161 "AND type = " . $ilDB->quote(ilCalendarCategory::TYPE_USR, 'integer') . " ";
162 $res = $ilDB->query($query);
163 return $res->numRows() ? true : false;
164 }
165
171 public static function deletePDItemsCache($a_usr_id)
172 {
173 ilCalendarCache::getInstance()->deleteByAdditionalKeys(
174 $a_usr_id,
175 self::MODE_PERSONAL_DESKTOP_ITEMS,
176 'categories'
177 );
178 }
179
185 public static function deleteRepositoryCache($a_usr_id)
186 {
187 ilCalendarCache::getInstance()->deleteByAdditionalKeys(
188 $a_usr_id,
189 self::MODE_REPOSITORY,
190 'categories'
191 );
192 }
193
194
199 protected function sleep()
200 {
201 return serialize(
202 array(
203 'categories' => $this->categories,
204 'categories_info' => $this->categories_info,
205 'subitem_categories' => $this->subitem_categories
206 )
207 );
208 }
209
215 protected function wakeup($a_ser)
216 {
217 $info = unserialize($a_ser);
218
219 $this->categories = $info['categories'];
220 $this->categories_info = $info['categories_info'];
221 $this->subitem_categories = $info['subitem_categories'];
222 }
223
228 public function setCHUserId($a_user_id)
229 {
230 $this->ch_user_id = $a_user_id;
231 }
232
233
238 public function getCHUserId()
239 {
240 return $this->ch_user_id;
241 }
242
243 protected function setMode($a_mode)
244 {
245 $this->mode = $a_mode;
246 }
247
248 public function getMode()
249 {
250 return $this->mode;
251 }
252
253 protected function setTargetRefId($a_ref_id)
254 {
255 $this->target_ref_id = $a_ref_id;
256 }
257
258 public function getTargetRefId()
259 {
261 }
262
268 public function setSourceRefId($a_val)
269 {
270 $this->root_ref_id = $a_val;
271 }
272
278 public function getSourceRefId()
279 {
280 return $this->root_ref_id;
281 }
282
291 public function initialize($a_mode, $a_source_ref_id = 0, $a_use_cache = false, $a_cat_id = 0)
292 {
293 if ($this->getMode() != 0) {
294 include_once("./Services/Calendar/exceptions/class.ilCalCategoriesInitializedMultipleException.php");
295 throw new ilCalCategoriesInitializedMultipleException("ilCalendarCategories is initialized multiple times for user " . $this->user_id . ".");
296 }
297
298 $this->setMode($a_mode);
299
300 // see comments in https://mantis.ilias.de/view.php?id=25254
301 if ($a_use_cache && $this->getMode() != self::MODE_REPOSITORY_CONTAINER_ONLY) {
302 // Read categories from cache
303 if ($cats = ilCalendarCache::getInstance()->getEntry($this->user_id . ':' . $a_mode . ':categories:' . (int) $a_source_ref_id)) {
304 if ($this->getMode() != self::MODE_REPOSITORY &&
305 $this->getMode() != self::MODE_CONSULTATION &&
306 $this->getMode() != self::MODE_PORTFOLIO_CONSULTATION) {
307 $this->wakeup($cats);
308 return;
309 }
310 }
311 }
312
313 switch ($this->getMode()) {
315 include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
317 $this->readPDCalendars();
318 } else {
320 }
321 break;
322
324 $this->readSelectedCalendar($a_source_ref_id);
325 break;
326
328 $this->readPDCalendars();
329 break;
330
333 break;
334
336 $this->root_ref_id = $a_source_ref_id;
337 $this->root_obj_id = ilObject::_lookupObjId($this->root_ref_id);
338 $this->readReposCalendars();
339 break;
340
342 $this->root_ref_id = $a_source_ref_id;
343 $this->root_obj_id = ilObject::_lookupObjId($this->root_ref_id);
344 $this->readReposCalendars(true);
345 break;
346
348 $this->readPDCalendars();
350 break;
351
353 #$this->readPrivateCalendars();
354 $this->setTargetRefId($a_source_ref_id);
355 $this->readConsultationHoursCalendar($a_source_ref_id);
356 break;
357
360 break;
361
363 $this->readSingleCalendar($a_cat_id);
364 break;
365 }
366
367 if ($a_use_cache) {
368 // Store in cache
369 ilCalendarCache::getInstance()->storeEntry(
370 $this->user_id . ':' . $a_mode . ':categories:' . (int) $a_source_ref_id,
371 $this->sleep(),
372 $this->user_id,
373 $a_mode,
374 'categories'
375 );
376 }
377 }
378
386 public function getCategoryInfo($a_cat_id)
387 {
388 if (isset($this->categories_info[$a_cat_id])) {
389 return $this->categories_info[$a_cat_id];
390 }
391
392 if (in_array($a_cat_id, (array) $this->subitem_categories)) {
393 foreach ($this->categories as $cat_id) {
394 if (in_array($a_cat_id, $this->categories_info[$cat_id]['subitem_ids'])) {
395 return $this->categories_info[$cat_id];
396 }
397 }
398 }
399 }
400
401
409 public function getCategoriesInfo()
410 {
411 return $this->categories_info ? $this->categories_info : array();
412 }
413
420 public function getCategories($a_include_subitem_calendars = false)
421 {
422 if ($a_include_subitem_calendars) {
423 return array_merge((array) $this->categories, (array) $this->subitem_categories);
424 }
425
426 return $this->categories ? $this->categories : array();
427 }
428
435 public function getSubitemCategories($a_cat_id)
436 {
437 if (!isset($this->categories_info[$a_cat_id]['subitem_ids'])) {
438 return array($a_cat_id);
439 }
440 return array_merge((array) $this->categories_info[$a_cat_id]['subitem_ids'], array($a_cat_id));
441 }
442
443
452 {
453 global $DIC;
454
455 $lng = $DIC['lng'];
456
457 $has_personal_calendar = false;
458 foreach ($this->categories_info as $info) {
459 if ($info['obj_type'] == 'sess' || $info['obj_type'] == 'exc') {
460 continue;
461 }
462 if ($info['type'] == ilCalendarCategory::TYPE_USR and $info['editable']) {
463 $has_personal_calendar = true;
464 }
465
466 if ($info['editable']) {
467 $cats[$info['cat_id']] = $info['title'];
468 }
469 }
470 // If there
471 if (!$has_personal_calendar) {
472 $cats[0] = $lng->txt('cal_default_calendar');
473 }
474 return $cats ? $cats : array();
475 }
476
482 public function getNotificationCalendars()
483 {
484 $not = array();
485 foreach ($this->categories_info as $info) {
486 if ($info['type'] == ilCalendarCategory::TYPE_OBJ and $info['editable'] == true) {
487 if (ilObject::_lookupType($info['obj_id']) == 'crs' or ilObject::_lookupType($info['obj_id']) == 'grp') {
488 $not[] = $info['cat_id'];
489 }
490 }
491 }
492 return $not;
493 }
494
502 public function isEditable($a_cat_id)
503 {
504 return isset($this->categories_info[$a_cat_id]['editable']) and $this->categories_info[$a_cat_id]['editable'];
505 }
506
514 public function isVisible($a_cat_id)
515 {
516 return in_array($a_cat_id, $this->categories) or
517 in_array($a_cat_id, (array) $this->subitem_categories);
518 }
519
520
521
522
530 protected function readPDCalendars()
531 {
532 global $DIC;
533
534 $rbacsystem = $DIC['rbacsystem'];
535
536
537 $this->readPublicCalendars();
538 $this->readPrivateCalendars();
540 $this->readBookingCalendar();
541
542 include_once('./Services/Membership/classes/class.ilParticipants.php');
545
546 $this->addSubitemCalendars();
547 }
548
553 protected function readSelectedCalendar($a_cal_id)
554 {
555 include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
556 $cat = new ilCalendarCategory($a_cal_id);
557 if ($cat->getType() == ilCalendarCategory::TYPE_OBJ) {
558 $this->readSelectedCategories(array($cat->getObjId()));
559 $this->addSubitemCalendars();
560 } else {
561 $this->categories[] = $a_cal_id;
562 }
563 }
564
571 protected function readSelectedItemCalendars()
572 {
573 global $DIC;
574
575 $ilUser = $DIC['ilUser'];
576 $ilAccess = $DIC['ilAccess'];
577
578 $this->readPublicCalendars();
579 $this->readPrivateCalendars();
581 $this->readBookingCalendar();
582
583 $obj_ids = array();
584
585 $courses = array();
586 $groups = array();
587 $sessions = array();
588 $exercises = array();
589 foreach ($this->fav_rep->getFavouritesOfUser($ilUser->getId(), array('crs','grp','sess','exc')) as $item) {
590 if ($ilAccess->checkAccess('read', '', $item['ref_id'])) {
591 switch ($item['type']) {
592 case 'crs':
593 $courses[] = $item['obj_id'];
594 break;
595
596 case 'sess':
597 $sessions[] = $item['obj_id'];
598 break;
599
600 case 'grp':
601 $groups[] = $item['obj_id'];
602 break;
603
604 case 'exc':
605 $exercises[] = $item['obj_id'];
606 break;
607 }
608 }
609 }
610 $this->readSelectedCategories($courses);
611 $this->readSelectedCategories($sessions);
612 $this->readSelectedCategories($groups);
613 $this->readSelectedCategories($exercises);
614
615 $this->addSubitemCalendars();
616 }
617
625 protected function readReposCalendars($a_container_only = false)
626 {
627 global $DIC;
628
629 $ilAccess = $DIC['ilAccess'];
630 $tree = $DIC['tree'];
631 global $DIC;
632
633 $ilDB = $DIC['ilDB'];
634
635 if (!$a_container_only) {
636 $this->readPublicCalendars();
637 $this->readPrivateCalendars();
638 //$this->readConsultationHoursCalendar($this->root_ref_id);
639 $this->readAllConsultationHoursCalendarOfContainer($this->root_ref_id);
640 }
641
642
643
644 #$query = "SELECT ref_id,obd.obj_id obj_id FROM tree t1 ".
645 # "JOIN object_reference obr ON t1.child = obr.ref_id ".
646 # "JOIN object_data obd ON obd.obj_id = obr.obj_id ".
647 # "WHERE t1.lft >= (SELECT lft FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
648 # "AND t1.lft <= (SELECT rgt FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
649 # "AND ".$ilDB->in('type',array('crs','grp','sess'),false,'text')." ".
650 # "AND tree = 1";
651
652 // alternative 1: do not aggregate items of current course
653 if (!true) { //
654 $subtree_query = $GLOBALS['DIC']['tree']->getSubTreeQuery(
655 $this->root_ref_id,
656 array('object_reference.ref_id', 'object_data.obj_id'),
657 array('crs', 'grp', 'sess', 'exc')
658 );
659
660 $res = $ilDB->query($subtree_query);
661 $obj_ids = array();
662 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
663 if ($tree->isDeleted($row->ref_id)) {
664 continue;
665 }
666
667 $obj_type = ilObject::_lookupType($row->obj_id);
668 if ($obj_type == 'crs' or $obj_type == 'grp') {
669 //Added for calendar revision --> https://goo.gl/CXGTRF
670 //In 5.2-trunk, the booking pools did not appear in the marginal calendar.
671 $this->readBookingCalendar();
672 // Check for global/local activation
673 if (!ilCalendarSettings::_getInstance()->lookupCalendarActivated($row->obj_id)) {
674 continue;
675 }
676 }
677 if ($ilAccess->checkAccess('read', '', $row->ref_id)) {
678 $obj_ids[] = $row->obj_id;
679 }
680 }
681 $this->readSelectedCategories($obj_ids, $this->root_ref_id);
682 } else { // alternative 2: aggregate items of current course (discussion with timon 3.8.3017: this is the current preference)
683 $this->readSelectedCategories(array($this->root_obj_id), $this->root_ref_id);
684 }
685
686 $this->addSubitemCalendars();
687
688
689 if (!$a_container_only) {
692 }
693 }
694
695 public function readSingleCalendar($a_cat_id)
696 {
697 include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
698 $cat = new ilCalendarCategory($a_cat_id);
699 switch ($cat->getType()) {
701 $this->readSelectedCalendar($a_cat_id);
702 break;
703
705 $this->readPublicCalendars(array($a_cat_id));
706 break;
707
709 $this->readPrivateCalendars(array($a_cat_id));
710 break;
711
713 $this->readConsultationHoursCalendar($this->root_ref_id, $a_cat_id);
714 break;
715
717 $this->readBookingCalendar();
718 break;
719 }
720 }
721
728 protected function readPublicCalendars($cat_ids = null)
729 {
730 global $DIC;
731
732 $rbacsystem = $DIC['rbacsystem'];
733 $ilAccess = $DIC['ilAccess'];
734
735 $in = "";
736 if (is_array($cat_ids)) {
737 $in = " AND " . $this->db->in('cat_id', $cat_ids, false, 'integer') . " ";
738 }
739
740 // global categories
741 $query = "SELECT * FROM cal_categories " .
742 "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_GLOBAL, 'integer') . " " . $in .
743 "ORDER BY title ";
744
745 $res = $this->db->query($query);
746 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
747 $this->categories[] = $row->cat_id;
748 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
749 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
750 $this->categories_info[$row->cat_id]['title'] = $row->title;
751 $this->categories_info[$row->cat_id]['color'] = $row->color;
752 $this->categories_info[$row->cat_id]['type'] = $row->type;
753 $this->categories_info[$row->cat_id]['editable'] = $rbacsystem->checkAccess('edit_event', ilCalendarSettings::_getInstance()->getCalendarSettingsId());
754 $this->categories_info[$row->cat_id]['settings'] = $rbacsystem->checkAccess('write', ilCalendarSettings::_getInstance()->getCalendarSettingsId());
755 $this->categories_info[$row->cat_id]['accepted'] = false;
756 $this->categories_info[$row->cat_id]['remote'] = ($row->loc_type == ilCalendarCategory::LTYPE_REMOTE);
757 }
758
759 return true;
760 }
761
768 protected function readPrivateCalendars($only_cat_ids = null)
769 {
770 global $DIC;
771
772 $ilUser = $DIC['ilUser'];
773 global $DIC;
774
775 $ilDB = $DIC['ilDB'];
776
777 $in = "";
778 if (is_array($only_cat_ids)) {
779 $in = " AND " . $this->db->in('cat_id', $only_cat_ids, false, 'integer') . " ";
780 }
781
782 // First read private calendars of user
783 $query = "SELECT cat_id FROM cal_categories " .
784 "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " .
785 "AND obj_id = " . $this->db->quote($ilUser->getId(), 'integer') . " " . $in;
786 $res = $this->db->query($query);
787 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
788 $cat_ids[] = $row->cat_id;
789 }
790
791 // Read shared calendars
792 include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
794 if (!$cat_ids = array_merge((array) $cat_ids, $accepted_ids)) {
795 return true;
796 }
797
798 if (is_array($only_cat_ids)) {
799 $cat_ids = array_filter($cat_ids, function ($id) use ($only_cat_ids) {
800 return in_array($id, $only_cat_ids);
801 });
802 }
803
804 // user categories
805 $query = "SELECT * FROM cal_categories " .
806 "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " .
807 "AND " . $ilDB->in('cat_id', $cat_ids, false, 'integer') . " " .
808 "ORDER BY title ";
809
810 $res = $this->db->query($query);
811 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
812 $this->categories[] = $row->cat_id;
813 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
814 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
815 $this->categories_info[$row->cat_id]['title'] = $row->title;
816 $this->categories_info[$row->cat_id]['color'] = $row->color;
817 $this->categories_info[$row->cat_id]['type'] = $row->type;
818
819 include_once './Services/Calendar/classes/class.ilCalendarShared.php';
820 if (in_array($row->cat_id, $accepted_ids)) {
821 $shared = new ilCalendarShared($row->cat_id);
822 if ($shared->isEditableForUser($ilUser->getId())) {
823 $this->categories_info[$row->cat_id]['editable'] = true;
824 } else {
825 $this->categories_info[$row->cat_id]['editable'] = false;
826 }
827 } else {
828 $this->categories_info[$row->cat_id]['editable'] = true;
829 }
830 if ($ilUser->getId() == $row->obj_id) {
831 $this->categories_info[$row->cat_id]['settings'] = true;
832 } else {
833 $this->categories_info[$row->cat_id]['settings'] = false;
834 }
835
836 $this->categories_info[$row->cat_id]['accepted'] = in_array($row->cat_id, $accepted_ids);
837 $this->categories_info[$row->cat_id]['remote'] = ($row->loc_type == ilCalendarCategory::LTYPE_REMOTE);
838 }
839 }
840
845 public function readAllConsultationHoursCalendarOfContainer($a_container_ref_id)
846 {
847 include_once "Modules/Course/classes/class.ilCourseParticipants.php";
848 $obj_id = ilObject::_lookupObjId($a_container_ref_id);
849 $participants = ilCourseParticipants::_getInstanceByObjId($obj_id);
850 $users = array_unique(array_merge($participants->getTutors(), $participants->getAdmins()));
851 include_once 'Services/Booking/classes/class.ilBookingEntry.php';
852 $users = ilBookingEntry::lookupBookableUsersForObject($obj_id, $users);
853 $old_ch = $this->getCHUserId();
854 foreach ($users as $user) {
855 $this->setCHUserId($user);
856 $this->readConsultationHoursCalendar($a_container_ref_id);
857 }
858 $this->setCHUserId($old_ch);
859 }
860
866 public function readConsultationHoursCalendar($a_target_ref_id = null, $a_cat_id = 0)
867 {
868 global $DIC;
869
870 $ilDB = $DIC['ilDB'];
871 $lng = $DIC['lng'];
872
873 if (!$this->getCHUserId()) {
874 $this->setCHUserId($this->user_id);
875 }
876
877 if ($a_target_ref_id) {
878 $target_obj_id = ilObject::_lookupObjId($a_target_ref_id);
879
880 $query = 'SELECT DISTINCT(cc.cat_id) FROM booking_entry be ' .
881 'LEFT JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
882 'JOIN cal_entries ce ON be.booking_id = ce.context_id ' .
883 'JOIN cal_cat_assignments ca ON ce.cal_id = ca.cal_id ' .
884 'JOIN cal_categories cc ON ca.cat_id = cc.cat_id ' .
885 'WHERE ((bo.target_obj_id IS NULL) OR bo.target_obj_id = ' . $ilDB->quote($target_obj_id, 'integer') . ' ) ';
886
887 // limit only to user if no cat id is given
888 if ($a_cat_id == 0) {
889 $query .= 'AND cc.obj_id = ' . $ilDB->quote($this->getCHUserId(), 'integer');
890 }
891
892
893 $res = $ilDB->query($query);
894 $categories = array();
895 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
896 if ($a_cat_id == 0 || $row->cat_id == $a_cat_id) {
897 $categories[] = $row->cat_id;
898 }
899 }
900
901 if ($categories) {
902 $query = 'SELECT * FROM cal_categories ' .
903 'WHERE ' . $ilDB->in('cat_id', $categories, false, 'integer');
904 $res = $ilDB->query($query);
905 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
906 $this->categories[] = $row->cat_id;
907 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
908 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
909 $this->categories_info[$row->cat_id]['title'] = ilObjUser::_lookupFullname($row->obj_id);
910 $this->categories_info[$row->cat_id]['color'] = $row->color;
911 $this->categories_info[$row->cat_id]['type'] = $row->type;
912 $this->categories_info[$row->cat_id]['editable'] = false;
913 $this->categories_info[$row->cat_id]['settings'] = false;
914 $this->categories_info[$row->cat_id]['accepted'] = false;
915 $this->categories_info[$row->cat_id]['remote'] = false;
916 }
917 }
918 } else { // no category given
919 $filter = ($a_cat_id > 0)
920 ? " AND cat_id = " . $ilDB->quote($a_cat_id, "integer")
921 : " AND obj_id = " . $ilDB->quote($this->getCHUserId(), 'integer');
922
923 $query = "SELECT * FROM cal_categories cc " .
924 "WHERE type = " . $ilDB->quote(ilCalendarCategory::TYPE_CH, 'integer') . ' ' . $filter;
925 $res = $ilDB->query($query);
926 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
927 $this->categories[] = $row->cat_id;
928 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
929 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
930 $this->categories_info[$row->cat_id]['title'] = $row->title;
931 $this->categories_info[$row->cat_id]['color'] = $row->color;
932 $this->categories_info[$row->cat_id]['type'] = $row->type;
933 $this->categories_info[$row->cat_id]['editable'] = false;
934 $this->categories_info[$row->cat_id]['settings'] = false;
935 $this->categories_info[$row->cat_id]['accepted'] = false;
936 $this->categories_info[$row->cat_id]['remote'] = false;
937 }
938 }
939 return true;
940 }
941
947 public function readBookingCalendar($user_id = null)
948 {
949 global $DIC;
950
951 $ilDB = $DIC['ilDB'];
952
953 if (!$user_id) {
955 }
956
957 $query = "SELECT * FROM cal_categories " .
958 "WHERE type = " . $ilDB->quote(ilCalendarCategory::TYPE_BOOK, 'integer') . ' ' .
959 "AND obj_id = " . $ilDB->quote($user_id, 'integer');
960 $res = $ilDB->query($query);
961 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
962 $this->categories[] = $row->cat_id;
963 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
964 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
965 $this->categories_info[$row->cat_id]['title'] = $row->title;
966 $this->categories_info[$row->cat_id]['color'] = $row->color;
967 $this->categories_info[$row->cat_id]['type'] = $row->type;
968 $this->categories_info[$row->cat_id]['editable'] = false;
969 $this->categories_info[$row->cat_id]['settings'] = false;
970 $this->categories_info[$row->cat_id]['accepted'] = false;
971 $this->categories_info[$row->cat_id]['remote'] = false;
972 }
973 }
974
981 protected function readSelectedCategories($a_obj_ids, $a_source_ref_id = 0)
982 {
983 global $DIC;
984
985 $ilAccess = $DIC['ilAccess'];
986 $tree = $DIC['tree'];
987 global $DIC;
988
989 $ilDB = $DIC['ilDB'];
990
991 if (!count($a_obj_ids)) {
992 return true;
993 }
994
995 $query = "SELECT * FROM cal_categories " .
996 "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_OBJ, 'integer') . " " .
997 "AND " . $ilDB->in('obj_id', $a_obj_ids, false, 'integer') . " " .
998 "ORDER BY title ";
999
1000 $res = $this->db->query($query);
1001 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1002 // check activation/deactivation
1003 $obj_type = ilObject::_lookupType($row->obj_id);
1004 if ($obj_type == 'crs' or $obj_type == 'grp') {
1005 if (!ilCalendarSettings::_getInstance()->lookupCalendarActivated($row->obj_id)) {
1006 continue;
1007 }
1008 }
1009
1010 $editable = false;
1011 $exists = false;
1012 $settings = false;
1013 foreach (ilObject::_getAllReferences($row->obj_id) as $ref_id) {
1014 if ($ilAccess->checkAccess('edit_event', '', $ref_id)) {
1015 $settings = true;
1016 }
1017 if ($ilAccess->checkAccess('edit_event', '', $ref_id)) {
1018 $exists = true;
1019 $editable = true;
1020 break;
1021 } elseif ($ilAccess->checkAccess('read', '', $ref_id)) {
1022 $exists = true;
1023 }
1024 }
1025 if (!$exists) {
1026 continue;
1027 }
1028 $this->categories_info[$row->cat_id]['editable'] = $editable;
1029 $this->categories_info[$row->cat_id]['settings'] = $settings;
1030
1031 $this->categories[] = $row->cat_id;
1032 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
1033 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
1034 $this->categories_info[$row->cat_id]['color'] = $row->color;
1035 #$this->categories_info[$row->cat_id]['title'] = ilObject::_lookupTitle($row->obj_id);
1036 $this->categories_info[$row->cat_id]['title'] = $row->title;
1037 $this->categories_info[$row->cat_id]['obj_type'] = ilObject::_lookupType($row->obj_id);
1038 $this->categories_info[$row->cat_id]['type'] = $row->type;
1039 $this->categories_info[$row->cat_id]['remote'] = false;
1040 $this->categories_info[$row->cat_id]['source_ref_id'] = $a_source_ref_id;
1041 }
1042 }
1043
1050 protected function addSubitemCalendars()
1051 {
1052 global $DIC;
1053
1054 $ilDB = $DIC->database();
1055 $access = $DIC->access();
1056
1057 $course_ids = array();
1058 foreach ($this->categories as $cat_id) {
1059 if ($this->categories_info[$cat_id]['obj_type'] == 'crs' or $this->categories_info[$cat_id]['obj_type'] == 'grp') {
1060 $course_ids[] = $this->categories_info[$cat_id]['obj_id'];
1061 }
1062 }
1063
1064 $query = "SELECT od2.obj_id sess_id, od1.obj_id crs_id,cat_id, or2.ref_id sess_ref_id FROM object_data od1 " .
1065 "JOIN object_reference or1 ON od1.obj_id = or1.obj_id " .
1066 "JOIN tree t ON or1.ref_id = t.parent " .
1067 "JOIN object_reference or2 ON t.child = or2.ref_id " .
1068 "JOIN object_data od2 ON or2.obj_id = od2.obj_id " .
1069 "JOIN cal_categories cc ON od2.obj_id = cc.obj_id " .
1070 "WHERE " . $ilDB->in('od2.type', array('sess','exc'), false, 'text') .
1071 "AND (od1.type = 'crs' OR od1.type = 'grp') " .
1072 "AND " . $ilDB->in('od1.obj_id', $course_ids, false, 'integer') . ' ' .
1073 "AND or2.deleted IS NULL";
1074
1075 $res = $ilDB->query($query);
1076 $cat_ids = array();
1077 $course_sessions = array();
1078 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1079 if (
1080 !$access->checkAccessOfUser($this->user_id, 'read', '', $row->sess_ref_id) ||
1081 !$access->checkAccessOfUser($this->user_id, 'visible', '', $row->sess_ref_id)
1082 ) {
1083 continue;
1084 }
1085 $cat_ids[] = $row->cat_id;
1086 $course_sessions[$row->crs_id][$row->sess_id] = $row->cat_id;
1087 $this->subitem_categories[] = $row->cat_id;
1088 }
1089
1090 foreach ($this->categories as $cat_id) {
1091 if (
1092 ($this->categories_info[$cat_id]['obj_type'] == 'crs' ||
1093 $this->categories_info[$cat_id]['obj_type'] == 'grp') &&
1094 isset($this->categories_info[$cat_id]['obj_id']) &&
1095 isset($course_sessions[$this->categories_info[$cat_id]['obj_id']]) &&
1096 is_array($course_sessions[$this->categories_info[$cat_id]['obj_id']])) {
1097 foreach ($course_sessions[$this->categories_info[$cat_id]['obj_id']] as $sess_id => $sess_cat_id) {
1098 $this->categories_info[$cat_id]['subitem_ids'][$sess_id] = $sess_cat_id;
1099 $this->categories_info[$cat_id]['subitem_obj_ids'][$sess_cat_id] = $sess_id;
1100 }
1101 } else {
1102 $this->categories_info[$cat_id]['subitem_ids'] = array();
1103 $this->categories_info[$cat_id]['subitem_obj_ids'] = array();
1104 }
1105 }
1106 }
1107
1114 public static function lookupPrivateCategories($a_user_id)
1115 {
1116 global $DIC;
1117
1118 $ilDB = $DIC['ilDB'];
1119
1120 // First read private calendars of user
1121 $set = $ilDB->query("SELECT * FROM cal_categories " .
1122 "WHERE type = " . $ilDB->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " .
1123 "AND obj_id = " . $ilDB->quote($a_user_id, 'integer'));
1124 $cats = array();
1125 while ($rec = $ilDB->fetchAssoc($set)) {
1126 $cats[] = $rec;
1127 }
1128 return $cats;
1129 }
1130}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
An exception for terminatinating execution or to throw for unit testing.
static lookupBookableUsersForObject($a_obj_id, $a_user_ids)
Consultation hours are offered if 1) consultation hour owner is admin or tutor and no object assignme...
Exception being thrown calendar categories is initiliazed multiple times for the same user.
static getInstance()
get singleton instance
class for calendar categories
static deletePDItemsCache($a_usr_id)
Delete cache (add remove desktop item)
readPDCalendars()
Read categories of user.
readAllConsultationHoursCalendarOfContainer($a_container_ref_id)
Read personal consultation hours calendar of all tutors for a container.
getNotificationCalendars()
Get all calendars that allow send of notifications (Editable and course group calendars)
readSelectedItemCalendars()
Read categories of selected items.
setCHUserId($a_user_id)
Set ch user id.
static _lookupCategoryIdByObjId($a_obj_id)
lookup category by obj_id
addSubitemCalendars()
Add subitem calendars E.g.
getSubitemCategories($a_cat_id)
get subitem categories for a specific category
readSelectedCategories($a_obj_ids, $a_source_ref_id=0)
read selected categories
readConsultationHoursCalendar($a_target_ref_id=null, $a_cat_id=0)
Read personal consultation hours calendar.
readPrivateCalendars($only_cat_ids=null)
Read private calendars.
readSelectedCalendar($a_cal_id)
Read info about selected calendar.
isVisible($a_cat_id)
check if category is visible
wakeup($a_ser)
Load from serialize string.
sleep()
Serialize categories.
readBookingCalendar($user_id=null)
Read booking manager calendar.
__construct($a_usr_id=0)
Singleton instance.
static lookupPrivateCategories($a_user_id)
Lookup private categories of user.
readReposCalendars($a_container_only=false)
Read available repository calendars.
setSourceRefId($a_val)
Set source ref id.
getCategoryInfo($a_cat_id)
@access public
static _isOwner($a_usr_id, $a_cal_id)
check if user is owner of a category
readPublicCalendars($cat_ids=null)
Read public calendars.
static deleteRepositoryCache($a_usr_id)
Delete cache.
isEditable($a_cat_id)
check if category is editable
prepareCategoriesOfUserForSelection()
prepare categories of users for selection
getCategories($a_include_subitem_calendars=false)
get categories
static _getInstance($a_usr_id=0)
get singleton instance
getSourceRefId()
Get source ref id.
initialize($a_mode, $a_source_ref_id=0, $a_use_cache=false, $a_cat_id=0)
initialize visible categories
Stores calendar categories.
static _getInstance()
get singleton instance
static getAcceptedCalendars($a_usr_id)
get accepted shared calendars
Handles shared calendars.
static _getInstance()
get instance for logged in user
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static _lookupFullname($a_user_id)
Lookup Full Name.
static _lookupObjId($a_id)
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
$query
$lng
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46