ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
24include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
25include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
26include_once './Services/Calendar/classes/class.ilCalendarCache.php';
27
38{
39 const MODE_REPOSITORY = 2;
43 const MODE_MANAGE = 6;
47
48 protected static $instance = null;
49
50 protected $db;
51
52 protected $user_id;
53
54 protected $mode = 0;
55
56 protected $categories = array();
57 protected $categories_info = array();
58 protected $subitem_categories = array();
59
60 protected $root_ref_id = 0;
61 protected $root_obj_id = 0;
62
63
64 protected $ch_user_id = 0;
65 protected $target_ref_id = 0;
66
70 protected $logger = null;
71
79 protected function __construct($a_usr_id = 0)
80 {
81 global $ilUser,$ilDB;
82
83 $this->logger = $GLOBALS['DIC']->logger()->cal();
84
85 $this->user_id = $a_usr_id;
86 if(!$this->user_id)
87 {
88 $this->user_id = $ilUser->getId();
89 }
90 $this->db = $ilDB;
91 }
92
101 public static function _getInstance($a_usr_id = 0)
102 {
103 if(self::$instance)
104 {
105 return self::$instance;
106 }
107 return self::$instance = new ilCalendarCategories($a_usr_id);
108 }
109
118 public static function _lookupCategoryIdByObjId($a_obj_id)
119 {
120 global $ilDB;
121
122 $query = "SELECT cat_id FROM cal_categories ".
123 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
124 "AND type = ".$ilDB->quote(ilCalendarCategory::TYPE_OBJ,'integer')." ";
125
126 $res = $ilDB->query($query);
127 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
128 {
129 return $row->cat_id;
130 }
131 return 0;
132 }
133
134
144 public static function _isOwner($a_usr_id,$a_cal_id)
145 {
146 global $ilDB;
147
148 $query = "SELECT * FROM cal_categories ".
149 "WHERE cat_id = ".$ilDB->quote($a_cal_id ,'integer')." ".
150 "AND obj_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
151 "AND type = ".$ilDB->quote(ilCalendarCategory::TYPE_USR ,'integer')." ";
152 $res = $ilDB->query($query);
153 return $res->numRows() ? true : false;
154 }
155
161 public static function deletePDItemsCache($a_usr_id)
162 {
163 ilCalendarCache::getInstance()->deleteByAdditionalKeys(
164 $a_usr_id,
165 self::MODE_PERSONAL_DESKTOP_ITEMS,
166 'categories'
167 );
168 }
169
175 public static function deleteRepositoryCache($a_usr_id)
176 {
177 ilCalendarCache::getInstance()->deleteByAdditionalKeys(
178 $a_usr_id,
179 self::MODE_REPOSITORY,
180 'categories'
181 );
182
183 }
184
185
190 protected function sleep()
191 {
192 return serialize(
193 array(
194 'categories' => $this->categories,
195 'categories_info' => $this->categories_info,
196 'subitem_categories'=> $this->subitem_categories
197 )
198 );
199 }
200
206 protected function wakeup($a_ser)
207 {
208 $info = unserialize($a_ser);
209
210 $this->categories = $info['categories'];
211 $this->categories_info = $info['categories_info'];
212 $this->subitem_categories = $info['subitem_categories'];
213 }
214
219 public function setCHUserId($a_user_id)
220 {
221 $this->ch_user_id = $a_user_id;
222 }
223
224
229 public function getCHUserId()
230 {
231 return $this->ch_user_id;
232 }
233
234 protected function setMode($a_mode)
235 {
236 $this->mode = $a_mode;
237 }
238
239 public function getMode()
240 {
241 return $this->mode;
242 }
243
244 protected function setTargetRefId($a_ref_id)
245 {
246 $this->target_ref_id = $a_ref_id;
247 }
248
249 public function getTargetRefId()
250 {
252 }
253
262 public function initialize($a_mode,$a_source_ref_id = 0,$a_use_cache = false)
263 {
264 $this->setMode($a_mode);
265 if($a_use_cache)
266 {
267 // Read categories from cache
268 if($cats = ilCalendarCache::getInstance()->getEntry($this->user_id.':'.$a_mode.':categories:'.(int) $a_source_ref_id))
269 {
270 if($this->getMode() != self::MODE_CONSULTATION &&
271 $this->getMode() != self::MODE_PORTFOLIO_CONSULTATION)
272 {
273 $this->wakeup($cats);
274 return;
275 }
276 }
277 }
278
279
280 switch($this->getMode())
281 {
283 include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
285 {
286 $this->readPDCalendars();
287 }
288 else
289 {
291 }
292 break;
293
295 $this->readSelectedCalendar($a_source_ref_id);
296 break;
297
299 $this->readPDCalendars();
300 break;
301
304 break;
305
307 $this->root_ref_id = $a_source_ref_id;
308 $this->root_obj_id = ilObject::_lookupObjId($this->root_ref_id);
309 $this->readReposCalendars();
310 break;
311
313 $this->readPDCalendars();
315 break;
316
318 #$this->readPrivateCalendars();
319 $this->setTargetRefId($a_source_ref_id);
320 $this->readConsultationHoursCalendar($a_source_ref_id);
321 break;
322
325 break;
326 }
327
328 if($a_use_cache)
329 {
330 // Store in cache
331 ilCalendarCache::getInstance()->storeEntry(
332 $this->user_id.':'.$a_mode.':categories:'.(int) $a_source_ref_id,
333 $this->sleep(),
334 $this->user_id,
335 $a_mode,
336 'categories'
337 );
338 }
339 }
340
348 public function getCategoryInfo($a_cat_id)
349 {
350 if(isset($this->categories_info[$a_cat_id]))
351 {
352 return $this->categories_info[$a_cat_id];
353 }
354
355 if(in_array($a_cat_id,(array) $this->subitem_categories))
356 {
357 foreach($this->categories as $cat_id)
358 {
359 if(in_array($a_cat_id,$this->categories_info[$cat_id]['subitem_ids']))
360 {
361 return $this->categories_info[$cat_id];
362 }
363 }
364 }
365 }
366
367
375 public function getCategoriesInfo()
376 {
377 return $this->categories_info ? $this->categories_info : array();
378 }
379
386 public function getCategories($a_include_subitem_calendars = false)
387 {
388 if($a_include_subitem_calendars)
389 {
390 return array_merge((array) $this->categories, (array) $this->subitem_categories);
391 }
392
393 return $this->categories ? $this->categories : array();
394 }
395
402 public function getSubitemCategories($a_cat_id)
403 {
404 if(!isset($this->categories_info[$a_cat_id]['subitem_ids']))
405 {
406 return array($a_cat_id);
407 }
408 return array_merge((array) $this->categories_info[$a_cat_id]['subitem_ids'],array($a_cat_id));
409 }
410
411
420 {
421 global $lng;
422
423 $has_personal_calendar = false;
424 foreach($this->categories_info as $info)
425 {
426 if($info['obj_type'] == 'sess' || $info['obj_type'] == 'exc')
427 {
428 continue;
429 }
430 if($info['type'] == ilCalendarCategory::TYPE_USR and $info['editable'])
431 {
432 $has_personal_calendar = true;
433 }
434
435 if($info['editable'])
436 {
437 $cats[$info['cat_id']] = $info['title'];
438 }
439 }
440 // If there
441 if(!$has_personal_calendar)
442 {
443 $cats[0] = $lng->txt('cal_default_calendar');
444 }
445 return $cats ? $cats : array();
446 }
447
453 public function getNotificationCalendars()
454 {
455 $not = array();
456 foreach($this->categories_info as $info)
457 {
458 if($info['type'] == ilCalendarCategory::TYPE_OBJ and $info['editable'] == true)
459 {
460 if(ilObject::_lookupType($info['obj_id']) == 'crs' or ilObject::_lookupType($info['obj_id']) == 'grp')
461 {
462 $not[] = $info['cat_id'];
463 }
464 }
465 }
466 return $not;
467 }
468
476 public function isEditable($a_cat_id)
477 {
478 return isset($this->categories_info[$a_cat_id]['editable']) and $this->categories_info[$a_cat_id]['editable'];
479 }
480
488 public function isVisible($a_cat_id)
489 {
490 return in_array($a_cat_id,$this->categories) or
491 in_array($a_cat_id,(array) $this->subitem_categories);
492 }
493
494
495
496
504 protected function readPDCalendars()
505 {
506 global $rbacsystem;
507
508
509 $this->readPublicCalendars();
510 $this->readPrivateCalendars();
512 $this->readBookingCalendar();
513
514 include_once('./Services/Membership/classes/class.ilParticipants.php');
517
518 $this->addSubitemCalendars();
519 }
520
525 protected function readSelectedCalendar($a_cal_id)
526 {
527 include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
528 $cat = new ilCalendarCategory($a_cal_id);
529 if($cat->getType() == ilCalendarCategory::TYPE_OBJ)
530 {
531 $this->readSelectedCategories(array($cat->getObjId()));
532 $this->addSubitemCalendars();
533 }
534 else
535 {
536 $this->categories[] = $a_cal_id;
537 }
538 }
539
546 protected function readSelectedItemCalendars()
547 {
548 global $ilUser,$ilAccess;
549
550 $this->readPublicCalendars();
551 $this->readPrivateCalendars();
553 $this->readBookingCalendar();
554
555 $obj_ids = array();
556
557 $courses = array();
558 $groups = array();
559 $sessions = array();
560 $exercises = array();
561 foreach(ilObjUser::_lookupDesktopItems($ilUser->getId(),array('crs','grp','sess','exc')) as $item)
562 {
563 if($ilAccess->checkAccess('read','',$item['ref_id']))
564 {
565 switch($item['type'])
566 {
567 case 'crs':
568 $courses[] = $item['obj_id'];
569 break;
570
571 case 'sess':
572 $sessions[] = $item['obj_id'];
573 break;
574
575 case 'grp':
576 $groups[] = $item['obj_id'];
577 break;
578
579 case 'exc':
580 $exercises[] = $item['obj_id'];
581 break;
582 }
583 }
584 }
585 $this->readSelectedCategories($courses);
586 $this->readSelectedCategories($sessions);
587 $this->readSelectedCategories($groups);
588 $this->readSelectedCategories($exercises);
589
590 $this->addSubitemCalendars();
591
592 }
593
601 protected function readReposCalendars()
602 {
603 global $ilAccess,$tree;
604 global $ilDB;
605
606 $this->readPublicCalendars();
607 $this->readPrivateCalendars();
609
610 #$query = "SELECT ref_id,obd.obj_id obj_id FROM tree t1 ".
611 # "JOIN object_reference obr ON t1.child = obr.ref_id ".
612 # "JOIN object_data obd ON obd.obj_id = obr.obj_id ".
613 # "WHERE t1.lft >= (SELECT lft FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
614 # "AND t1.lft <= (SELECT rgt FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
615 # "AND ".$ilDB->in('type',array('crs','grp','sess'),false,'text')." ".
616 # "AND tree = 1";
617
618 $subtree_query = $GLOBALS['tree']->getSubTreeQuery(
619 $this->root_ref_id,
620 array('object_reference.ref_id','object_data.obj_id'),
621 array('crs','grp','sess','exc')
622 );
623
624 $res = $ilDB->query($subtree_query);
625 $obj_ids = array();
626 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
627 {
628 if($tree->isDeleted($row->ref_id))
629 {
630 continue;
631 }
632
633 $obj_type = ilObject::_lookupType($row->obj_id);
634 if($obj_type == 'crs' or $obj_type == 'grp')
635 {
636 // Check for global/local activation
637 if(!ilCalendarSettings::_getInstance()->lookupCalendarActivated($row->obj_id))
638 {
639 continue;
640 }
641 }
642 if($ilAccess->checkAccess('read','',$row->ref_id))
643 {
644 $obj_ids[] = $row->obj_id;
645 }
646 }
647 $this->readSelectedCategories($obj_ids);
648 }
649
656 protected function readPublicCalendars()
657 {
658 global $rbacsystem,$ilAccess;
659
660 // global categories
661 $query = "SELECT * FROM cal_categories ".
662 "WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_GLOBAL ,'integer')." ".
663 "ORDER BY title ";
664
665 $res = $this->db->query($query);
666 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
667 {
668 $this->categories[] = $row->cat_id;
669 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
670 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
671 $this->categories_info[$row->cat_id]['title'] = $row->title;
672 $this->categories_info[$row->cat_id]['color'] = $row->color;
673 $this->categories_info[$row->cat_id]['type'] = $row->type;
674 $this->categories_info[$row->cat_id]['editable'] = $rbacsystem->checkAccess('edit_event',ilCalendarSettings::_getInstance()->getCalendarSettingsId());
675 $this->categories_info[$row->cat_id]['accepted'] = false;
676 $this->categories_info[$row->cat_id]['remote'] = ($row->loc_type == ilCalendarCategory::LTYPE_REMOTE);
677 }
678
679 return true;
680 }
681
688 protected function readPrivateCalendars()
689 {
690 global $ilUser;
691 global $ilDB;
692
693 // First read private calendars of user
694 $query = "SELECT cat_id FROM cal_categories ".
695 "WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_USR ,'integer')." ".
696 "AND obj_id = ".$this->db->quote($ilUser->getId(),'integer')." ";
697 $res = $this->db->query($query);
698 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
699 {
700 $cat_ids[] = $row->cat_id;
701 }
702
703 // Read shared calendars
704 include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
706 if(!$cat_ids = array_merge((array) $cat_ids, $accepted_ids))
707 {
708 return true;
709 }
710
711
712 // user categories
713 $query = "SELECT * FROM cal_categories ".
714 "WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_USR ,'integer')." ".
715 "AND ".$ilDB->in('cat_id',$cat_ids,false,'integer')." ".
716 "ORDER BY title ";
717
718 $res = $this->db->query($query);
719 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
720 {
721 $this->categories[] = $row->cat_id;
722 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
723 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
724 $this->categories_info[$row->cat_id]['title'] = $row->title;
725 $this->categories_info[$row->cat_id]['color'] = $row->color;
726 $this->categories_info[$row->cat_id]['type'] = $row->type;
727
728 include_once './Services/Calendar/classes/class.ilCalendarShared.php';
729 if(in_array($row->cat_id, $accepted_ids))
730 {
731 $shared = new ilCalendarShared($row->cat_id);
732 if($shared->isEditableForUser($ilUser->getId()))
733 {
734 $this->categories_info[$row->cat_id]['editable'] = true;
735 }
736 else
737 {
738 $this->categories_info[$row->cat_id]['editable'] = false;
739 }
740 }
741 else
742 {
743 $this->categories_info[$row->cat_id]['editable'] = true;
744 }
745
746 $this->categories_info[$row->cat_id]['accepted'] = in_array($row->cat_id, $accepted_ids);
747 $this->categories_info[$row->cat_id]['remote'] = ($row->loc_type == ilCalendarCategory::LTYPE_REMOTE);
748 }
749 }
750
756 public function readConsultationHoursCalendar($a_target_ref_id = NULL)
757 {
758 global $ilDB;
759
760 if(!$this->getCHUserId())
761 {
762 $this->setCHUserId($this->user_id);
763 }
764
765 if($a_target_ref_id)
766 {
767 $target_obj_id = ilObject::_lookupObjId($a_target_ref_id);
768
769 $query = 'SELECT DISTINCT(cc.cat_id) FROM booking_entry be '.
770 'LEFT JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id '.
771 'JOIN cal_entries ce ON be.booking_id = ce.context_id '.
772 'JOIN cal_cat_assignments ca ON ce.cal_id = ca.cal_id '.
773 'JOIN cal_categories cc ON ca.cat_id = cc.cat_id '.
774 'WHERE ((bo.target_obj_id IS NULL) OR bo.target_obj_id = '.$ilDB->quote($target_obj_id,'integer').' ) '.
775 'AND cc.obj_id = '.$ilDB->quote($this->getCHUserId(),'integer');
776
777
778 $res = $ilDB->query($query);
779 $categories = array();
780 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
781 {
782 $categories[] = $row->cat_id;
783 }
784
785 if($categories)
786 {
787 $query = 'SELECT * FROM cal_categories '.
788 'WHERE '.$ilDB->in('cat_id',$categories,false,'integer');
789 $res = $ilDB->query($query);
790 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
791 {
792 $this->categories[] = $row->cat_id;
793 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
794 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
795 $this->categories_info[$row->cat_id]['title'] = $row->title;
796 $this->categories_info[$row->cat_id]['color'] = $row->color;
797 $this->categories_info[$row->cat_id]['type'] = $row->type;
798 $this->categories_info[$row->cat_id]['editable'] = false;
799 $this->categories_info[$row->cat_id]['accepted'] = false;
800 $this->categories_info[$row->cat_id]['remote'] = false;
801 }
802 }
803 }
804 else // no category given
805 {
806 $query = "SELECT * FROM cal_categories cc ".
807 "WHERE type = ".$ilDB->quote(ilCalendarCategory::TYPE_CH,'integer').' '.
808 "AND obj_id = ".$ilDB->quote($this->getCHUserId(),'integer');
809 $res = $ilDB->query($query);
810 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
811 {
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 $this->categories_info[$row->cat_id]['editable'] = false;
819 $this->categories_info[$row->cat_id]['accepted'] = false;
820 $this->categories_info[$row->cat_id]['remote'] = false;
821 }
822 }
823 return true;
824 }
825
831 public function readBookingCalendar($user_id = NULL)
832 {
833 global $ilDB;
834
835 if(!$user_id)
836 {
838 }
839
840 $query = "SELECT * FROM cal_categories ".
841 "WHERE type = ".$ilDB->quote(ilCalendarCategory::TYPE_BOOK,'integer').' '.
842 "AND obj_id = ".$ilDB->quote($user_id,'integer');
843 $res = $ilDB->query($query);
844 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
845 {
846 $this->categories[] = $row->cat_id;
847 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
848 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
849 $this->categories_info[$row->cat_id]['title'] = $row->title;
850 $this->categories_info[$row->cat_id]['color'] = $row->color;
851 $this->categories_info[$row->cat_id]['type'] = $row->type;
852 $this->categories_info[$row->cat_id]['editable'] = false;
853 $this->categories_info[$row->cat_id]['accepted'] = false;
854 $this->categories_info[$row->cat_id]['remote'] = false;
855 }
856 }
857
864 protected function readSelectedCategories($a_obj_ids)
865 {
866 global $ilAccess,$tree;
867 global $ilDB;
868
869 if(!count($a_obj_ids))
870 {
871 return true;
872 }
873
874 $query = "SELECT * FROM cal_categories ".
875 "WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_OBJ ,'integer')." ".
876 "AND ".$ilDB->in('obj_id',$a_obj_ids,false,'integer')." ".
877 "ORDER BY title ";
878
879 $res = $this->db->query($query);
880 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
881 {
882 // check activation/deactivation
883 $obj_type = ilObject::_lookupType($row->obj_id);
884 if($obj_type == 'crs' or $obj_type == 'grp')
885 {
886 if(!ilCalendarSettings::_getInstance()->lookupCalendarActivated($row->obj_id))
887 {
888 continue;
889 }
890 }
891
892 $editable = false;
893 $exists = false;
894 foreach(ilObject::_getAllReferences($row->obj_id) as $ref_id)
895 {
896 if($ilAccess->checkAccess('edit_event','',$ref_id))
897 {
898 $exists = true;
899 $editable = true;
900 break;
901 }
902 elseif($ilAccess->checkAccess('read','',$ref_id))
903 {
904 $exists = true;
905 }
906 }
907 if(!$exists)
908 {
909 continue;
910 }
911 $this->categories_info[$row->cat_id]['editable'] = $editable;
912
913 $this->categories[] = $row->cat_id;
914 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
915 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
916 $this->categories_info[$row->cat_id]['color'] = $row->color;
917 #$this->categories_info[$row->cat_id]['title'] = ilObject::_lookupTitle($row->obj_id);
918 $this->categories_info[$row->cat_id]['title'] = $row->title;
919 $this->categories_info[$row->cat_id]['obj_type'] = ilObject::_lookupType($row->obj_id);
920 $this->categories_info[$row->cat_id]['type'] = $row->type;
921 $this->categories_info[$row->cat_id]['remote'] = false;
922
923 }
924 }
925
932 protected function addSubitemCalendars()
933 {
934 global $ilDB;
935
936 $course_ids = array();
937 foreach($this->categories as $cat_id)
938 {
939 if($this->categories_info[$cat_id]['obj_type'] == 'crs' or $this->categories_info[$cat_id]['obj_type'] == 'grp')
940 {
941 $course_ids[] = $this->categories_info[$cat_id]['obj_id'];
942 }
943 }
944
945 $query = "SELECT od2.obj_id sess_id, od1.obj_id crs_id,cat_id FROM object_data od1 ".
946 "JOIN object_reference or1 ON od1.obj_id = or1.obj_id ".
947 "JOIN tree t ON or1.ref_id = t.parent ".
948 "JOIN object_reference or2 ON t.child = or2.ref_id ".
949 "JOIN object_data od2 ON or2.obj_id = od2.obj_id ".
950 "JOIN cal_categories cc ON od2.obj_id = cc.obj_id ".
951 "WHERE ".$ilDB->in('od2.type',array('sess','exc'),false,'text').
952 "AND (od1.type = 'crs' OR od1.type = 'grp') ".
953 "AND ".$ilDB->in('od1.obj_id',$course_ids,false,'integer').' '.
954 "AND or2.deleted IS NULL";
955
956 $res = $ilDB->query($query);
957 $cat_ids = array();
958 $course_sessions = array();
959 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
960 {
961 $cat_ids[] = $row->cat_id;
962 $course_sessions[$row->crs_id][$row->sess_id] = $row->cat_id;
963 $this->subitem_categories[] = $row->cat_id;
964 }
965
966 foreach($this->categories as $cat_id)
967 {
968 if(
969 ($this->categories_info[$cat_id]['obj_type'] == 'crs' ||
970 $this->categories_info[$cat_id]['obj_type'] == 'grp' ) &&
971 isset($this->categories_info[$cat_id]['obj_id']) &&
972 isset($course_sessions[$this->categories_info[$cat_id]['obj_id']]) &&
973 is_array($course_sessions[$this->categories_info[$cat_id]['obj_id']]))
974 {
975 foreach($course_sessions[$this->categories_info[$cat_id]['obj_id']] as $sess_id => $sess_cat_id)
976 {
977 $this->categories_info[$cat_id]['subitem_ids'][$sess_id] = $sess_cat_id;
978 $this->categories_info[$cat_id]['subitem_obj_ids'][$sess_cat_id] = $sess_id;
979 }
980 }
981 else
982 {
983 $this->categories_info[$cat_id]['subitem_ids'] = array();
984 $this->categories_info[$cat_id]['subitem_obj_ids'] = array();
985 }
986 }
987 }
988
995 static function lookupPrivateCategories($a_user_id)
996 {
997 global $ilDB;
998
999 // First read private calendars of user
1000 $set = $ilDB->query("SELECT * FROM cal_categories ".
1001 "WHERE type = ".$ilDB->quote(ilCalendarCategory::TYPE_USR ,'integer')." ".
1002 "AND obj_id = ".$ilDB->quote($a_user_id,'integer'));
1003 $cats = array();
1004 while ($rec = $ilDB->fetchAssoc($set))
1005 {
1006 $cats[] = $rec;
1007 }
1008 return $cats;
1009 }
1010
1011}
1012?>
An exception for terminatinating execution or to throw for unit testing.
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.
getNotificationCalendars()
Get all calendars that allow send of notifications (Editable and course group calendars)
readPrivateCalendars()
Read private 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)
read selected categories
readPublicCalendars()
Read public 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.
__construct($a_usr_id=0)
Singleton instance.
readBookingCalendar($user_id=NULL)
Read booking manager calendar.
static lookupPrivateCategories($a_user_id)
Lookup private categories of user.
getCategoryInfo($a_cat_id)
@access public
static _isOwner($a_usr_id, $a_cal_id)
check if user is owner of a category
readReposCalendars()
Read available repository calendars.
readConsultationHoursCalendar($a_target_ref_id=NULL)
Read personal consultation hours calendar.
initialize($a_mode, $a_source_ref_id=0, $a_use_cache=false)
initialize visible categories
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
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 _lookupDesktopItems($user_id, $a_types="")
get all desktop items of user and specified type
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
$info
Definition: example_052.php:80
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $lng
Definition: privfeed.php:17
$ref_id
Definition: sahs_server.php:39
global $ilDB
$ilUser
Definition: imgupload.php:18