ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public function __construct($a_usr_id = 0)
79  {
80  global $DIC;
81 
82  $ilUser = $DIC['ilUser'];
83  $ilDB = $DIC['ilDB'];
84 
85  $this->logger = $GLOBALS['DIC']->logger()->cal();
86 
87  $this->user_id = $a_usr_id;
88  if (!$this->user_id) {
89  $this->user_id = $ilUser->getId();
90  }
91  $this->db = $ilDB;
92  }
93 
102  public static function _getInstance($a_usr_id = 0)
103  {
104  if (self::$instance) {
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 $DIC;
121 
122  $ilDB = $DIC['ilDB'];
123 
124  $query = "SELECT cat_id FROM cal_categories " .
125  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
126  "AND type = " . $ilDB->quote(ilCalendarCategory::TYPE_OBJ, 'integer') . " ";
127 
128  $res = $ilDB->query($query);
129  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
130  return $row->cat_id;
131  }
132  return 0;
133  }
134 
135 
145  public static function _isOwner($a_usr_id, $a_cal_id)
146  {
147  global $DIC;
148 
149  $ilDB = $DIC['ilDB'];
150 
151  $query = "SELECT * FROM cal_categories " .
152  "WHERE cat_id = " . $ilDB->quote($a_cal_id, 'integer') . " " .
153  "AND obj_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
154  "AND type = " . $ilDB->quote(ilCalendarCategory::TYPE_USR, 'integer') . " ";
155  $res = $ilDB->query($query);
156  return $res->numRows() ? true : false;
157  }
158 
164  public static function deletePDItemsCache($a_usr_id)
165  {
166  ilCalendarCache::getInstance()->deleteByAdditionalKeys(
167  $a_usr_id,
168  self::MODE_PERSONAL_DESKTOP_ITEMS,
169  'categories'
170  );
171  }
172 
178  public static function deleteRepositoryCache($a_usr_id)
179  {
180  ilCalendarCache::getInstance()->deleteByAdditionalKeys(
181  $a_usr_id,
182  self::MODE_REPOSITORY,
183  'categories'
184  );
185  }
186 
187 
192  protected function sleep()
193  {
194  return serialize(
195  array(
196  'categories' => $this->categories,
197  'categories_info' => $this->categories_info,
198  'subitem_categories' => $this->subitem_categories
199  )
200  );
201  }
202 
208  protected function wakeup($a_ser)
209  {
210  $info = unserialize($a_ser);
211 
212  $this->categories = $info['categories'];
213  $this->categories_info = $info['categories_info'];
214  $this->subitem_categories = $info['subitem_categories'];
215  }
216 
221  public function setCHUserId($a_user_id)
222  {
223  $this->ch_user_id = $a_user_id;
224  }
225 
226 
231  public function getCHUserId()
232  {
233  return $this->ch_user_id;
234  }
235 
236  protected function setMode($a_mode)
237  {
238  $this->mode = $a_mode;
239  }
240 
241  public function getMode()
242  {
243  return $this->mode;
244  }
245 
246  protected function setTargetRefId($a_ref_id)
247  {
248  $this->target_ref_id = $a_ref_id;
249  }
250 
251  public function getTargetRefId()
252  {
253  return $this->target_ref_id;
254  }
255 
261  public function setSourceRefId($a_val)
262  {
263  $this->root_ref_id = $a_val;
264  }
265 
271  public function getSourceRefId()
272  {
273  return $this->root_ref_id;
274  }
275 
284  public function initialize($a_mode, $a_source_ref_id = 0, $a_use_cache = false, $a_cat_id = 0)
285  {
286  if ($this->getMode() != 0) {
287  include_once("./Services/Calendar/exceptions/class.ilCalCategoriesInitializedMultipleException.php");
288  throw new ilCalCategoriesInitializedMultipleException("ilCalendarCategories is initialized multiple times for user " . $this->user_id . ".");
289  }
290 
291  $this->setMode($a_mode);
292 
293  // see comments in https://mantis.ilias.de/view.php?id=25254
294  if ($a_use_cache && $this->getMode() != self::MODE_REPOSITORY_CONTAINER_ONLY) {
295  // Read categories from cache
296  if ($cats = ilCalendarCache::getInstance()->getEntry($this->user_id . ':' . $a_mode . ':categories:' . (int) $a_source_ref_id)) {
297  if ($this->getMode() != self::MODE_REPOSITORY &&
298  $this->getMode() != self::MODE_CONSULTATION &&
299  $this->getMode() != self::MODE_PORTFOLIO_CONSULTATION) {
300  $this->wakeup($cats);
301  return;
302  }
303  }
304  }
305 
306  switch ($this->getMode()) {
307  case self::MODE_REMOTE_ACCESS:
308  include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
310  $this->readPDCalendars();
311  } else {
312  $this->readSelectedItemCalendars();
313  }
314  break;
315 
316  case self::MODE_REMOTE_SELECTED:
317  $this->readSelectedCalendar($a_source_ref_id);
318  break;
319 
320  case self::MODE_PERSONAL_DESKTOP_MEMBERSHIP:
321  $this->readPDCalendars();
322  break;
323 
324  case self::MODE_PERSONAL_DESKTOP_ITEMS:
325  $this->readSelectedItemCalendars();
326  break;
327 
328  case self::MODE_REPOSITORY:
329  $this->root_ref_id = $a_source_ref_id;
330  $this->root_obj_id = ilObject::_lookupObjId($this->root_ref_id);
331  $this->readReposCalendars();
332  break;
333 
334  case self::MODE_REPOSITORY_CONTAINER_ONLY:
335  $this->root_ref_id = $a_source_ref_id;
336  $this->root_obj_id = ilObject::_lookupObjId($this->root_ref_id);
337  $this->readReposCalendars(true);
338  break;
339 
340  case self::MODE_MANAGE:
341  $this->readPDCalendars();
342  $this->readSelectedItemCalendars();
343  break;
344 
345  case self::MODE_CONSULTATION:
346  #$this->readPrivateCalendars();
347  $this->setTargetRefId($a_source_ref_id);
348  $this->readConsultationHoursCalendar($a_source_ref_id);
349  break;
350 
351  case self::MODE_PORTFOLIO_CONSULTATION:
353  break;
354 
355  case self::MODE_SINGLE_CALENDAR:
356  $this->readSingleCalendar($a_cat_id);
357  break;
358  }
359 
360  if ($a_use_cache) {
361  // Store in cache
362  ilCalendarCache::getInstance()->storeEntry(
363  $this->user_id . ':' . $a_mode . ':categories:' . (int) $a_source_ref_id,
364  $this->sleep(),
365  $this->user_id,
366  $a_mode,
367  'categories'
368  );
369  }
370  }
371 
379  public function getCategoryInfo($a_cat_id)
380  {
381  if (isset($this->categories_info[$a_cat_id])) {
382  return $this->categories_info[$a_cat_id];
383  }
384 
385  if (in_array($a_cat_id, (array) $this->subitem_categories)) {
386  foreach ($this->categories as $cat_id) {
387  if (in_array($a_cat_id, $this->categories_info[$cat_id]['subitem_ids'])) {
388  return $this->categories_info[$cat_id];
389  }
390  }
391  }
392  }
393 
394 
402  public function getCategoriesInfo()
403  {
404  return $this->categories_info ? $this->categories_info : array();
405  }
406 
413  public function getCategories($a_include_subitem_calendars = false)
414  {
415  if ($a_include_subitem_calendars) {
416  return array_merge((array) $this->categories, (array) $this->subitem_categories);
417  }
418 
419  return $this->categories ? $this->categories : array();
420  }
421 
428  public function getSubitemCategories($a_cat_id)
429  {
430  if (!isset($this->categories_info[$a_cat_id]['subitem_ids'])) {
431  return array($a_cat_id);
432  }
433  return array_merge((array) $this->categories_info[$a_cat_id]['subitem_ids'], array($a_cat_id));
434  }
435 
436 
445  {
446  global $DIC;
447 
448  $lng = $DIC['lng'];
449 
450  $has_personal_calendar = false;
451  foreach ($this->categories_info as $info) {
452  if ($info['obj_type'] == 'sess' || $info['obj_type'] == 'exc') {
453  continue;
454  }
455  if ($info['type'] == ilCalendarCategory::TYPE_USR and $info['editable']) {
456  $has_personal_calendar = true;
457  }
458 
459  if ($info['editable']) {
460  $cats[$info['cat_id']] = $info['title'];
461  }
462  }
463  // If there
464  if (!$has_personal_calendar) {
465  $cats[0] = $lng->txt('cal_default_calendar');
466  }
467  return $cats ? $cats : array();
468  }
469 
475  public function getNotificationCalendars()
476  {
477  $not = array();
478  foreach ($this->categories_info as $info) {
479  if ($info['type'] == ilCalendarCategory::TYPE_OBJ and $info['editable'] == true) {
480  if (ilObject::_lookupType($info['obj_id']) == 'crs' or ilObject::_lookupType($info['obj_id']) == 'grp') {
481  $not[] = $info['cat_id'];
482  }
483  }
484  }
485  return $not;
486  }
487 
495  public function isEditable($a_cat_id)
496  {
497  return isset($this->categories_info[$a_cat_id]['editable']) and $this->categories_info[$a_cat_id]['editable'];
498  }
499 
507  public function isVisible($a_cat_id)
508  {
509  return in_array($a_cat_id, $this->categories) or
510  in_array($a_cat_id, (array) $this->subitem_categories);
511  }
512 
513 
514 
515 
523  protected function readPDCalendars()
524  {
525  global $DIC;
526 
527  $rbacsystem = $DIC['rbacsystem'];
528 
529 
530  $this->readPublicCalendars();
531  $this->readPrivateCalendars();
533  $this->readBookingCalendar();
534 
535  include_once('./Services/Membership/classes/class.ilParticipants.php');
536  $this->readSelectedCategories(ilParticipants::_getMembershipByType($this->user_id, 'crs'));
537  $this->readSelectedCategories(ilParticipants::_getMembershipByType($this->user_id, 'grp'));
538 
539  $this->addSubitemCalendars();
540  }
541 
546  protected function readSelectedCalendar($a_cal_id)
547  {
548  include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
549  $cat = new ilCalendarCategory($a_cal_id);
550  if ($cat->getType() == ilCalendarCategory::TYPE_OBJ) {
551  $this->readSelectedCategories(array($cat->getObjId()));
552  $this->addSubitemCalendars();
553  } else {
554  $this->categories[] = $a_cal_id;
555  }
556  }
557 
564  protected function readSelectedItemCalendars()
565  {
566  global $DIC;
567 
568  $ilUser = $DIC['ilUser'];
569  $ilAccess = $DIC['ilAccess'];
570 
571  $this->readPublicCalendars();
572  $this->readPrivateCalendars();
574  $this->readBookingCalendar();
575 
576  $obj_ids = array();
577 
578  $courses = array();
579  $groups = array();
580  $sessions = array();
581  $exercises = array();
582  foreach (ilObjUser::_lookupDesktopItems($ilUser->getId(), array('crs','grp','sess','exc')) as $item) {
583  if ($ilAccess->checkAccess('read', '', $item['ref_id'])) {
584  switch ($item['type']) {
585  case 'crs':
586  $courses[] = $item['obj_id'];
587  break;
588 
589  case 'sess':
590  $sessions[] = $item['obj_id'];
591  break;
592 
593  case 'grp':
594  $groups[] = $item['obj_id'];
595  break;
596 
597  case 'exc':
598  $exercises[] = $item['obj_id'];
599  break;
600  }
601  }
602  }
603  $this->readSelectedCategories($courses);
604  $this->readSelectedCategories($sessions);
605  $this->readSelectedCategories($groups);
606  $this->readSelectedCategories($exercises);
607 
608  $this->addSubitemCalendars();
609  }
610 
618  protected function readReposCalendars($a_container_only = false)
619  {
620  global $DIC;
621 
622  $ilAccess = $DIC['ilAccess'];
623  $tree = $DIC['tree'];
624  global $DIC;
625 
626  $ilDB = $DIC['ilDB'];
627 
628  if (!$a_container_only) {
629  $this->readPublicCalendars();
630  $this->readPrivateCalendars();
631  //$this->readConsultationHoursCalendar($this->root_ref_id);
632  $this->readAllConsultationHoursCalendarOfContainer($this->root_ref_id);
633  }
634 
635 
636 
637  #$query = "SELECT ref_id,obd.obj_id obj_id FROM tree t1 ".
638  # "JOIN object_reference obr ON t1.child = obr.ref_id ".
639  # "JOIN object_data obd ON obd.obj_id = obr.obj_id ".
640  # "WHERE t1.lft >= (SELECT lft FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
641  # "AND t1.lft <= (SELECT rgt FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
642  # "AND ".$ilDB->in('type',array('crs','grp','sess'),false,'text')." ".
643  # "AND tree = 1";
644 
645  // alternative 1: do not aggregate items of current course
646  if (!true) { //
647  $subtree_query = $GLOBALS['DIC']['tree']->getSubTreeQuery(
648  $this->root_ref_id,
649  array('object_reference.ref_id', 'object_data.obj_id'),
650  array('crs', 'grp', 'sess', 'exc')
651  );
652 
653  $res = $ilDB->query($subtree_query);
654  $obj_ids = array();
655  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
656  if ($tree->isDeleted($row->ref_id)) {
657  continue;
658  }
659 
660  $obj_type = ilObject::_lookupType($row->obj_id);
661  if ($obj_type == 'crs' or $obj_type == 'grp') {
662  //Added for calendar revision --> https://goo.gl/CXGTRF
663  //In 5.2-trunk, the booking pools did not appear in the marginal calendar.
664  $this->readBookingCalendar();
665  // Check for global/local activation
666  if (!ilCalendarSettings::_getInstance()->lookupCalendarActivated($row->obj_id)) {
667  continue;
668  }
669  }
670  if ($ilAccess->checkAccess('read', '', $row->ref_id)) {
671  $obj_ids[] = $row->obj_id;
672  }
673  }
674  $this->readSelectedCategories($obj_ids, $this->root_ref_id);
675  } else { // alternative 2: aggregate items of current course (discussion with timon 3.8.3017: this is the current preference)
676  $this->readSelectedCategories(array($this->root_obj_id), $this->root_ref_id);
677  }
678 
679  $this->addSubitemCalendars();
680 
681 
682  if (!$a_container_only) {
683  $this->readSelectedCategories(ilParticipants::_getMembershipByType($this->user_id, 'crs'));
684  $this->readSelectedCategories(ilParticipants::_getMembershipByType($this->user_id, 'grp'));
685  }
686  }
687 
688  public function readSingleCalendar($a_cat_id)
689  {
690  include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
691  $cat = new ilCalendarCategory($a_cat_id);
692  switch ($cat->getType()) {
694  $this->readSelectedCalendar($a_cat_id);
695  break;
696 
698  $this->readPublicCalendars(array($a_cat_id));
699  break;
700 
702  $this->readPrivateCalendars(array($a_cat_id));
703  break;
704 
706  $this->readConsultationHoursCalendar($this->root_ref_id, $a_cat_id);
707  break;
708 
710  $this->readBookingCalendar();
711  break;
712  }
713  }
714 
721  protected function readPublicCalendars($cat_ids = null)
722  {
723  global $DIC;
724 
725  $rbacsystem = $DIC['rbacsystem'];
726  $ilAccess = $DIC['ilAccess'];
727 
728  $in = "";
729  if (is_array($cat_ids)) {
730  $in = " AND " . $this->db->in('cat_id', $cat_ids, false, 'integer') . " ";
731  }
732 
733  // global categories
734  $query = "SELECT * FROM cal_categories " .
735  "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_GLOBAL, 'integer') . " " . $in .
736  "ORDER BY title ";
737 
738  $res = $this->db->query($query);
739  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
740  $this->categories[] = $row->cat_id;
741  $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
742  $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
743  $this->categories_info[$row->cat_id]['title'] = $row->title;
744  $this->categories_info[$row->cat_id]['color'] = $row->color;
745  $this->categories_info[$row->cat_id]['type'] = $row->type;
746  $this->categories_info[$row->cat_id]['editable'] = $rbacsystem->checkAccess('edit_event', ilCalendarSettings::_getInstance()->getCalendarSettingsId());
747  $this->categories_info[$row->cat_id]['settings'] = $rbacsystem->checkAccess('write', ilCalendarSettings::_getInstance()->getCalendarSettingsId());
748  $this->categories_info[$row->cat_id]['accepted'] = false;
749  $this->categories_info[$row->cat_id]['remote'] = ($row->loc_type == ilCalendarCategory::LTYPE_REMOTE);
750  }
751 
752  return true;
753  }
754 
761  protected function readPrivateCalendars($only_cat_ids = null)
762  {
763  global $DIC;
764 
765  $ilUser = $DIC['ilUser'];
766  global $DIC;
767 
768  $ilDB = $DIC['ilDB'];
769 
770  $in = "";
771  if (is_array($only_cat_ids)) {
772  $in = " AND " . $this->db->in('cat_id', $only_cat_ids, false, 'integer') . " ";
773  }
774 
775  // First read private calendars of user
776  $query = "SELECT cat_id FROM cal_categories " .
777  "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " .
778  "AND obj_id = " . $this->db->quote($ilUser->getId(), 'integer') . " " . $in;
779  $res = $this->db->query($query);
780  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
781  $cat_ids[] = $row->cat_id;
782  }
783 
784  // Read shared calendars
785  include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
786  $accepted_ids = ilCalendarSharedStatus::getAcceptedCalendars($ilUser->getId());
787  if (!$cat_ids = array_merge((array) $cat_ids, $accepted_ids)) {
788  return true;
789  }
790 
791  if (is_array($only_cat_ids)) {
792  $cat_ids = array_filter($cat_ids, function ($id) use ($only_cat_ids) {
793  return in_array($id, $only_cat_ids);
794  });
795  }
796 
797  // user categories
798  $query = "SELECT * FROM cal_categories " .
799  "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " .
800  "AND " . $ilDB->in('cat_id', $cat_ids, false, 'integer') . " " .
801  "ORDER BY title ";
802 
803  $res = $this->db->query($query);
804  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
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 
812  include_once './Services/Calendar/classes/class.ilCalendarShared.php';
813  if (in_array($row->cat_id, $accepted_ids)) {
814  $shared = new ilCalendarShared($row->cat_id);
815  if ($shared->isEditableForUser($ilUser->getId())) {
816  $this->categories_info[$row->cat_id]['editable'] = true;
817  } else {
818  $this->categories_info[$row->cat_id]['editable'] = false;
819  }
820  } else {
821  $this->categories_info[$row->cat_id]['editable'] = true;
822  }
823  if ($ilUser->getId() == $row->obj_id) {
824  $this->categories_info[$row->cat_id]['settings'] = true;
825  } else {
826  $this->categories_info[$row->cat_id]['settings'] = false;
827  }
828 
829  $this->categories_info[$row->cat_id]['accepted'] = in_array($row->cat_id, $accepted_ids);
830  $this->categories_info[$row->cat_id]['remote'] = ($row->loc_type == ilCalendarCategory::LTYPE_REMOTE);
831  }
832  }
833 
838  public function readAllConsultationHoursCalendarOfContainer($a_container_ref_id)
839  {
840  include_once "Modules/Course/classes/class.ilCourseParticipants.php";
841  $obj_id = ilObject::_lookupObjId($a_container_ref_id);
842  $participants = ilCourseParticipants::_getInstanceByObjId($obj_id);
843  $users = array_unique(array_merge($participants->getTutors(), $participants->getAdmins()));
844  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
846  $old_ch = $this->getCHUserId();
847  foreach ($users as $user) {
848  $this->setCHUserId($user);
849  $this->readConsultationHoursCalendar($a_container_ref_id);
850  }
851  $this->setCHUserId($old_ch);
852  }
853 
859  public function readConsultationHoursCalendar($a_target_ref_id = null, $a_cat_id = 0)
860  {
861  global $DIC;
862 
863  $ilDB = $DIC['ilDB'];
864  $lng = $DIC['lng'];
865 
866  if (!$this->getCHUserId()) {
867  $this->setCHUserId($this->user_id);
868  }
869 
870  if ($a_target_ref_id) {
871  $target_obj_id = ilObject::_lookupObjId($a_target_ref_id);
872 
873  $query = 'SELECT DISTINCT(cc.cat_id) FROM booking_entry be ' .
874  'LEFT JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
875  'JOIN cal_entries ce ON be.booking_id = ce.context_id ' .
876  'JOIN cal_cat_assignments ca ON ce.cal_id = ca.cal_id ' .
877  'JOIN cal_categories cc ON ca.cat_id = cc.cat_id ' .
878  'WHERE ((bo.target_obj_id IS NULL) OR bo.target_obj_id = ' . $ilDB->quote($target_obj_id, 'integer') . ' ) ';
879 
880  // limit only to user if no cat id is given
881  if ($a_cat_id == 0) {
882  $query .= 'AND cc.obj_id = ' . $ilDB->quote($this->getCHUserId(), 'integer');
883  }
884 
885 
886  $res = $ilDB->query($query);
887  $categories = array();
888  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
889  if ($a_cat_id == 0 || $row->cat_id == $a_cat_id) {
890  $categories[] = $row->cat_id;
891  }
892  }
893 
894  if ($categories) {
895  $query = 'SELECT * FROM cal_categories ' .
896  'WHERE ' . $ilDB->in('cat_id', $categories, false, 'integer');
897  $res = $ilDB->query($query);
898  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
899  $this->categories[] = $row->cat_id;
900  $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
901  $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
902  $this->categories_info[$row->cat_id]['title'] = ilObjUser::_lookupFullname($row->obj_id);
903  $this->categories_info[$row->cat_id]['color'] = $row->color;
904  $this->categories_info[$row->cat_id]['type'] = $row->type;
905  $this->categories_info[$row->cat_id]['editable'] = false;
906  $this->categories_info[$row->cat_id]['settings'] = false;
907  $this->categories_info[$row->cat_id]['accepted'] = false;
908  $this->categories_info[$row->cat_id]['remote'] = false;
909  }
910  }
911  } else { // no category given
912  $filter = ($a_cat_id > 0)
913  ? " AND cat_id = " . $ilDB->quote($a_cat_id, "integer")
914  : " AND obj_id = " . $ilDB->quote($this->getCHUserId(), 'integer');
915 
916  $query = "SELECT * FROM cal_categories cc " .
917  "WHERE type = " . $ilDB->quote(ilCalendarCategory::TYPE_CH, 'integer') . ' ' . $filter;
918  $res = $ilDB->query($query);
919  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
920  $this->categories[] = $row->cat_id;
921  $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
922  $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
923  $this->categories_info[$row->cat_id]['title'] = $row->title;
924  $this->categories_info[$row->cat_id]['color'] = $row->color;
925  $this->categories_info[$row->cat_id]['type'] = $row->type;
926  $this->categories_info[$row->cat_id]['editable'] = false;
927  $this->categories_info[$row->cat_id]['settings'] = false;
928  $this->categories_info[$row->cat_id]['accepted'] = false;
929  $this->categories_info[$row->cat_id]['remote'] = false;
930  }
931  }
932  return true;
933  }
934 
940  public function readBookingCalendar($user_id = null)
941  {
942  global $DIC;
943 
944  $ilDB = $DIC['ilDB'];
945 
946  if (!$user_id) {
948  }
949 
950  $query = "SELECT * FROM cal_categories " .
951  "WHERE type = " . $ilDB->quote(ilCalendarCategory::TYPE_BOOK, 'integer') . ' ' .
952  "AND obj_id = " . $ilDB->quote($user_id, 'integer');
953  $res = $ilDB->query($query);
954  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
955  $this->categories[] = $row->cat_id;
956  $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
957  $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
958  $this->categories_info[$row->cat_id]['title'] = $row->title;
959  $this->categories_info[$row->cat_id]['color'] = $row->color;
960  $this->categories_info[$row->cat_id]['type'] = $row->type;
961  $this->categories_info[$row->cat_id]['editable'] = false;
962  $this->categories_info[$row->cat_id]['settings'] = false;
963  $this->categories_info[$row->cat_id]['accepted'] = false;
964  $this->categories_info[$row->cat_id]['remote'] = false;
965  }
966  }
967 
974  protected function readSelectedCategories($a_obj_ids, $a_source_ref_id = 0)
975  {
976  global $DIC;
977 
978  $ilAccess = $DIC['ilAccess'];
979  $tree = $DIC['tree'];
980  global $DIC;
981 
982  $ilDB = $DIC['ilDB'];
983 
984  if (!count($a_obj_ids)) {
985  return true;
986  }
987 
988  $query = "SELECT * FROM cal_categories " .
989  "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_OBJ, 'integer') . " " .
990  "AND " . $ilDB->in('obj_id', $a_obj_ids, false, 'integer') . " " .
991  "ORDER BY title ";
992 
993  $res = $this->db->query($query);
994  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
995  // check activation/deactivation
996  $obj_type = ilObject::_lookupType($row->obj_id);
997  if ($obj_type == 'crs' or $obj_type == 'grp') {
998  if (!ilCalendarSettings::_getInstance()->lookupCalendarActivated($row->obj_id)) {
999  continue;
1000  }
1001  }
1002 
1003  $editable = false;
1004  $exists = false;
1005  $settings = false;
1006  foreach (ilObject::_getAllReferences($row->obj_id) as $ref_id) {
1007  if ($ilAccess->checkAccess('edit_event', '', $ref_id)) {
1008  $settings = true;
1009  }
1010  if ($ilAccess->checkAccess('edit_event', '', $ref_id)) {
1011  $exists = true;
1012  $editable = true;
1013  break;
1014  } elseif ($ilAccess->checkAccess('read', '', $ref_id)) {
1015  $exists = true;
1016  }
1017  }
1018  if (!$exists) {
1019  continue;
1020  }
1021  $this->categories_info[$row->cat_id]['editable'] = $editable;
1022  $this->categories_info[$row->cat_id]['settings'] = $settings;
1023 
1024  $this->categories[] = $row->cat_id;
1025  $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
1026  $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
1027  $this->categories_info[$row->cat_id]['color'] = $row->color;
1028  #$this->categories_info[$row->cat_id]['title'] = ilObject::_lookupTitle($row->obj_id);
1029  $this->categories_info[$row->cat_id]['title'] = $row->title;
1030  $this->categories_info[$row->cat_id]['obj_type'] = ilObject::_lookupType($row->obj_id);
1031  $this->categories_info[$row->cat_id]['type'] = $row->type;
1032  $this->categories_info[$row->cat_id]['remote'] = false;
1033  $this->categories_info[$row->cat_id]['source_ref_id'] = $a_source_ref_id;
1034  }
1035  }
1036 
1043  protected function addSubitemCalendars()
1044  {
1045  global $DIC;
1046 
1047  $ilDB = $DIC->database();
1048  $access = $DIC->access();
1049 
1050  $course_ids = array();
1051  foreach ($this->categories as $cat_id) {
1052  if ($this->categories_info[$cat_id]['obj_type'] == 'crs' or $this->categories_info[$cat_id]['obj_type'] == 'grp') {
1053  $course_ids[] = $this->categories_info[$cat_id]['obj_id'];
1054  }
1055  }
1056 
1057  $query = "SELECT od2.obj_id sess_id, od1.obj_id crs_id,cat_id, or2.ref_id sess_ref_id FROM object_data od1 " .
1058  "JOIN object_reference or1 ON od1.obj_id = or1.obj_id " .
1059  "JOIN tree t ON or1.ref_id = t.parent " .
1060  "JOIN object_reference or2 ON t.child = or2.ref_id " .
1061  "JOIN object_data od2 ON or2.obj_id = od2.obj_id " .
1062  "JOIN cal_categories cc ON od2.obj_id = cc.obj_id " .
1063  "WHERE " . $ilDB->in('od2.type', array('sess','exc'), false, 'text') .
1064  "AND (od1.type = 'crs' OR od1.type = 'grp') " .
1065  "AND " . $ilDB->in('od1.obj_id', $course_ids, false, 'integer') . ' ' .
1066  "AND or2.deleted IS NULL";
1067 
1068  $res = $ilDB->query($query);
1069  $cat_ids = array();
1070  $course_sessions = array();
1071  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1072  if (
1073  !$access->checkAccessOfUser($this->user_id, 'read', '', $row->sess_ref_id) ||
1074  !$access->checkAccessOfUser($this->user_id, 'visible', '', $row->sess_ref_id)
1075  ) {
1076  continue;
1077  }
1078  $cat_ids[] = $row->cat_id;
1079  $course_sessions[$row->crs_id][$row->sess_id] = $row->cat_id;
1080  $this->subitem_categories[] = $row->cat_id;
1081  }
1082 
1083  foreach ($this->categories as $cat_id) {
1084  if (
1085  ($this->categories_info[$cat_id]['obj_type'] == 'crs' ||
1086  $this->categories_info[$cat_id]['obj_type'] == 'grp') &&
1087  isset($this->categories_info[$cat_id]['obj_id']) &&
1088  isset($course_sessions[$this->categories_info[$cat_id]['obj_id']]) &&
1089  is_array($course_sessions[$this->categories_info[$cat_id]['obj_id']])) {
1090  foreach ($course_sessions[$this->categories_info[$cat_id]['obj_id']] as $sess_id => $sess_cat_id) {
1091  $this->categories_info[$cat_id]['subitem_ids'][$sess_id] = $sess_cat_id;
1092  $this->categories_info[$cat_id]['subitem_obj_ids'][$sess_cat_id] = $sess_id;
1093  }
1094  } else {
1095  $this->categories_info[$cat_id]['subitem_ids'] = array();
1096  $this->categories_info[$cat_id]['subitem_obj_ids'] = array();
1097  }
1098  }
1099  }
1100 
1107  public static function lookupPrivateCategories($a_user_id)
1108  {
1109  global $DIC;
1110 
1111  $ilDB = $DIC['ilDB'];
1112 
1113  // First read private calendars of user
1114  $set = $ilDB->query("SELECT * FROM cal_categories " .
1115  "WHERE type = " . $ilDB->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " .
1116  "AND obj_id = " . $ilDB->quote($a_user_id, 'integer'));
1117  $cats = array();
1118  while ($rec = $ilDB->fetchAssoc($set)) {
1119  $cats[] = $rec;
1120  }
1121  return $cats;
1122  }
1123 }
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
global $DIC
Definition: saml.php:7
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
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
$lng
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
$user
Definition: migrateto20.php:57
static _getInstance($a_usr_id=0)
get singleton instance
static _lookupType($a_id, $a_reference=false)
lookup object type
$users
Definition: authpage.php:44
$row
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 $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.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.