ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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)
37  const MODE_REMOTE_ACCESS = 3;
40  const MODE_MANAGE = 6;
41  const MODE_CONSULTATION = 7;
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 
78  protected function __construct($a_usr_id = 0)
79  {
80  global $ilUser,$ilDB;
81 
82  $this->logger = $GLOBALS['DIC']->logger()->cal();
83 
84  $this->user_id = $a_usr_id;
85  if (!$this->user_id) {
86  $this->user_id = $ilUser->getId();
87  }
88  $this->db = $ilDB;
89  }
90 
99  public static function _getInstance($a_usr_id = 0)
100  {
101  if (self::$instance) {
102  return self::$instance;
103  }
104  return self::$instance = new ilCalendarCategories($a_usr_id);
105  }
106 
115  public static function _lookupCategoryIdByObjId($a_obj_id)
116  {
117  global $ilDB;
118 
119  $query = "SELECT cat_id FROM cal_categories " .
120  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
121  "AND type = " . $ilDB->quote(ilCalendarCategory::TYPE_OBJ, 'integer') . " ";
122 
123  $res = $ilDB->query($query);
124  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
125  return $row->cat_id;
126  }
127  return 0;
128  }
129 
130 
140  public static function _isOwner($a_usr_id, $a_cal_id)
141  {
142  global $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 $res->numRows() ? true : false;
150  }
151 
157  public static function deletePDItemsCache($a_usr_id)
158  {
159  ilCalendarCache::getInstance()->deleteByAdditionalKeys(
160  $a_usr_id,
161  self::MODE_PERSONAL_DESKTOP_ITEMS,
162  'categories'
163  );
164  }
165 
171  public static function deleteRepositoryCache($a_usr_id)
172  {
173  ilCalendarCache::getInstance()->deleteByAdditionalKeys(
174  $a_usr_id,
175  self::MODE_REPOSITORY,
176  'categories'
177  );
178  }
179 
180 
185  protected function sleep()
186  {
187  return serialize(
188  array(
189  'categories' => $this->categories,
190  'categories_info' => $this->categories_info,
191  'subitem_categories'=> $this->subitem_categories
192  )
193  );
194  }
195 
201  protected function wakeup($a_ser)
202  {
203  $info = unserialize($a_ser);
204 
205  $this->categories = $info['categories'];
206  $this->categories_info = $info['categories_info'];
207  $this->subitem_categories = $info['subitem_categories'];
208  }
209 
214  public function setCHUserId($a_user_id)
215  {
216  $this->ch_user_id = $a_user_id;
217  }
218 
219 
224  public function getCHUserId()
225  {
226  return $this->ch_user_id;
227  }
228 
229  protected function setMode($a_mode)
230  {
231  $this->mode = $a_mode;
232  }
233 
234  public function getMode()
235  {
236  return $this->mode;
237  }
238 
239  protected function setTargetRefId($a_ref_id)
240  {
241  $this->target_ref_id = $a_ref_id;
242  }
243 
244  public function getTargetRefId()
245  {
246  return $this->target_ref_id;
247  }
248 
254  public function setSourceRefId($a_val)
255  {
256  $this->root_ref_id = $a_val;
257  }
258 
264  public function getSourceRefId()
265  {
266  return $this->root_ref_id;
267  }
268 
277  public function initialize($a_mode, $a_source_ref_id = 0, $a_use_cache = false, $a_cat_id = 0)
278  {
279  if ($this->getMode() != 0) {
280  include_once("./Services/Calendar/exceptions/class.ilCalCategoriesInitializedMultipleException.php");
281  throw new ilCalCategoriesInitializedMultipleException("ilCalendarCategories is initialized multiple times for user " . $this->user_id . ".");
282  }
283 
284  $this->setMode($a_mode);
285 
286  // see comments in https://mantis.ilias.de/view.php?id=25254
287  if ($a_use_cache && $this->getMode() != self::MODE_REPOSITORY_CONTAINER_ONLY) {
288  // Read categories from cache
289  if ($cats = ilCalendarCache::getInstance()->getEntry($this->user_id . ':' . $a_mode . ':categories:' . (int) $a_source_ref_id)) {
290  if ($this->getMode() != self::MODE_REPOSITORY &&
291  $this->getMode() != self::MODE_CONSULTATION &&
292  $this->getMode() != self::MODE_PORTFOLIO_CONSULTATION) {
293  $this->wakeup($cats);
294  return;
295  }
296  }
297  }
298 
299  switch ($this->getMode()) {
300  case self::MODE_REMOTE_ACCESS:
301  include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
303  $this->readPDCalendars();
304  } else {
305  $this->readSelectedItemCalendars();
306  }
307  break;
308 
309  case self::MODE_REMOTE_SELECTED:
310  $this->readSelectedCalendar($a_source_ref_id);
311  break;
312 
313  case self::MODE_PERSONAL_DESKTOP_MEMBERSHIP:
314  $this->readPDCalendars();
315  break;
316 
317  case self::MODE_PERSONAL_DESKTOP_ITEMS:
318  $this->readSelectedItemCalendars();
319  break;
320 
321  case self::MODE_REPOSITORY:
322  $this->root_ref_id = $a_source_ref_id;
323  $this->root_obj_id = ilObject::_lookupObjId($this->root_ref_id);
324  $this->readReposCalendars();
325  break;
326 
327  case self::MODE_REPOSITORY_CONTAINER_ONLY:
328  $this->root_ref_id = $a_source_ref_id;
329  $this->root_obj_id = ilObject::_lookupObjId($this->root_ref_id);
330  $this->readReposCalendars(true);
331  break;
332 
333  case self::MODE_MANAGE:
334  $this->readPDCalendars();
335  $this->readSelectedItemCalendars();
336  break;
337 
338  case self::MODE_CONSULTATION:
339  #$this->readPrivateCalendars();
340  $this->setTargetRefId($a_source_ref_id);
341  $this->readConsultationHoursCalendar($a_source_ref_id);
342  break;
343 
344  case self::MODE_PORTFOLIO_CONSULTATION:
346  break;
347 
348  case self::MODE_SINGLE_CALENDAR:
349  $this->readSingleCalendar($a_cat_id);
350  break;
351  }
352 
353  if ($a_use_cache) {
354  // Store in cache
355  ilCalendarCache::getInstance()->storeEntry(
356  $this->user_id . ':' . $a_mode . ':categories:' . (int) $a_source_ref_id,
357  $this->sleep(),
358  $this->user_id,
359  $a_mode,
360  'categories'
361  );
362  }
363  }
364 
372  public function getCategoryInfo($a_cat_id)
373  {
374  if (isset($this->categories_info[$a_cat_id])) {
375  return $this->categories_info[$a_cat_id];
376  }
377 
378  if (in_array($a_cat_id, (array) $this->subitem_categories)) {
379  foreach ($this->categories as $cat_id) {
380  if (in_array($a_cat_id, $this->categories_info[$cat_id]['subitem_ids'])) {
381  return $this->categories_info[$cat_id];
382  }
383  }
384  }
385  }
386 
387 
395  public function getCategoriesInfo()
396  {
397  return $this->categories_info ? $this->categories_info : array();
398  }
399 
406  public function getCategories($a_include_subitem_calendars = false)
407  {
408  if ($a_include_subitem_calendars) {
409  return array_merge((array) $this->categories, (array) $this->subitem_categories);
410  }
411 
412  return $this->categories ? $this->categories : array();
413  }
414 
421  public function getSubitemCategories($a_cat_id)
422  {
423  if (!isset($this->categories_info[$a_cat_id]['subitem_ids'])) {
424  return array($a_cat_id);
425  }
426  return array_merge((array) $this->categories_info[$a_cat_id]['subitem_ids'], array($a_cat_id));
427  }
428 
429 
438  {
439  global $lng;
440 
441  $has_personal_calendar = false;
442  foreach ($this->categories_info as $info) {
443  if ($info['obj_type'] == 'sess' || $info['obj_type'] == 'exc') {
444  continue;
445  }
446  if ($info['type'] == ilCalendarCategory::TYPE_USR and $info['editable']) {
447  $has_personal_calendar = true;
448  }
449 
450  if ($info['editable']) {
451  $cats[$info['cat_id']] = $info['title'];
452  }
453  }
454  // If there
455  if (!$has_personal_calendar) {
456  $cats[0] = $lng->txt('cal_default_calendar');
457  }
458  return $cats ? $cats : array();
459  }
460 
466  public function getNotificationCalendars()
467  {
468  $not = array();
469  foreach ($this->categories_info as $info) {
470  if ($info['type'] == ilCalendarCategory::TYPE_OBJ and $info['editable'] == true) {
471  if (ilObject::_lookupType($info['obj_id']) == 'crs' or ilObject::_lookupType($info['obj_id']) == 'grp') {
472  $not[] = $info['cat_id'];
473  }
474  }
475  }
476  return $not;
477  }
478 
486  public function isEditable($a_cat_id)
487  {
488  return isset($this->categories_info[$a_cat_id]['editable']) and $this->categories_info[$a_cat_id]['editable'];
489  }
490 
498  public function isVisible($a_cat_id)
499  {
500  return in_array($a_cat_id, $this->categories) or
501  in_array($a_cat_id, (array) $this->subitem_categories);
502  }
503 
504 
505 
506 
514  protected function readPDCalendars()
515  {
516  global $rbacsystem;
517 
518 
519  $this->readPublicCalendars();
520  $this->readPrivateCalendars();
522  $this->readBookingCalendar();
523 
524  include_once('./Services/Membership/classes/class.ilParticipants.php');
525  $this->readSelectedCategories(ilParticipants::_getMembershipByType($this->user_id, 'crs'));
526  $this->readSelectedCategories(ilParticipants::_getMembershipByType($this->user_id, 'grp'));
527 
528  $this->addSubitemCalendars();
529  }
530 
535  protected function readSelectedCalendar($a_cal_id)
536  {
537  include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
538  $cat = new ilCalendarCategory($a_cal_id);
539  if ($cat->getType() == ilCalendarCategory::TYPE_OBJ) {
540  $this->readSelectedCategories(array($cat->getObjId()));
541  $this->addSubitemCalendars();
542  } else {
543  $this->categories[] = $a_cal_id;
544  }
545  }
546 
553  protected function readSelectedItemCalendars()
554  {
555  global $ilUser,$ilAccess;
556 
557  $this->readPublicCalendars();
558  $this->readPrivateCalendars();
560  $this->readBookingCalendar();
561 
562  $obj_ids = array();
563 
564  $courses = array();
565  $groups = array();
566  $sessions = array();
567  $exercises = array();
568  foreach (ilObjUser::_lookupDesktopItems($ilUser->getId(), array('crs','grp','sess','exc')) as $item) {
569  if ($ilAccess->checkAccess('read', '', $item['ref_id'])) {
570  switch ($item['type']) {
571  case 'crs':
572  $courses[] = $item['obj_id'];
573  break;
574 
575  case 'sess':
576  $sessions[] = $item['obj_id'];
577  break;
578 
579  case 'grp':
580  $groups[] = $item['obj_id'];
581  break;
582 
583  case 'exc':
584  $exercises[] = $item['obj_id'];
585  break;
586  }
587  }
588  }
589  $this->readSelectedCategories($courses);
590  $this->readSelectedCategories($sessions);
591  $this->readSelectedCategories($groups);
592  $this->readSelectedCategories($exercises);
593 
594  $this->addSubitemCalendars();
595  }
596 
604  protected function readReposCalendars($a_container_only = false)
605  {
606  global $ilAccess,$tree;
607  global $ilDB;
608 
609  if (!$a_container_only) {
610  $this->readPublicCalendars();
611  $this->readPrivateCalendars();
612  //$this->readConsultationHoursCalendar($this->root_ref_id);
613  $this->readAllConsultationHoursCalendarOfContainer($this->root_ref_id);
614  }
615 
616 
617 
618  #$query = "SELECT ref_id,obd.obj_id obj_id FROM tree t1 ".
619  # "JOIN object_reference obr ON t1.child = obr.ref_id ".
620  # "JOIN object_data obd ON obd.obj_id = obr.obj_id ".
621  # "WHERE t1.lft >= (SELECT lft FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
622  # "AND t1.lft <= (SELECT rgt FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
623  # "AND ".$ilDB->in('type',array('crs','grp','sess'),false,'text')." ".
624  # "AND tree = 1";
625 
626  // alternative 1: do not aggregate items of current course
627  if (!true) { //
628  $subtree_query = $GLOBALS['tree']->getSubTreeQuery(
629  $this->root_ref_id,
630  array('object_reference.ref_id', 'object_data.obj_id'),
631  array('crs', 'grp', 'sess', 'exc')
632  );
633 
634  $res = $ilDB->query($subtree_query);
635  $obj_ids = array();
636  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
637  if ($tree->isDeleted($row->ref_id)) {
638  continue;
639  }
640 
641  $obj_type = ilObject::_lookupType($row->obj_id);
642  if ($obj_type == 'crs' or $obj_type == 'grp') {
643  //Added for calendar revision --> https://goo.gl/CXGTRF
644  //In 5.2-trunk, the booking pools did not appear in the marginal calendar.
645  $this->readBookingCalendar();
646  // Check for global/local activation
647  if (!ilCalendarSettings::_getInstance()->lookupCalendarActivated($row->obj_id)) {
648  continue;
649  }
650  }
651  if ($ilAccess->checkAccess('read', '', $row->ref_id)) {
652  $obj_ids[] = $row->obj_id;
653  }
654  }
655  $this->readSelectedCategories($obj_ids, $this->root_ref_id);
656  } else { // alternative 2: aggregate items of current course (discussion with timon 3.8.3017: this is the current preference)
657  $this->readSelectedCategories(array($this->root_obj_id), $this->root_ref_id);
658  }
659 
660  $this->addSubitemCalendars();
661 
662 
663  if (!$a_container_only) {
664  $this->readSelectedCategories(ilParticipants::_getMembershipByType($this->user_id, 'crs'));
665  $this->readSelectedCategories(ilParticipants::_getMembershipByType($this->user_id, 'grp'));
666  }
667  }
668 
669  public function readSingleCalendar($a_cat_id)
670  {
671  include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
672  $cat = new ilCalendarCategory($a_cat_id);
673  switch ($cat->getType()) {
675  $this->readSelectedCalendar($a_cat_id);
676  break;
677 
679  $this->readPublicCalendars(array($a_cat_id));
680  break;
681 
683  $this->readPrivateCalendars(array($a_cat_id));
684  break;
685 
687  $this->readConsultationHoursCalendar($this->root_ref_id, $a_cat_id);
688  break;
689 
691  $this->readBookingCalendar();
692  break;
693  }
694  }
695 
702  protected function readPublicCalendars($cat_ids = null)
703  {
704  global $rbacsystem,$ilAccess;
705 
706  $in = "";
707  if (is_array($cat_ids)) {
708  $in = " AND " . $this->db->in('cat_id', $cat_ids, false, 'integer') . " ";
709  }
710 
711  // global categories
712  $query = "SELECT * FROM cal_categories " .
713  "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_GLOBAL, 'integer') . " " . $in .
714  "ORDER BY title ";
715 
716  $res = $this->db->query($query);
717  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
718  $this->categories[] = $row->cat_id;
719  $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
720  $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
721  $this->categories_info[$row->cat_id]['title'] = $row->title;
722  $this->categories_info[$row->cat_id]['color'] = $row->color;
723  $this->categories_info[$row->cat_id]['type'] = $row->type;
724  $this->categories_info[$row->cat_id]['editable'] = $rbacsystem->checkAccess('edit_event', ilCalendarSettings::_getInstance()->getCalendarSettingsId());
725  $this->categories_info[$row->cat_id]['settings'] = $rbacsystem->checkAccess('write', ilCalendarSettings::_getInstance()->getCalendarSettingsId());
726  $this->categories_info[$row->cat_id]['accepted'] = false;
727  $this->categories_info[$row->cat_id]['remote'] = ($row->loc_type == ilCalendarCategory::LTYPE_REMOTE);
728  }
729 
730  return true;
731  }
732 
739  protected function readPrivateCalendars($only_cat_ids = null)
740  {
741  global $ilUser;
742  global $ilDB;
743 
744  $in = "";
745  if (is_array($only_cat_ids)) {
746  $in = " AND " . $this->db->in('cat_id', $only_cat_ids, false, 'integer') . " ";
747  }
748 
749  // First read private calendars of user
750  $query = "SELECT cat_id FROM cal_categories " .
751  "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " .
752  "AND obj_id = " . $this->db->quote($ilUser->getId(), 'integer') . " " . $in;
753  $res = $this->db->query($query);
754  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
755  $cat_ids[] = $row->cat_id;
756  }
757 
758  // Read shared calendars
759  include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
760  $accepted_ids = ilCalendarSharedStatus::getAcceptedCalendars($ilUser->getId());
761  if (!$cat_ids = array_merge((array) $cat_ids, $accepted_ids)) {
762  return true;
763  }
764 
765  if (is_array($only_cat_ids)) {
766  $cat_ids = array_filter($cat_ids, function ($id) use ($only_cat_ids) {
767  return in_array($id, $only_cat_ids);
768  });
769  }
770 
771  // user categories
772  $query = "SELECT * FROM cal_categories " .
773  "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " .
774  "AND " . $ilDB->in('cat_id', $cat_ids, false, 'integer') . " " .
775  "ORDER BY title ";
776 
777  $res = $this->db->query($query);
778  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
779  $this->categories[] = $row->cat_id;
780  $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
781  $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
782  $this->categories_info[$row->cat_id]['title'] = $row->title;
783  $this->categories_info[$row->cat_id]['color'] = $row->color;
784  $this->categories_info[$row->cat_id]['type'] = $row->type;
785 
786  include_once './Services/Calendar/classes/class.ilCalendarShared.php';
787  if (in_array($row->cat_id, $accepted_ids)) {
788  $shared = new ilCalendarShared($row->cat_id);
789  if ($shared->isEditableForUser($ilUser->getId())) {
790  $this->categories_info[$row->cat_id]['editable'] = true;
791  } else {
792  $this->categories_info[$row->cat_id]['editable'] = false;
793  }
794  } else {
795  $this->categories_info[$row->cat_id]['editable'] = true;
796  }
797  if ($ilUser->getId() == $row->obj_id) {
798  $this->categories_info[$row->cat_id]['settings'] = true;
799  } else {
800  $this->categories_info[$row->cat_id]['settings'] = false;
801  }
802 
803  $this->categories_info[$row->cat_id]['accepted'] = in_array($row->cat_id, $accepted_ids);
804  $this->categories_info[$row->cat_id]['remote'] = ($row->loc_type == ilCalendarCategory::LTYPE_REMOTE);
805  }
806  }
807 
812  public function readAllConsultationHoursCalendarOfContainer($a_container_ref_id)
813  {
814  include_once "Modules/Course/classes/class.ilCourseParticipants.php";
815  $obj_id = ilObject::_lookupObjId($a_container_ref_id);
816  $participants = ilCourseParticipants::_getInstanceByObjId($obj_id);
817  $users = array_unique(array_merge($participants->getTutors(), $participants->getAdmins()));
818  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
820  $old_ch = $this->getCHUserId();
821  foreach ($users as $user) {
822  $this->setCHUserId($user);
823  $this->readConsultationHoursCalendar($a_container_ref_id);
824  }
825  $this->setCHUserId($old_ch);
826  }
827 
833  public function readConsultationHoursCalendar($a_target_ref_id = null, $a_cat_id = 0)
834  {
835  global $ilDB, $lng;
836 
837  if (!$this->getCHUserId()) {
838  $this->setCHUserId($this->user_id);
839  }
840 
841  if ($a_target_ref_id) {
842  $target_obj_id = ilObject::_lookupObjId($a_target_ref_id);
843 
844  $query = 'SELECT DISTINCT(cc.cat_id) FROM booking_entry be ' .
845  'LEFT JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
846  'JOIN cal_entries ce ON be.booking_id = ce.context_id ' .
847  'JOIN cal_cat_assignments ca ON ce.cal_id = ca.cal_id ' .
848  'JOIN cal_categories cc ON ca.cat_id = cc.cat_id ' .
849  'WHERE ((bo.target_obj_id IS NULL) OR bo.target_obj_id = ' . $ilDB->quote($target_obj_id, 'integer') . ' ) ';
850 
851  // limit only to user if no cat id is given
852  if ($a_cat_id == 0) {
853  $query.= 'AND cc.obj_id = ' . $ilDB->quote($this->getCHUserId(), 'integer');
854  }
855 
856 
857  $res = $ilDB->query($query);
858  $categories = array();
859  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
860  if ($a_cat_id == 0 || $row->cat_id == $a_cat_id) {
861  $categories[] = $row->cat_id;
862  }
863  }
864 
865  if ($categories) {
866  $query = 'SELECT * FROM cal_categories ' .
867  'WHERE ' . $ilDB->in('cat_id', $categories, false, 'integer');
868  $res = $ilDB->query($query);
869  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
870  $this->categories[] = $row->cat_id;
871  $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
872  $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
873  $this->categories_info[$row->cat_id]['title'] = ilObjUser::_lookupFullname($row->obj_id);
874  $this->categories_info[$row->cat_id]['color'] = $row->color;
875  $this->categories_info[$row->cat_id]['type'] = $row->type;
876  $this->categories_info[$row->cat_id]['editable'] = false;
877  $this->categories_info[$row->cat_id]['settings'] = false;
878  $this->categories_info[$row->cat_id]['accepted'] = false;
879  $this->categories_info[$row->cat_id]['remote'] = false;
880  }
881  }
882  } else { // no category given
883  $filter = ($a_cat_id > 0)
884  ? " AND cat_id = " . $ilDB->quote($a_cat_id, "integer")
885  : " AND obj_id = " . $ilDB->quote($this->getCHUserId(), 'integer');
886 
887  $query = "SELECT * FROM cal_categories cc " .
888  "WHERE type = " . $ilDB->quote(ilCalendarCategory::TYPE_CH, 'integer') . ' ' . $filter;
889  $res = $ilDB->query($query);
890  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
891  $this->categories[] = $row->cat_id;
892  $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
893  $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
894  $this->categories_info[$row->cat_id]['title'] = $row->title;
895  $this->categories_info[$row->cat_id]['color'] = $row->color;
896  $this->categories_info[$row->cat_id]['type'] = $row->type;
897  $this->categories_info[$row->cat_id]['editable'] = false;
898  $this->categories_info[$row->cat_id]['settings'] = false;
899  $this->categories_info[$row->cat_id]['accepted'] = false;
900  $this->categories_info[$row->cat_id]['remote'] = false;
901  }
902  }
903  return true;
904  }
905 
911  public function readBookingCalendar($user_id = null)
912  {
913  global $ilDB;
914 
915  if (!$user_id) {
917  }
918 
919  $query = "SELECT * FROM cal_categories " .
920  "WHERE type = " . $ilDB->quote(ilCalendarCategory::TYPE_BOOK, 'integer') . ' ' .
921  "AND obj_id = " . $ilDB->quote($user_id, 'integer');
922  $res = $ilDB->query($query);
923  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
924  $this->categories[] = $row->cat_id;
925  $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
926  $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
927  $this->categories_info[$row->cat_id]['title'] = $row->title;
928  $this->categories_info[$row->cat_id]['color'] = $row->color;
929  $this->categories_info[$row->cat_id]['type'] = $row->type;
930  $this->categories_info[$row->cat_id]['editable'] = false;
931  $this->categories_info[$row->cat_id]['settings'] = false;
932  $this->categories_info[$row->cat_id]['accepted'] = false;
933  $this->categories_info[$row->cat_id]['remote'] = false;
934  }
935  }
936 
943  protected function readSelectedCategories($a_obj_ids, $a_source_ref_id = 0)
944  {
945  global $ilAccess,$tree;
946  global $ilDB;
947 
948  if (!count($a_obj_ids)) {
949  return true;
950  }
951 
952  $query = "SELECT * FROM cal_categories " .
953  "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_OBJ, 'integer') . " " .
954  "AND " . $ilDB->in('obj_id', $a_obj_ids, false, 'integer') . " " .
955  "ORDER BY title ";
956 
957  $res = $this->db->query($query);
958  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
959  // check activation/deactivation
960  $obj_type = ilObject::_lookupType($row->obj_id);
961  if ($obj_type == 'crs' or $obj_type == 'grp') {
962  if (!ilCalendarSettings::_getInstance()->lookupCalendarActivated($row->obj_id)) {
963  continue;
964  }
965  }
966 
967  $editable = false;
968  $exists = false;
969  $settings = false;
970  foreach (ilObject::_getAllReferences($row->obj_id) as $ref_id) {
971  if ($ilAccess->checkAccess('edit_event', '', $ref_id)) {
972  $settings = true;
973  }
974  if ($ilAccess->checkAccess('edit_event', '', $ref_id)) {
975  $exists = true;
976  $editable = true;
977  break;
978  } elseif ($ilAccess->checkAccess('read', '', $ref_id)) {
979  $exists = true;
980  }
981  }
982  if (!$exists) {
983  continue;
984  }
985  $this->categories_info[$row->cat_id]['editable'] = $editable;
986  $this->categories_info[$row->cat_id]['settings'] = $settings;
987 
988  $this->categories[] = $row->cat_id;
989  $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
990  $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
991  $this->categories_info[$row->cat_id]['color'] = $row->color;
992  #$this->categories_info[$row->cat_id]['title'] = ilObject::_lookupTitle($row->obj_id);
993  $this->categories_info[$row->cat_id]['title'] = $row->title;
994  $this->categories_info[$row->cat_id]['obj_type'] = ilObject::_lookupType($row->obj_id);
995  $this->categories_info[$row->cat_id]['type'] = $row->type;
996  $this->categories_info[$row->cat_id]['remote'] = false;
997  $this->categories_info[$row->cat_id]['source_ref_id'] = $a_source_ref_id;
998  }
999  }
1000 
1007  protected function addSubitemCalendars()
1008  {
1009  global $ilDB;
1010 
1011  $course_ids = array();
1012  foreach ($this->categories as $cat_id) {
1013  if ($this->categories_info[$cat_id]['obj_type'] == 'crs' or $this->categories_info[$cat_id]['obj_type'] == 'grp') {
1014  $course_ids[] = $this->categories_info[$cat_id]['obj_id'];
1015  }
1016  }
1017 
1018  $query = "SELECT od2.obj_id sess_id, od1.obj_id crs_id,cat_id FROM object_data od1 " .
1019  "JOIN object_reference or1 ON od1.obj_id = or1.obj_id " .
1020  "JOIN tree t ON or1.ref_id = t.parent " .
1021  "JOIN object_reference or2 ON t.child = or2.ref_id " .
1022  "JOIN object_data od2 ON or2.obj_id = od2.obj_id " .
1023  "JOIN cal_categories cc ON od2.obj_id = cc.obj_id " .
1024  "WHERE " . $ilDB->in('od2.type', array('sess','exc'), false, 'text') .
1025  "AND (od1.type = 'crs' OR od1.type = 'grp') " .
1026  "AND " . $ilDB->in('od1.obj_id', $course_ids, false, 'integer') . ' ' .
1027  "AND or2.deleted IS NULL";
1028 
1029  $res = $ilDB->query($query);
1030  $cat_ids = array();
1031  $course_sessions = array();
1032  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1033  $cat_ids[] = $row->cat_id;
1034  $course_sessions[$row->crs_id][$row->sess_id] = $row->cat_id;
1035  $this->subitem_categories[] = $row->cat_id;
1036  }
1037 
1038  foreach ($this->categories as $cat_id) {
1039  if (
1040  ($this->categories_info[$cat_id]['obj_type'] == 'crs' ||
1041  $this->categories_info[$cat_id]['obj_type'] == 'grp') &&
1042  isset($this->categories_info[$cat_id]['obj_id']) &&
1043  isset($course_sessions[$this->categories_info[$cat_id]['obj_id']]) &&
1044  is_array($course_sessions[$this->categories_info[$cat_id]['obj_id']])) {
1045  foreach ($course_sessions[$this->categories_info[$cat_id]['obj_id']] as $sess_id => $sess_cat_id) {
1046  $this->categories_info[$cat_id]['subitem_ids'][$sess_id] = $sess_cat_id;
1047  $this->categories_info[$cat_id]['subitem_obj_ids'][$sess_cat_id] = $sess_id;
1048  }
1049  } else {
1050  $this->categories_info[$cat_id]['subitem_ids'] = array();
1051  $this->categories_info[$cat_id]['subitem_obj_ids'] = array();
1052  }
1053  }
1054  }
1055 
1062  public static function lookupPrivateCategories($a_user_id)
1063  {
1064  global $ilDB;
1065 
1066  // First read private calendars of user
1067  $set = $ilDB->query("SELECT * FROM cal_categories " .
1068  "WHERE type = " . $ilDB->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " .
1069  "AND obj_id = " . $ilDB->quote($a_user_id, 'integer'));
1070  $cats = array();
1071  while ($rec = $ilDB->fetchAssoc($set)) {
1072  $cats[] = $rec;
1073  }
1074  return $cats;
1075  }
1076 }
class for calendar categories
static getInstance()
get singleton instance
readAllConsultationHoursCalendarOfContainer($a_container_ref_id)
Read personal consultation hours calendar of all tutors for a container.
readSelectedItemCalendars()
Read categories of selected items.
addSubitemCalendars()
Add subitem calendars E.g.
readSelectedCategories($a_obj_ids, $a_source_ref_id=0)
read selected categories
static _getInstance()
get singleton instance
Exception being thrown calendar categories is initiliazed multiple times for the same user...
static _isOwner($a_usr_id, $a_cal_id)
check if user is owner of a category
wakeup($a_ser)
Load from serialize string.
static getAcceptedCalendars($a_usr_id)
get accepted shared calendars
static _lookupFullname($a_user_id)
Lookup Full Name.
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
readReposCalendars($a_container_only=false)
Read available repository calendars.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
if(!array_key_exists('StateId', $_REQUEST)) $id
setCHUserId($a_user_id)
Set ch user id.
static _lookupCategoryIdByObjId($a_obj_id)
lookup category by obj_id
readBookingCalendar($user_id=null)
Read booking manager calendar.
sleep()
Serialize categories.
isVisible($a_cat_id)
check if category is visible
Stores calendar categories.
static deletePDItemsCache($a_usr_id)
Delete cache (add remove desktop item)
Handles shared calendars.
readPrivateCalendars($only_cat_ids=null)
Read private calendars.
static _getAllReferences($a_id)
get all reference ids of object
setSourceRefId($a_val)
Set source ref id.
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...
isEditable($a_cat_id)
check if category is editable
static deleteRepositoryCache($a_usr_id)
Delete cache.
foreach($_POST as $key=> $value) $res
getSourceRefId()
Get source ref id.
static _getInstance()
get instance for logged in user
static _lookupObjId($a_id)
initialize($a_mode, $a_source_ref_id=0, $a_use_cache=false, $a_cat_id=0)
initialize visible categories
getSubitemCategories($a_cat_id)
get subitem categories for a specific category
readSelectedCalendar($a_cal_id)
Read info about selected calendar.
$ilUser
Definition: imgupload.php:18
$query
prepareCategoriesOfUserForSelection()
prepare categories of users for selection
static _getInstance($a_usr_id=0)
get singleton instance
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
$users
Definition: authpage.php:44
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
static _lookupDesktopItems($user_id, $a_types="")
get all desktop items of user and specified type
readConsultationHoursCalendar($a_target_ref_id=null, $a_cat_id=0)
Read personal consultation hours calendar.
getCategories($a_include_subitem_calendars=false)
get categories
__construct($a_usr_id=0)
Singleton instance.
global $lng
Definition: privfeed.php:17
global $ilDB
getNotificationCalendars()
Get all calendars that allow send of notifications (Editable and course group calendars) ...
$info
Definition: index.php:5
static lookupPrivateCategories($a_user_id)
Lookup private categories of user.
readPublicCalendars($cat_ids=null)
Read public calendars.
readPDCalendars()
Read categories of user.