ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
74 protected function __construct($a_usr_id = 0)
75 {
76 global $ilUser,$ilDB;
77
78 $this->user_id = $a_usr_id;
79 if(!$this->user_id)
80 {
81 $this->user_id = $ilUser->getId();
82 }
83 $this->db = $ilDB;
84 }
85
94 public static function _getInstance($a_usr_id = 0)
95 {
96 if(self::$instance)
97 {
98 return self::$instance;
99 }
100 return self::$instance = new ilCalendarCategories($a_usr_id);
101 }
102
111 public static function _lookupCategoryIdByObjId($a_obj_id)
112 {
113 global $ilDB;
114
115 $query = "SELECT cat_id FROM cal_categories ".
116 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
117 "AND type = ".$ilDB->quote(ilCalendarCategory::TYPE_OBJ,'integer')." ";
118
119 $res = $ilDB->query($query);
120 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
121 {
122 return $row->cat_id;
123 }
124 return 0;
125 }
126
127
137 public static function _isOwner($a_usr_id,$a_cal_id)
138 {
139 global $ilDB;
140
141 $query = "SELECT * FROM cal_categories ".
142 "WHERE cat_id = ".$ilDB->quote($a_cal_id ,'integer')." ".
143 "AND obj_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
144 "AND type = ".$ilDB->quote(ilCalendarCategory::TYPE_USR ,'integer')." ";
145 $res = $ilDB->query($query);
146 return $res->numRows() ? true : false;
147 }
148
154 public static function deletePDItemsCache($a_usr_id)
155 {
156 ilCalendarCache::getInstance()->deleteByAdditionalKeys(
157 $a_usr_id,
158 self::MODE_PERSONAL_DESKTOP_ITEMS,
159 'categories'
160 );
161 }
162
168 public static function deleteRepositoryCache($a_usr_id)
169 {
170 ilCalendarCache::getInstance()->deleteByAdditionalKeys(
171 $a_usr_id,
172 self::MODE_REPOSITORY,
173 'categories'
174 );
175
176 }
177
178
183 protected function sleep()
184 {
185 return serialize(
186 array(
187 'categories' => $this->categories,
188 'categories_info' => $this->categories_info,
189 'subitem_categories'=> $this->subitem_categories
190 )
191 );
192 }
193
199 protected function wakeup($a_ser)
200 {
201 $info = unserialize($a_ser);
202
203 $this->categories = $info['categories'];
204 $this->categories_info = $info['categories_info'];
205 $this->subitem_categories = $info['subitem_categories'];
206 }
207
212 public function setCHUserId($a_user_id)
213 {
214 $this->ch_user_id = $a_user_id;
215 }
216
217
222 public function getCHUserId()
223 {
224 return $this->ch_user_id;
225 }
226
227 protected function setMode($a_mode)
228 {
229 $this->mode = $a_mode;
230 }
231
232 public function getMode()
233 {
234 return $this->mode;
235 }
236
237 protected function setTargetRefId($a_ref_id)
238 {
239 $this->target_ref_id = $a_ref_id;
240 }
241
242 public function getTargetRefId()
243 {
245 }
246
255 public function initialize($a_mode,$a_source_ref_id = 0,$a_use_cache = false)
256 {
257 $this->setMode($a_mode);
258 if($a_use_cache)
259 {
260 // Read categories from cache
261 if($cats = ilCalendarCache::getInstance()->getEntry($this->user_id.':'.$a_mode.':categories:'.(int) $a_source_ref_id))
262 {
263 if($this->getMode() != self::MODE_CONSULTATION &&
264 $this->getMode() != self::MODE_PORTFOLIO_CONSULTATION)
265 {
266 $this->wakeup($cats);
267 return;
268 }
269 }
270 }
271
272
273 switch($this->getMode())
274 {
276 include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
278 {
279 $this->readPDCalendars();
280 }
281 else
282 {
284 }
285 break;
286
288 $this->readSelectedCalendar($a_source_ref_id);
289 break;
290
292 $this->readPDCalendars();
293 break;
294
297 break;
298
300 $this->root_ref_id = $a_source_ref_id;
301 $this->root_obj_id = ilObject::_lookupObjId($this->root_ref_id);
302 $this->readReposCalendars();
303 break;
304
306 $this->readPDCalendars();
308 break;
309
311 #$this->readPrivateCalendars();
312 $this->setTargetRefId($a_source_ref_id);
313 $this->readConsultationHoursCalendar($a_source_ref_id);
314 break;
315
318 break;
319 }
320
321 if($a_use_cache)
322 {
323 // Store in cache
324 ilCalendarCache::getInstance()->storeEntry(
325 $this->user_id.':'.$a_mode.':categories:'.(int) $a_source_ref_id,
326 $this->sleep(),
327 $this->user_id,
328 $a_mode,
329 'categories'
330 );
331 }
332 }
333
341 public function getCategoryInfo($a_cat_id)
342 {
343 if(isset($this->categories_info[$a_cat_id]))
344 {
345 return $this->categories_info[$a_cat_id];
346 }
347
348 if(in_array($a_cat_id,(array) $this->subitem_categories))
349 {
350 foreach($this->categories as $cat_id)
351 {
352 if(in_array($a_cat_id,$this->categories_info[$cat_id]['subitem_ids']))
353 {
354 return $this->categories_info[$cat_id];
355 }
356 }
357 }
358 }
359
360
368 public function getCategoriesInfo()
369 {
370 return $this->categories_info ? $this->categories_info : array();
371 }
372
379 public function getCategories($a_include_subitem_calendars = false)
380 {
381 if($a_include_subitem_calendars)
382 {
383 return array_merge((array) $this->categories, (array) $this->subitem_categories);
384 }
385
386 return $this->categories ? $this->categories : array();
387 }
388
395 public function getSubitemCategories($a_cat_id)
396 {
397 if(!isset($this->categories_info[$a_cat_id]['subitem_ids']))
398 {
399 return array($a_cat_id);
400 }
401 return array_merge((array) $this->categories_info[$a_cat_id]['subitem_ids'],array($a_cat_id));
402 }
403
404
413 {
414 global $lng;
415
416 $has_personal_calendar = false;
417 foreach($this->categories_info as $info)
418 {
419 if($info['obj_type'] == 'sess' || $info['obj_type'] == 'exc')
420 {
421 continue;
422 }
423 if($info['type'] == ilCalendarCategory::TYPE_USR and $info['editable'])
424 {
425 $has_personal_calendar = true;
426 }
427
428 if($info['editable'])
429 {
430 $cats[$info['cat_id']] = $info['title'];
431 }
432 }
433 // If there
434 if(!$has_personal_calendar)
435 {
436 $cats[0] = $lng->txt('cal_default_calendar');
437 }
438 return $cats ? $cats : array();
439 }
440
446 public function getNotificationCalendars()
447 {
448 $not = array();
449 foreach($this->categories_info as $info)
450 {
451 if($info['type'] == ilCalendarCategory::TYPE_OBJ and $info['editable'] == true)
452 {
453 if(ilObject::_lookupType($info['obj_id']) == 'crs' or ilObject::_lookupType($info['obj_id']) == 'grp')
454 {
455 $not[] = $info['cat_id'];
456 }
457 }
458 }
459 return $not;
460 }
461
469 public function isEditable($a_cat_id)
470 {
471 return isset($this->categories_info[$a_cat_id]['editable']) and $this->categories_info[$a_cat_id]['editable'];
472 }
473
481 public function isVisible($a_cat_id)
482 {
483 return in_array($a_cat_id,$this->categories) or
484 in_array($a_cat_id,(array) $this->subitem_categories);
485 }
486
487
488
489
497 protected function readPDCalendars()
498 {
499 global $rbacsystem;
500
501
502 $this->readPublicCalendars();
503 $this->readPrivateCalendars();
505 $this->readBookingCalendar();
506
507 include_once('./Services/Membership/classes/class.ilParticipants.php');
510
511 $this->addSubitemCalendars();
512 }
513
518 protected function readSelectedCalendar($a_cal_id)
519 {
520 include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
521 $cat = new ilCalendarCategory($a_cal_id);
522 if($cat->getType() == ilCalendarCategory::TYPE_OBJ)
523 {
524 $this->readSelectedCategories(array($cat->getObjId()));
525 $this->addSubitemCalendars();
526 }
527 else
528 {
529 $this->categories[] = $a_cal_id;
530 }
531 }
532
539 protected function readSelectedItemCalendars()
540 {
541 global $ilUser,$ilAccess;
542
543 $this->readPublicCalendars();
544 $this->readPrivateCalendars();
546 $this->readBookingCalendar();
547
548 $obj_ids = array();
549
550 $courses = array();
551 $groups = array();
552 $sessions = array();
553 $exercises = array();
554 foreach(ilObjUser::_lookupDesktopItems($ilUser->getId(),array('crs','grp','sess','exc')) as $item)
555 {
556 if($ilAccess->checkAccess('read','',$item['ref_id']))
557 {
558 switch($item['type'])
559 {
560 case 'crs':
561 $courses[] = $item['obj_id'];
562 break;
563
564 case 'sess':
565 $sessions[] = $item['obj_id'];
566 break;
567
568 case 'grp':
569 $groups[] = $item['obj_id'];
570 break;
571
572 case 'exc':
573 $exercises[] = $item['obj_id'];
574 break;
575 }
576 }
577 }
578 $this->readSelectedCategories($courses);
579 $this->readSelectedCategories($sessions);
580 $this->readSelectedCategories($groups);
581 $this->readSelectedCategories($exercises);
582
583 $this->addSubitemCalendars();
584
585 }
586
594 protected function readReposCalendars()
595 {
596 global $ilAccess,$tree;
597 global $ilDB;
598
599 $this->readPublicCalendars();
600 $this->readPrivateCalendars();
602
603 #$query = "SELECT ref_id,obd.obj_id obj_id FROM tree t1 ".
604 # "JOIN object_reference obr ON t1.child = obr.ref_id ".
605 # "JOIN object_data obd ON obd.obj_id = obr.obj_id ".
606 # "WHERE t1.lft >= (SELECT lft FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
607 # "AND t1.lft <= (SELECT rgt FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
608 # "AND ".$ilDB->in('type',array('crs','grp','sess'),false,'text')." ".
609 # "AND tree = 1";
610
611 $subtree_query = $GLOBALS['tree']->getSubTreeQuery(
612 $this->root_ref_id,
613 array('object_reference.ref_id','object_data.obj_id'),
614 array('crs','grp','sess','exc')
615 );
616
617 $res = $ilDB->query($subtree_query);
618 $obj_ids = array();
619 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
620 {
621 if($tree->isDeleted($row->ref_id))
622 {
623 continue;
624 }
625
626 $obj_type = ilObject::_lookupType($row->obj_id);
627 if($obj_type == 'crs' or $obj_type == 'grp')
628 {
629 // Check for global/local activation
630 if(!ilCalendarSettings::_getInstance()->lookupCalendarActivated($row->obj_id))
631 {
632 continue;
633 }
634 }
635 if($ilAccess->checkAccess('read','',$row->ref_id))
636 {
637 $obj_ids[] = $row->obj_id;
638 }
639 }
640 $this->readSelectedCategories($obj_ids);
641 }
642
649 protected function readPublicCalendars()
650 {
651 global $rbacsystem,$ilAccess;
652
653 // global categories
654 $query = "SELECT * FROM cal_categories ".
655 "WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_GLOBAL ,'integer')." ".
656 "ORDER BY title ";
657
658 $res = $this->db->query($query);
659 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
660 {
661 $this->categories[] = $row->cat_id;
662 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
663 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
664 $this->categories_info[$row->cat_id]['title'] = $row->title;
665 $this->categories_info[$row->cat_id]['color'] = $row->color;
666 $this->categories_info[$row->cat_id]['type'] = $row->type;
667 $this->categories_info[$row->cat_id]['editable'] = $rbacsystem->checkAccess('edit_event',ilCalendarSettings::_getInstance()->getCalendarSettingsId());
668 $this->categories_info[$row->cat_id]['accepted'] = false;
669 $this->categories_info[$row->cat_id]['remote'] = ($row->loc_type == ilCalendarCategory::LTYPE_REMOTE);
670 }
671
672 return true;
673 }
674
681 protected function readPrivateCalendars()
682 {
683 global $ilUser;
684 global $ilDB;
685
686 // First read private calendars of user
687 $query = "SELECT cat_id FROM cal_categories ".
688 "WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_USR ,'integer')." ".
689 "AND obj_id = ".$this->db->quote($ilUser->getId(),'integer')." ";
690 $res = $this->db->query($query);
691 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
692 {
693 $cat_ids[] = $row->cat_id;
694 }
695
696 // Read shared calendars
697 include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
699 if(!$cat_ids = array_merge((array) $cat_ids, $accepted_ids))
700 {
701 return true;
702 }
703
704
705 // user categories
706 $query = "SELECT * FROM cal_categories ".
707 "WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_USR ,'integer')." ".
708 "AND ".$ilDB->in('cat_id',$cat_ids,false,'integer')." ".
709 "ORDER BY title ";
710
711 $res = $this->db->query($query);
712 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
713 {
714 $this->categories[] = $row->cat_id;
715 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
716 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
717 $this->categories_info[$row->cat_id]['title'] = $row->title;
718 $this->categories_info[$row->cat_id]['color'] = $row->color;
719 $this->categories_info[$row->cat_id]['type'] = $row->type;
720
721 include_once './Services/Calendar/classes/class.ilCalendarShared.php';
722 if(in_array($row->cat_id, $accepted_ids))
723 {
724 $shared = new ilCalendarShared($row->cat_id);
725 if($shared->isEditableForUser($ilUser->getId()))
726 {
727 $this->categories_info[$row->cat_id]['editable'] = true;
728 }
729 else
730 {
731 $this->categories_info[$row->cat_id]['editable'] = false;
732 }
733 }
734 else
735 {
736 $this->categories_info[$row->cat_id]['editable'] = true;
737 }
738
739 $this->categories_info[$row->cat_id]['accepted'] = in_array($row->cat_id, $accepted_ids);
740 $this->categories_info[$row->cat_id]['remote'] = ($row->loc_type == ilCalendarCategory::LTYPE_REMOTE);
741 }
742 }
743
749 public function readConsultationHoursCalendar($a_target_ref_id = NULL)
750 {
751 global $ilDB;
752
753 if(!$this->getCHUserId())
754 {
755 $this->setCHUserId($this->user_id);
756 }
757
758 if($a_target_ref_id)
759 {
760 $target_obj_id = ilObject::_lookupObjId($a_target_ref_id);
761
762 $query = 'SELECT DISTINCT(cc.cat_id) FROM booking_entry be '.
763 'LEFT JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id '.
764 'JOIN cal_entries ce ON be.booking_id = ce.context_id '.
765 'JOIN cal_cat_assignments ca ON ce.cal_id = ca.cal_id '.
766 'JOIN cal_categories cc ON ca.cat_id = cc.cat_id '.
767 'WHERE ((bo.target_obj_id IS NULL) OR bo.target_obj_id = '.$ilDB->quote($target_obj_id,'integer').' ) '.
768 'AND cc.obj_id = '.$ilDB->quote($this->getCHUserId(),'integer');
769
770
771 $res = $ilDB->query($query);
772 $categories = array();
773 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
774 {
775 $categories[] = $row->cat_id;
776 }
777
778 if($categories)
779 {
780 $query = 'SELECT * FROM cal_categories '.
781 'WHERE '.$ilDB->in('cat_id',$categories,false,'integer');
782 $res = $ilDB->query($query);
783 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
784 {
785 $this->categories[] = $row->cat_id;
786 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
787 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
788 $this->categories_info[$row->cat_id]['title'] = $row->title;
789 $this->categories_info[$row->cat_id]['color'] = $row->color;
790 $this->categories_info[$row->cat_id]['type'] = $row->type;
791 $this->categories_info[$row->cat_id]['editable'] = false;
792 $this->categories_info[$row->cat_id]['accepted'] = false;
793 $this->categories_info[$row->cat_id]['remote'] = false;
794 }
795 }
796 }
797 else // no category given
798 {
799 $query = "SELECT * FROM cal_categories cc ".
800 "WHERE type = ".$ilDB->quote(ilCalendarCategory::TYPE_CH,'integer').' '.
801 "AND obj_id = ".$ilDB->quote($this->getCHUserId(),'integer');
802 $res = $ilDB->query($query);
803 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
804 {
805 $this->categories[] = $row->cat_id;
806 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
807 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
808 $this->categories_info[$row->cat_id]['title'] = $row->title;
809 $this->categories_info[$row->cat_id]['color'] = $row->color;
810 $this->categories_info[$row->cat_id]['type'] = $row->type;
811 $this->categories_info[$row->cat_id]['editable'] = false;
812 $this->categories_info[$row->cat_id]['accepted'] = false;
813 $this->categories_info[$row->cat_id]['remote'] = false;
814 }
815 }
816 return true;
817 }
818
824 public function readBookingCalendar($user_id = NULL)
825 {
826 global $ilDB;
827
828 if(!$user_id)
829 {
831 }
832
833 $query = "SELECT * FROM cal_categories ".
834 "WHERE type = ".$ilDB->quote(ilCalendarCategory::TYPE_BOOK,'integer').' '.
835 "AND obj_id = ".$ilDB->quote($user_id,'integer');
836 $res = $ilDB->query($query);
837 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
838 {
839 $this->categories[] = $row->cat_id;
840 $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
841 $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
842 $this->categories_info[$row->cat_id]['title'] = $row->title;
843 $this->categories_info[$row->cat_id]['color'] = $row->color;
844 $this->categories_info[$row->cat_id]['type'] = $row->type;
845 $this->categories_info[$row->cat_id]['editable'] = false;
846 $this->categories_info[$row->cat_id]['accepted'] = false;
847 $this->categories_info[$row->cat_id]['remote'] = false;
848 }
849 }
850
857 protected function readSelectedCategories($a_obj_ids)
858 {
859 global $ilAccess,$tree;
860 global $ilDB;
861
862 if(!count($a_obj_ids))
863 {
864 return true;
865 }
866
867 $query = "SELECT * FROM cal_categories ".
868 "WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_OBJ ,'integer')." ".
869 "AND ".$ilDB->in('obj_id',$a_obj_ids,false,'integer')." ".
870 "ORDER BY title ";
871
872 $res = $this->db->query($query);
873 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
874 {
875 // check activation/deactivation
876 $obj_type = ilObject::_lookupType($row->obj_id);
877 if($obj_type == 'crs' or $obj_type == 'grp')
878 {
879 if(!ilCalendarSettings::_getInstance()->lookupCalendarActivated($row->obj_id))
880 {
881 continue;
882 }
883 }
884
885 $editable = false;
886 $exists = false;
887 foreach(ilObject::_getAllReferences($row->obj_id) as $ref_id)
888 {
889 if($ilAccess->checkAccess('edit_event','',$ref_id))
890 {
891 $exists = true;
892 $editable = true;
893 break;
894 }
895 elseif($ilAccess->checkAccess('read','',$ref_id))
896 {
897 $exists = true;
898 }
899 }
900 if(!$exists)
901 {
902 continue;
903 }
904 $this->categories_info[$row->cat_id]['editable'] = $editable;
905
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]['color'] = $row->color;
910 #$this->categories_info[$row->cat_id]['title'] = ilObject::_lookupTitle($row->obj_id);
911 $this->categories_info[$row->cat_id]['title'] = $row->title;
912 $this->categories_info[$row->cat_id]['obj_type'] = ilObject::_lookupType($row->obj_id);
913 $this->categories_info[$row->cat_id]['type'] = $row->type;
914 $this->categories_info[$row->cat_id]['remote'] = false;
915
916 }
917 }
918
925 protected function addSubitemCalendars()
926 {
927 global $ilDB;
928
929 $course_ids = array();
930 foreach($this->categories as $cat_id)
931 {
932 if($this->categories_info[$cat_id]['obj_type'] == 'crs' or $this->categories_info[$cat_id]['obj_type'] == 'grp')
933 {
934 $course_ids[] = $this->categories_info[$cat_id]['obj_id'];
935 }
936 }
937
938 $query = "SELECT od2.obj_id sess_id, od1.obj_id crs_id,cat_id FROM object_data od1 ".
939 "JOIN object_reference or1 ON od1.obj_id = or1.obj_id ".
940 "JOIN tree t ON or1.ref_id = t.parent ".
941 "JOIN object_reference or2 ON t.child = or2.ref_id ".
942 "JOIN object_data od2 ON or2.obj_id = od2.obj_id ".
943 "JOIN cal_categories cc ON od2.obj_id = cc.obj_id ".
944 "WHERE ".$ilDB->in('od2.type',array('sess','exc'),false,'text').
945 "AND (od1.type = 'crs' OR od1.type = 'grp') ".
946 "AND ".$ilDB->in('od1.obj_id',$course_ids,false,'integer').' '.
947 "AND or2.deleted IS NULL";
948
949 $res = $ilDB->query($query);
950 $cat_ids = array();
951 $course_sessions = array();
952 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
953 {
954 $cat_ids[] = $row->cat_id;
955 $course_sessions[$row->crs_id][$row->sess_id] = $row->cat_id;
956 $this->subitem_categories[] = $row->cat_id;
957 }
958
959 foreach($this->categories as $cat_id)
960 {
961 if(
962 ($this->categories_info[$cat_id]['obj_type'] == 'crs' ||
963 $this->categories_info[$cat_id]['obj_type'] == 'grp' ) &&
964 isset($this->categories_info[$cat_id]['obj_id']) &&
965 isset($course_sessions[$this->categories_info[$cat_id]['obj_id']]) &&
966 is_array($course_sessions[$this->categories_info[$cat_id]['obj_id']]))
967 {
968 foreach($course_sessions[$this->categories_info[$cat_id]['obj_id']] as $sess_id => $sess_cat_id)
969 {
970 $this->categories_info[$cat_id]['subitem_ids'][$sess_id] = $sess_cat_id;
971 $this->categories_info[$cat_id]['subitem_obj_ids'][$sess_cat_id] = $sess_id;
972 }
973 }
974 else
975 {
976 $this->categories_info[$cat_id]['subitem_ids'] = array();
977 $this->categories_info[$cat_id]['subitem_obj_ids'] = array();
978 }
979 }
980 }
981
988 static function lookupPrivateCategories($a_user_id)
989 {
990 global $ilDB;
991
992 // First read private calendars of user
993 $set = $ilDB->query("SELECT * FROM cal_categories ".
994 "WHERE type = ".$ilDB->quote(ilCalendarCategory::TYPE_USR ,'integer')." ".
995 "AND obj_id = ".$ilDB->quote($a_user_id,'integer'));
996 $cats = array();
997 while ($rec = $ilDB->fetchAssoc($set))
998 {
999 $cats[] = $rec;
1000 }
1001 return $cats;
1002 }
1003
1004}
1005?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
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
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['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $lng
Definition: privfeed.php:40
$ref_id
Definition: sahs_server.php:39
global $ilDB
global $ilUser
Definition: imgupload.php:15