3 declare(strict_types=1);
53 protected int $mode = self::MODE_UNDEFINED;
72 $this->
user = $DIC->user();
73 $this->db = $DIC->database();
74 $this->
logger = $DIC->logger()->cal();
75 $this->
lng = $DIC->language();
76 $this->rbacsystem = $DIC->rbac()->system();
77 $this->
access = $DIC->access();
78 $this->user_id = $a_usr_id;
79 $this->tree = $DIC->repositoryTree();
80 if (!$this->user_id) {
81 $this->user_id = $this->
user->getId();
91 if (self::$instance) {
92 return self::$instance;
104 $db = $DIC->database();
106 $query =
'SELECT cat_id FROM cal_categories ' .
123 $ilDB = $DIC->database();
124 $query =
"SELECT cat_id FROM cal_categories " .
125 "WHERE obj_id = " .
$ilDB->quote($a_obj_id,
'integer') .
" " .
130 return (
int) $row->cat_id;
138 public static function _isOwner(
int $a_usr_id,
int $a_cal_id): bool
142 $ilDB = $DIC[
'ilDB'];
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') .
" " .
149 return (
bool)
$res->numRows();
159 self::MODE_PERSONAL_DESKTOP_ITEMS,
171 self::MODE_REPOSITORY,
179 final protected function sleep(): string
183 'categories' => $this->categories,
184 'categories_info' => $this->categories_info,
185 'subitem_categories' => $this->subitem_categories
193 protected function wakeup(
string $a_ser): void
195 $info = unserialize($a_ser);
197 $this->categories = $info[
'categories'];
198 $this->categories_info = $info[
'categories_info'];
199 $this->subitem_categories = $info[
'subitem_categories'];
207 $this->ch_user_id = $a_user_id;
217 $this->mode = $a_mode;
227 $this->target_ref_id = $a_ref_id;
237 $this->root_ref_id = $a_val;
252 int $a_source_ref_id = 0,
253 bool $a_use_cache =
false,
263 if ($a_use_cache && $this->
getMode() != self::MODE_REPOSITORY_CONTAINER_ONLY) {
266 if ($this->
getMode() != self::MODE_REPOSITORY &&
267 $this->
getMode() != self::MODE_CONSULTATION &&
268 $this->
getMode() != self::MODE_PORTFOLIO_CONSULTATION) {
276 case self::MODE_REMOTE_ACCESS:
284 case self::MODE_REMOTE_SELECTED:
288 case self::MODE_PERSONAL_DESKTOP_MEMBERSHIP:
292 case self::MODE_PERSONAL_DESKTOP_ITEMS:
296 case self::MODE_REPOSITORY:
297 $this->root_ref_id = $a_source_ref_id;
302 case self::MODE_REPOSITORY_CONTAINER_ONLY:
303 $this->root_ref_id = $a_source_ref_id;
308 case self::MODE_MANAGE:
313 case self::MODE_CONSULTATION:
314 #$this->readPrivateCalendars(); 319 case self::MODE_PORTFOLIO_CONSULTATION:
323 case self::MODE_SINGLE_CALENDAR:
331 $this->user_id .
':' . $a_mode .
':categories:' . $a_source_ref_id,
342 if (isset($this->categories_info[$a_cat_id])) {
343 return $this->categories_info[$a_cat_id];
346 if (in_array($a_cat_id, $this->subitem_categories)) {
347 foreach ($this->categories as $cat_id) {
348 if (in_array($a_cat_id, $this->categories_info[$cat_id][
'subitem_ids'])) {
349 return $this->categories_info[$cat_id];
358 return $this->categories_info ?: array();
361 public function getCategories(
bool $a_include_subitem_calendars =
false): array
363 if ($a_include_subitem_calendars) {
364 return array_merge($this->categories, $this->subitem_categories);
367 return $this->categories ?: array();
372 if (!isset($this->categories_info[$a_cat_id][
'subitem_ids'])) {
373 return array($a_cat_id);
375 return array_merge((array) $this->categories_info[$a_cat_id][
'subitem_ids'], array($a_cat_id));
380 $has_personal_calendar =
false;
382 foreach ($this->categories_info as $info) {
383 if ($info[
'obj_type'] ==
'sess' || $info[
'obj_type'] ==
'exc') {
392 $has_personal_calendar =
true;
395 if ($info[
'editable']) {
396 $cats[$info[
'cat_id']] = $info[
'title'];
400 if (!$has_personal_calendar) {
401 $cats[0] = $this->
lng->txt(
'cal_default_calendar');
413 foreach ($this->categories_info as $info) {
416 $not[] = (
int) $info[
'cat_id'];
428 return isset($this->categories_info[$a_cat_id][
'editable']) && $this->categories_info[$a_cat_id][
'editable'];
436 return in_array($a_cat_id, $this->categories) || in_array($a_cat_id, $this->subitem_categories);
470 $this->categories[] = $a_cal_id;
486 $exercises = array();
487 foreach ($this->fav_rep->getFavouritesOfUser(
488 $this->user->getId(),
489 array(
'crs',
'grp',
'sess',
'exc')
491 if ($this->
access->checkAccess(
'read',
'', $item[
'ref_id'])) {
492 switch ($item[
'type']) {
494 $courses[] = $item[
'obj_id'];
498 $sessions[] = $item[
'obj_id'];
502 $groups[] = $item[
'obj_id'];
506 $exercises[] = $item[
'obj_id'];
529 if (!$a_container_only) {
536 #$query = "SELECT ref_id,obd.obj_id obj_id FROM tree t1 ". 537 # "JOIN object_reference obr ON t1.child = obr.ref_id ". 538 # "JOIN object_data obd ON obd.obj_id = obr.obj_id ". 539 # "WHERE t1.lft >= (SELECT lft FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ". 540 # "AND t1.lft <= (SELECT rgt FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ". 541 # "AND ".$ilDB->in('type',array('crs','grp','sess'),false,'text')." ". 546 $subtree_query =
$GLOBALS[
'DIC'][
'tree']->getSubTreeQuery(
548 array(
'object_reference.ref_id',
'object_data.obj_id'),
549 array(
'crs',
'grp',
'sess',
'exc')
552 $res = $this->db->query($subtree_query);
555 if ($this->tree->isDeleted((
int) $row->ref_id)) {
560 if ($obj_type ==
'crs' or $obj_type ==
'grp') {
569 if ($this->
access->checkAccess(
'read',
'', (
int) $row->ref_id)) {
570 $obj_ids[] = (
int) $row->obj_id;
578 if (!$a_container_only) {
594 switch ($cat->getType()) {
623 if (is_array($cat_ids)) {
624 $in =
" AND " . $this->db->in(
'cat_id', $cat_ids,
false,
'integer') .
" ";
628 $query =
"SELECT * FROM cal_categories " .
634 $this->categories[] = (
int) $row->cat_id;
635 $this->categories_info[(
int) $row->cat_id][
'obj_type'] =
'';
636 $this->categories_info[(
int) $row->cat_id][
'source_ref_id'] = 0;
637 $this->categories_info[(
int) $row->cat_id][
'obj_id'] = (
int) $row->obj_id;
638 $this->categories_info[(
int) $row->cat_id][
'cat_id'] = (
int) $row->cat_id;
639 $this->categories_info[(
int) $row->cat_id][
'title'] = $row->title;
640 $this->categories_info[(
int) $row->cat_id][
'color'] = $row->color;
641 $this->categories_info[(
int) $row->cat_id][
'type'] = (
int) $row->type;
642 $this->categories_info[(
int) $row->cat_id][
'editable'] = $this->rbacsystem->checkAccess(
646 $this->categories_info[(
int) $row->cat_id][
'settings'] = $this->rbacsystem->checkAccess(
650 $this->categories_info[(
int) $row->cat_id][
'accepted'] =
false;
662 if (is_array($only_cat_ids)) {
663 $in =
" AND " . $this->db->in(
'cat_id', $only_cat_ids,
false,
'integer') .
" ";
667 $query =
"SELECT cat_id FROM cal_categories " .
669 "AND obj_id = " . $this->db->quote($this->
user->getId(),
'integer') .
" " . $in;
672 $cat_ids[] = (
int) $row->cat_id;
677 if (!$cat_ids = array_merge($cat_ids, $accepted_ids)) {
680 if (is_array($only_cat_ids)) {
681 $cat_ids = array_filter($cat_ids,
function (
$id) use ($only_cat_ids) {
682 return in_array(
$id, $only_cat_ids);
686 $query =
"SELECT * FROM cal_categories " .
688 "AND " . $this->db->in(
'cat_id', $cat_ids,
false,
'integer') .
" " .
691 $res = $this->db->query($query);
693 $this->categories[] = (
int) $row->cat_id;
694 $this->categories_info[(
int) $row->cat_id][
'obj_type'] =
'';
695 $this->categories_info[(
int) $row->cat_id][
'source_ref_id'] = 0;
696 $this->categories_info[(
int) $row->cat_id][
'obj_id'] = (
int) $row->obj_id;
697 $this->categories_info[(
int) $row->cat_id][
'cat_id'] = (
int) $row->cat_id;
698 $this->categories_info[(
int) $row->cat_id][
'title'] = $row->title;
699 $this->categories_info[(
int) $row->cat_id][
'color'] = $row->color;
700 $this->categories_info[(
int) $row->cat_id][
'type'] = (
int) $row->type;
702 if (in_array((
int) $row->cat_id, $accepted_ids)) {
704 if ($shared->isEditableForUser($this->user->getId())) {
705 $this->categories_info[(
int) $row->cat_id][
'editable'] =
true;
707 $this->categories_info[(
int) $row->cat_id][
'editable'] =
false;
710 $this->categories_info[(
int) $row->cat_id][
'editable'] =
true;
712 if ($this->
user->getId() == (
int) $row->obj_id) {
713 $this->categories_info[(
int) $row->cat_id][
'settings'] =
true;
715 $this->categories_info[(
int) $row->cat_id][
'settings'] =
false;
718 $this->categories_info[(
int) $row->cat_id][
'accepted'] = in_array((
int) $row->cat_id, $accepted_ids);
730 $users = array_unique(array_merge($participants->getTutors(), $participants->getAdmins()));
733 foreach ($users as $user) {
749 if ($a_target_ref_id) {
752 $query =
'SELECT DISTINCT(cc.cat_id) FROM booking_entry be ' .
753 'LEFT JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
754 'JOIN cal_entries ce ON be.booking_id = ce.context_id ' .
755 'JOIN cal_cat_assignments ca ON ce.cal_id = ca.cal_id ' .
756 'JOIN cal_categories cc ON ca.cat_id = cc.cat_id ' .
757 'WHERE ((bo.target_obj_id IS NULL) OR bo.target_obj_id = ' . $this->db->quote(
763 if ($a_cat_id == 0) {
764 $query .=
'AND cc.obj_id = ' . $this->db->quote($this->
getCHUserId(),
'integer');
768 $categories = array();
770 if ($a_cat_id == 0 || (
int) $row->cat_id == $a_cat_id) {
771 $categories[] = (
int) $row->cat_id;
776 $query =
'SELECT * FROM cal_categories ' .
777 'WHERE ' . $this->db->in(
'cat_id', $categories,
false,
'integer');
780 $this->categories[] = (
int) $row->cat_id;
781 $this->categories_info[(
int) $row->cat_id][
'obj_type'] =
'';
782 $this->categories_info[(
int) $row->cat_id][
'source_ref_id'] = 0;
783 $this->categories_info[(
int) $row->cat_id][
'obj_id'] = (
int) $row->obj_id;
784 $this->categories_info[(
int) $row->cat_id][
'cat_id'] = (
int) $row->cat_id;
786 $this->categories_info[(
int) $row->cat_id][
'color'] = $row->color;
787 $this->categories_info[(
int) $row->cat_id][
'type'] = (
int) $row->type;
788 $this->categories_info[(
int) $row->cat_id][
'editable'] =
false;
789 $this->categories_info[(
int) $row->cat_id][
'settings'] =
false;
790 $this->categories_info[(
int) $row->cat_id][
'accepted'] =
false;
791 $this->categories_info[(
int) $row->cat_id][
'remote'] =
false;
795 $filter = ($a_cat_id > 0)
796 ?
" AND cat_id = " . $this->db->quote($a_cat_id,
"integer")
797 :
" AND obj_id = " . $this->db->quote($this->
getCHUserId(),
'integer');
799 $query =
"SELECT * FROM cal_categories cc " .
803 $this->categories[] = (
int) $row->cat_id;
804 $this->categories_info[(
int) $row->cat_id][
'obj_type'] =
'';
805 $this->categories_info[(
int) $row->cat_id][
'source_ref_id'] = 0;
806 $this->categories_info[(
int) $row->cat_id][
'obj_id'] = (
int) $row->obj_id;
807 $this->categories_info[(
int) $row->cat_id][
'cat_id'] = (
int) $row->cat_id;
808 $this->categories_info[(
int) $row->cat_id][
'title'] = $row->title;
809 $this->categories_info[(
int) $row->cat_id][
'color'] = $row->color;
810 $this->categories_info[(
int) $row->cat_id][
'type'] = (
int) $row->type;
811 $this->categories_info[(
int) $row->cat_id][
'editable'] =
false;
812 $this->categories_info[(
int) $row->cat_id][
'settings'] =
false;
813 $this->categories_info[(
int) $row->cat_id][
'accepted'] =
false;
814 $this->categories_info[(
int) $row->cat_id][
'remote'] =
false;
828 $query =
"SELECT * FROM cal_categories " .
830 "AND obj_id = " . $this->db->quote($user_id,
'integer');
833 $this->categories[] = (
int) $row->cat_id;
834 $this->categories_info[(
int) $row->cat_id][
'source_ref_id'] = 0;
835 $this->categories_info[(
int) $row->cat_id][
'obj_type'] =
'';
836 $this->categories_info[(
int) $row->cat_id][
'obj_id'] = (
int) $row->obj_id;
837 $this->categories_info[(
int) $row->cat_id][
'cat_id'] = (
int) $row->cat_id;
838 $this->categories_info[(
int) $row->cat_id][
'title'] = $row->title;
839 $this->categories_info[(
int) $row->cat_id][
'color'] = $row->color;
840 $this->categories_info[(
int) $row->cat_id][
'type'] = (
int) $row->type;
841 $this->categories_info[(
int) $row->cat_id][
'editable'] =
false;
842 $this->categories_info[(
int) $row->cat_id][
'settings'] =
false;
843 $this->categories_info[(
int) $row->cat_id][
'accepted'] =
false;
844 $this->categories_info[(
int) $row->cat_id][
'remote'] =
false;
848 protected function readSelectedCategories(array $a_obj_ids,
int $a_source_ref_id = 0,
bool $check_permissions =
true): void
850 if (!count($a_obj_ids)) {
854 $query =
"SELECT * FROM cal_categories " .
856 "AND " . $this->db->in(
'obj_id', $a_obj_ids,
false,
'integer') .
" " .
863 if ($obj_type ==
'crs' or $obj_type ==
'grp') {
873 if ($this->
access->checkAccess(
'edit_event',
'', $ref_id)) {
876 if ($this->
access->checkAccess(
'edit_event',
'', $ref_id)) {
880 } elseif ($this->
access->checkAccess(
'read',
'', $ref_id)) {
884 if (!$exists && $check_permissions) {
887 $this->categories_info[(
int) $row->cat_id][
'editable'] = $editable;
888 $this->categories_info[(
int) $row->cat_id][
'accepted'] =
false;
889 $this->categories_info[(
int) $row->cat_id][
'settings'] =
$settings;
891 $this->categories[] = (
int) $row->cat_id;
893 $this->categories_info[(
int) $row->cat_id][
'obj_id'] = (
int) $row->obj_id;
894 $this->categories_info[(
int) $row->cat_id][
'cat_id'] = (
int) $row->cat_id;
895 $this->categories_info[(
int) $row->cat_id][
'color'] = $row->color;
897 $this->categories_info[(
int) $row->cat_id][
'title'] = $row->title;
898 $this->categories_info[(
int) $row->cat_id][
'type'] = (
int) $row->type;
899 $this->categories_info[(
int) $row->cat_id][
'remote'] =
false;
900 $this->categories_info[(
int) $row->cat_id][
'source_ref_id'] = $a_source_ref_id;
910 $course_ids = array();
911 foreach ($this->categories as $cat_id) {
912 if (isset($this->categories_info[$cat_id][
'obj_type']) &&
913 in_array($this->categories_info[$cat_id][
'obj_type'], [
'crs',
'grp',
'tals'])) {
914 $course_ids[] = $this->categories_info[$cat_id][
'obj_id'];
918 $query =
"SELECT od2.obj_id sess_id, od1.obj_id crs_id,cat_id, or2.ref_id sess_ref_id, od2.type FROM object_data od1 " .
919 "JOIN object_reference or1 ON od1.obj_id = or1.obj_id " .
920 "JOIN tree t ON or1.ref_id = t.parent " .
921 "JOIN object_reference or2 ON t.child = or2.ref_id " .
922 "JOIN object_data od2 ON or2.obj_id = od2.obj_id " .
923 "JOIN cal_categories cc ON od2.obj_id = cc.obj_id " .
924 "WHERE " . $this->db->in(
'od2.type', array(
'sess',
'exc',
'etal'),
false,
'text') .
925 "AND (od1.type = 'crs' OR od1.type = 'grp' OR od1.type = 'tals') " .
926 "AND " . $this->db->in(
'od1.obj_id', $course_ids,
false,
'integer') .
' ' .
927 "AND or2.deleted IS NULL";
931 $course_sessions = array();
933 if ($row->type !==
'etal') {
935 !$this->
access->checkAccessOfUser($this->user_id,
'read',
'', (
int) $row->sess_ref_id) ||
936 !$this->
access->checkAccessOfUser($this->user_id,
'visible',
'', (
int) $row->sess_ref_id)
941 $cat_ids[] = (
int) $row->cat_id;
942 $course_sessions[(
int) $row->crs_id][(
int) $row->sess_id] = (
int) $row->cat_id;
943 $this->subitem_categories[] = (
int) $row->cat_id;
946 foreach ($this->categories as $cat_id) {
948 (isset($this->categories_info[$cat_id][
'obj_type']) &&
949 in_array($this->categories_info[$cat_id][
'obj_type'], [
'crs',
'grp',
'tals'])) &&
950 isset($this->categories_info[$cat_id][
'obj_id']) &&
951 isset($course_sessions[$this->categories_info[$cat_id][
'obj_id']]) &&
952 is_array($course_sessions[$this->categories_info[$cat_id][
'obj_id']])) {
953 foreach ($course_sessions[$this->categories_info[$cat_id][
'obj_id']] as $sess_id => $sess_cat_id) {
954 $this->categories_info[$cat_id][
'subitem_ids'][$sess_id] = $sess_cat_id;
955 $this->categories_info[$cat_id][
'subitem_obj_ids'][$sess_cat_id] = $sess_id;
958 $this->categories_info[$cat_id][
'subitem_ids'] = array();
959 $this->categories_info[$cat_id][
'subitem_obj_ids'] = array();
970 $talks = $repository->findByOwnerAndEmployee();
972 return $item->
getId();
984 $ilDB = $DIC[
'ilDB'];
987 $set =
$ilDB->query(
"SELECT * FROM cal_categories " .
989 "AND obj_id = " .
$ilDB->quote($a_user_id,
'integer'));
992 while ($rec =
$ilDB->fetchAssoc($set)) {
993 $rec[
'cat_id'] = (
int) $rec[
'cat_id'];
994 $rec[
'obj_id'] = (
int) $rec[
'obj_id'];
995 $rec[
'type'] = (
int) $rec[
'type'];
996 $rec[
'loc_type'] = (
int) $rec[
'loc_type'];
class for calendar categories
static lookupPrivateCategories(int $a_user_id)
Lookup private categories of user.
getSubitemCategories(int $a_cat_id)
initialize(int $a_mode, int $a_source_ref_id=0, bool $a_use_cache=false, int $a_cat_id=0)
initialize visible categories
isEditable(int $a_cat_id)
check if category is editable
readSelectedItemCalendars()
setSourceRefId(int $a_val)
addSubitemCalendars()
Add subitem calendars E.g.
setCHUserId(int $a_user_id)
Set ch user id.
Exception being thrown calendar categories is initiliazed multiple times for the same user...
getCategoryInfo(int $a_cat_id)
__construct(int $a_usr_id=0)
Singleton instance.
static _lookupFullname(int $a_user_id)
const MODE_PERSONAL_DESKTOP_MEMBERSHIP
static getAcceptedCalendars(int $a_usr_id)
static _getAllReferences(int $id)
get all reference ids for object ID
readReposCalendars($a_container_only=false)
Read available repository calendars.
const CAL_SELECTION_MEMBERSHIP
ilFavouritesDBRepository $fav_rep
readBookingCalendar(?int $user_id=null)
Read booking manager calendar.
const MODE_REMOTE_SELECTED
sleep()
Serialize categories.
isVisible($a_cat_id)
check if category is visible
quote($value, string $type)
const MODE_REPOSITORY_CONTAINER_ONLY
Stores calendar categories.
const MODE_SINGLE_CALENDAR
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjId(int $ref_id)
static _lookupCategoryIdByObjId(int $a_obj_id)
lookup category by obj_id
static lookupRemoteCalendars()
getCategories(bool $a_include_subitem_calendars=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _isOwner(int $a_usr_id, int $a_cal_id)
check if user is owner of a category
array $subitem_categories
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTitle(int $obj_id)
static _getInstanceByObjId(int $a_obj_id)
readSelectedCategories(array $a_obj_ids, int $a_source_ref_id=0, bool $check_permissions=true)
readAllConsultationHoursCalendarOfContainer(int $a_container_ref_id)
Read personal consultation hours calendar of all tutors for a container.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
static deleteRepositoryCache(int $a_usr_id)
Delete cache.
query(string $query)
Run a (read-only) Query on the database.
const MODE_PORTFOLIO_CONSULTATION
prepareCategoriesOfUserForSelection()
static _getInstance($a_usr_id=0)
get singleton instance
readPrivateCalendars(?array $only_cat_ids=null)
Read private calendars.
readSingleCalendar(int $a_cat_id)
setTargetRefId(int $a_ref_id)
wakeup(string $a_ser)
Load from serialize string.
static ilCalendarCategories $instance
static lookupBookableUsersForObject(array $a_obj_id, array $a_user_ids)
Consultation hours are offered if 1) consultation hour owner is admin or tutor and no object assignme...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
lookupRelevantTalkSeriesIds()
getNotificationCalendars()
Get all calendars that allow send of notifications (Editable and course group calendars) ...
static _getMembershipByType(int $a_usr_id, array $a_type, bool $a_only_member_role=false)
get membership by type Get course or group membership
static _lookupType(int $id, bool $reference=false)
readPublicCalendars($cat_ids=null)
Read public calendars.
readSelectedCalendar(int $a_cal_id)
Read info about selected calendar.
readConsultationHoursCalendar(?int $a_target_ref_id=null, int $a_cat_id=0)
Read personal consultation hours calendar.
static deletePDItemsCache(int $a_usr_id)
Delete cache (add remove desktop item)
readPDCalendars()
Read categories of user.
const MODE_PERSONAL_DESKTOP_ITEMS