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:
329 if ($this->
getMode() != self::MODE_REPOSITORY &&
330 $this->
getMode() != self::MODE_CONSULTATION &&
331 $this->
getMode() != self::MODE_PORTFOLIO_CONSULTATION) {
334 $this->user_id .
':' . $a_mode .
':categories:' . $a_source_ref_id,
346 if (isset($this->categories_info[$a_cat_id])) {
347 return $this->categories_info[$a_cat_id];
350 if (in_array($a_cat_id, $this->subitem_categories)) {
351 foreach ($this->categories as $cat_id) {
352 if (in_array($a_cat_id, $this->categories_info[$cat_id][
'subitem_ids'])) {
353 return $this->categories_info[$cat_id];
362 return $this->categories_info ?: array();
365 public function getCategories(
bool $a_include_subitem_calendars =
false): array
367 if ($a_include_subitem_calendars) {
368 return array_merge($this->categories, $this->subitem_categories);
371 return $this->categories ?: array();
376 if (!isset($this->categories_info[$a_cat_id][
'subitem_ids'])) {
377 return array($a_cat_id);
379 return array_merge((array) $this->categories_info[$a_cat_id][
'subitem_ids'], array($a_cat_id));
384 $has_personal_calendar =
false;
386 foreach ($this->categories_info as $info) {
387 if ($info[
'obj_type'] ==
'sess' || $info[
'obj_type'] ==
'exc') {
396 $has_personal_calendar =
true;
399 if ($info[
'editable']) {
400 $cats[$info[
'cat_id']] = $info[
'title'];
404 if (!$has_personal_calendar) {
405 $cats[0] = $this->
lng->txt(
'cal_default_calendar');
417 foreach ($this->categories_info as $info) {
420 $not[] = (
int) $info[
'cat_id'];
432 return isset($this->categories_info[$a_cat_id][
'editable']) && $this->categories_info[$a_cat_id][
'editable'];
440 return in_array($a_cat_id, $this->categories) || in_array($a_cat_id, $this->subitem_categories);
474 $this->categories[] = $a_cal_id;
490 $exercises = array();
491 foreach ($this->fav_rep->getFavouritesOfUser(
492 $this->user->getId(),
493 array(
'crs',
'grp',
'sess',
'exc')
495 if ($this->
access->checkAccess(
'read',
'', $item[
'ref_id'])) {
496 switch ($item[
'type']) {
498 $courses[] = $item[
'obj_id'];
502 $sessions[] = $item[
'obj_id'];
506 $groups[] = $item[
'obj_id'];
510 $exercises[] = $item[
'obj_id'];
533 if (!$a_container_only) {
540 #$query = "SELECT ref_id,obd.obj_id obj_id FROM tree t1 ". 541 # "JOIN object_reference obr ON t1.child = obr.ref_id ". 542 # "JOIN object_data obd ON obd.obj_id = obr.obj_id ". 543 # "WHERE t1.lft >= (SELECT lft FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ". 544 # "AND t1.lft <= (SELECT rgt FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ". 545 # "AND ".$ilDB->in('type',array('crs','grp','sess'),false,'text')." ". 550 $subtree_query =
$GLOBALS[
'DIC'][
'tree']->getSubTreeQuery(
552 array(
'object_reference.ref_id',
'object_data.obj_id'),
553 array(
'crs',
'grp',
'sess',
'exc')
556 $res = $this->db->query($subtree_query);
559 if ($this->tree->isDeleted((
int) $row->ref_id)) {
564 if ($obj_type ==
'crs' or $obj_type ==
'grp') {
573 if ($this->
access->checkAccess(
'read',
'', (
int) $row->ref_id)) {
574 $obj_ids[] = (
int) $row->obj_id;
582 if (!$a_container_only) {
598 switch ($cat->getType()) {
627 if (is_array($cat_ids)) {
628 $in =
" AND " . $this->db->in(
'cat_id', $cat_ids,
false,
'integer') .
" ";
632 $query =
"SELECT * FROM cal_categories " .
636 $res = $this->db->query($query);
638 $this->categories[] = (
int) $row->cat_id;
639 $this->categories_info[(
int) $row->cat_id][
'obj_type'] =
'';
640 $this->categories_info[(
int) $row->cat_id][
'source_ref_id'] = 0;
641 $this->categories_info[(
int) $row->cat_id][
'obj_id'] = (
int) $row->obj_id;
642 $this->categories_info[(
int) $row->cat_id][
'cat_id'] = (
int) $row->cat_id;
643 $this->categories_info[(
int) $row->cat_id][
'title'] = $row->title;
644 $this->categories_info[(
int) $row->cat_id][
'color'] = $row->color;
645 $this->categories_info[(
int) $row->cat_id][
'type'] = (
int) $row->type;
646 $this->categories_info[(
int) $row->cat_id][
'editable'] = $this->rbacsystem->checkAccess(
650 $this->categories_info[(
int) $row->cat_id][
'settings'] = $this->rbacsystem->checkAccess(
654 $this->categories_info[(
int) $row->cat_id][
'accepted'] =
false;
666 if (is_array($only_cat_ids)) {
667 $in =
" AND " . $this->db->in(
'cat_id', $only_cat_ids,
false,
'integer') .
" ";
671 $query =
"SELECT cat_id FROM cal_categories " .
673 "AND obj_id = " . $this->db->quote($this->
user->getId(),
'integer') .
" " . $in;
674 $res = $this->db->query($query);
676 $cat_ids[] = (
int) $row->cat_id;
681 if (!$cat_ids = array_merge($cat_ids, $accepted_ids)) {
684 if (is_array($only_cat_ids)) {
685 $cat_ids = array_filter($cat_ids,
function (
$id) use ($only_cat_ids) {
686 return in_array(
$id, $only_cat_ids);
690 $query =
"SELECT * FROM cal_categories " .
692 "AND " . $this->db->in(
'cat_id', $cat_ids,
false,
'integer') .
" " .
695 $res = $this->db->query($query);
697 $this->categories[] = (
int) $row->cat_id;
698 $this->categories_info[(
int) $row->cat_id][
'obj_type'] =
'';
699 $this->categories_info[(
int) $row->cat_id][
'source_ref_id'] = 0;
700 $this->categories_info[(
int) $row->cat_id][
'obj_id'] = (
int) $row->obj_id;
701 $this->categories_info[(
int) $row->cat_id][
'cat_id'] = (
int) $row->cat_id;
702 $this->categories_info[(
int) $row->cat_id][
'title'] = $row->title;
703 $this->categories_info[(
int) $row->cat_id][
'color'] = $row->color;
704 $this->categories_info[(
int) $row->cat_id][
'type'] = (
int) $row->type;
706 if (in_array((
int) $row->cat_id, $accepted_ids)) {
708 if ($shared->isEditableForUser($this->user->getId())) {
709 $this->categories_info[(
int) $row->cat_id][
'editable'] =
true;
711 $this->categories_info[(
int) $row->cat_id][
'editable'] =
false;
714 $this->categories_info[(
int) $row->cat_id][
'editable'] =
true;
716 if ($this->
user->getId() == (
int) $row->obj_id) {
717 $this->categories_info[(
int) $row->cat_id][
'settings'] =
true;
719 $this->categories_info[(
int) $row->cat_id][
'settings'] =
false;
722 $this->categories_info[(
int) $row->cat_id][
'accepted'] = in_array((
int) $row->cat_id, $accepted_ids);
734 $users = array_unique(array_merge($participants->getTutors(), $participants->getAdmins()));
737 foreach ($users as $user) {
753 if ($a_target_ref_id) {
756 $query =
'SELECT DISTINCT(cc.cat_id) FROM booking_entry be ' .
757 'LEFT JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
758 'JOIN cal_entries ce ON be.booking_id = ce.context_id ' .
759 'JOIN cal_cat_assignments ca ON ce.cal_id = ca.cal_id ' .
760 'JOIN cal_categories cc ON ca.cat_id = cc.cat_id ' .
761 'WHERE ((bo.target_obj_id IS NULL) OR bo.target_obj_id = ' . $this->db->quote(
767 if ($a_cat_id == 0) {
768 $query .=
'AND cc.obj_id = ' . $this->db->quote($this->
getCHUserId(),
'integer');
771 $res = $this->db->query($query);
772 $categories = array();
774 if ($a_cat_id == 0 || (
int) $row->cat_id == $a_cat_id) {
775 $categories[] = (
int) $row->cat_id;
780 $query =
'SELECT * FROM cal_categories ' .
781 'WHERE ' . $this->db->in(
'cat_id', $categories,
false,
'integer');
782 $res = $this->db->query($query);
784 $this->categories[] = (
int) $row->cat_id;
785 $this->categories_info[(
int) $row->cat_id][
'obj_type'] =
'';
786 $this->categories_info[(
int) $row->cat_id][
'source_ref_id'] = 0;
787 $this->categories_info[(
int) $row->cat_id][
'obj_id'] = (
int) $row->obj_id;
788 $this->categories_info[(
int) $row->cat_id][
'cat_id'] = (
int) $row->cat_id;
790 $this->categories_info[(
int) $row->cat_id][
'color'] = $row->color;
791 $this->categories_info[(
int) $row->cat_id][
'type'] = (
int) $row->type;
792 $this->categories_info[(
int) $row->cat_id][
'editable'] =
false;
793 $this->categories_info[(
int) $row->cat_id][
'settings'] =
false;
794 $this->categories_info[(
int) $row->cat_id][
'accepted'] =
false;
795 $this->categories_info[(
int) $row->cat_id][
'remote'] =
false;
799 $filter = ($a_cat_id > 0)
800 ?
" AND cat_id = " . $this->db->quote($a_cat_id,
"integer")
801 :
" AND obj_id = " . $this->db->quote($this->
getCHUserId(),
'integer');
803 $query =
"SELECT * FROM cal_categories cc " .
805 $res = $this->db->query($query);
807 $this->categories[] = (
int) $row->cat_id;
808 $this->categories_info[(
int) $row->cat_id][
'obj_type'] =
'';
809 $this->categories_info[(
int) $row->cat_id][
'source_ref_id'] = 0;
810 $this->categories_info[(
int) $row->cat_id][
'obj_id'] = (
int) $row->obj_id;
811 $this->categories_info[(
int) $row->cat_id][
'cat_id'] = (
int) $row->cat_id;
812 $this->categories_info[(
int) $row->cat_id][
'title'] = $row->title;
813 $this->categories_info[(
int) $row->cat_id][
'color'] = $row->color;
814 $this->categories_info[(
int) $row->cat_id][
'type'] = (
int) $row->type;
815 $this->categories_info[(
int) $row->cat_id][
'editable'] =
false;
816 $this->categories_info[(
int) $row->cat_id][
'settings'] =
false;
817 $this->categories_info[(
int) $row->cat_id][
'accepted'] =
false;
818 $this->categories_info[(
int) $row->cat_id][
'remote'] =
false;
832 $query =
"SELECT * FROM cal_categories " .
834 "AND obj_id = " . $this->db->quote($user_id,
'integer');
835 $res = $this->db->query($query);
837 $this->categories[] = (
int) $row->cat_id;
838 $this->categories_info[(
int) $row->cat_id][
'source_ref_id'] = 0;
839 $this->categories_info[(
int) $row->cat_id][
'obj_type'] =
'';
840 $this->categories_info[(
int) $row->cat_id][
'obj_id'] = (
int) $row->obj_id;
841 $this->categories_info[(
int) $row->cat_id][
'cat_id'] = (
int) $row->cat_id;
842 $this->categories_info[(
int) $row->cat_id][
'title'] = $row->title;
843 $this->categories_info[(
int) $row->cat_id][
'color'] = $row->color;
844 $this->categories_info[(
int) $row->cat_id][
'type'] = (
int) $row->type;
845 $this->categories_info[(
int) $row->cat_id][
'editable'] =
false;
846 $this->categories_info[(
int) $row->cat_id][
'settings'] =
false;
847 $this->categories_info[(
int) $row->cat_id][
'accepted'] =
false;
848 $this->categories_info[(
int) $row->cat_id][
'remote'] =
false;
852 protected function readSelectedCategories(array $a_obj_ids,
int $a_source_ref_id = 0,
bool $check_permissions =
true): void
854 if (!count($a_obj_ids)) {
858 $query =
"SELECT * FROM cal_categories " .
860 "AND " . $this->db->in(
'obj_id', $a_obj_ids,
false,
'integer') .
" " .
863 $res = $this->db->query($query);
867 if ($obj_type ==
'crs' or $obj_type ==
'grp') {
877 if ($this->
access->checkAccess(
'edit_event',
'', $ref_id)) {
880 if ($this->
access->checkAccess(
'edit_event',
'', $ref_id)) {
884 } elseif ($this->
access->checkAccess(
'read',
'', $ref_id)) {
888 if (!$exists && $check_permissions) {
891 $this->categories_info[(
int) $row->cat_id][
'editable'] = $editable;
892 $this->categories_info[(
int) $row->cat_id][
'accepted'] =
false;
893 $this->categories_info[(
int) $row->cat_id][
'settings'] =
$settings;
895 $this->categories[] = (
int) $row->cat_id;
897 $this->categories_info[(
int) $row->cat_id][
'obj_id'] = (
int) $row->obj_id;
898 $this->categories_info[(
int) $row->cat_id][
'cat_id'] = (
int) $row->cat_id;
899 $this->categories_info[(
int) $row->cat_id][
'color'] = $row->color;
901 $this->categories_info[(
int) $row->cat_id][
'title'] = $row->title;
902 $this->categories_info[(
int) $row->cat_id][
'type'] = (
int) $row->type;
903 $this->categories_info[(
int) $row->cat_id][
'remote'] =
false;
904 $this->categories_info[(
int) $row->cat_id][
'source_ref_id'] = $a_source_ref_id;
914 $course_ids = array();
915 foreach ($this->categories as $cat_id) {
916 if (isset($this->categories_info[$cat_id][
'obj_type']) &&
917 in_array($this->categories_info[$cat_id][
'obj_type'], [
'crs',
'grp',
'tals'])) {
918 $course_ids[] = $this->categories_info[$cat_id][
'obj_id'];
922 $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 " .
923 "JOIN object_reference or1 ON od1.obj_id = or1.obj_id " .
924 "JOIN tree t ON or1.ref_id = t.parent " .
925 "JOIN object_reference or2 ON t.child = or2.ref_id " .
926 "JOIN object_data od2 ON or2.obj_id = od2.obj_id " .
927 "JOIN cal_categories cc ON od2.obj_id = cc.obj_id " .
928 "WHERE " . $this->db->in(
'od2.type', array(
'sess',
'exc',
'etal'),
false,
'text') .
929 "AND (od1.type = 'crs' OR od1.type = 'grp' OR od1.type = 'tals') " .
930 "AND " . $this->db->in(
'od1.obj_id', $course_ids,
false,
'integer') .
' ' .
931 "AND or2.deleted IS NULL";
933 $res = $this->db->query($query);
935 $course_sessions = array();
937 if ($row->type !==
'etal') {
939 !$this->
access->checkAccessOfUser($this->user_id,
'read',
'', (
int) $row->sess_ref_id) ||
940 !$this->
access->checkAccessOfUser($this->user_id,
'visible',
'', (
int) $row->sess_ref_id)
945 $cat_ids[] = (
int) $row->cat_id;
946 $course_sessions[(
int) $row->crs_id][(
int) $row->sess_id] = (
int) $row->cat_id;
947 $this->subitem_categories[] = (
int) $row->cat_id;
950 foreach ($this->categories as $cat_id) {
952 (isset($this->categories_info[$cat_id][
'obj_type']) &&
953 in_array($this->categories_info[$cat_id][
'obj_type'], [
'crs',
'grp',
'tals'])) &&
954 isset($this->categories_info[$cat_id][
'obj_id']) &&
955 isset($course_sessions[$this->categories_info[$cat_id][
'obj_id']]) &&
956 is_array($course_sessions[$this->categories_info[$cat_id][
'obj_id']])) {
957 foreach ($course_sessions[$this->categories_info[$cat_id][
'obj_id']] as $sess_id => $sess_cat_id) {
958 $this->categories_info[$cat_id][
'subitem_ids'][$sess_id] = $sess_cat_id;
959 $this->categories_info[$cat_id][
'subitem_obj_ids'][$sess_cat_id] = $sess_id;
962 $this->categories_info[$cat_id][
'subitem_ids'] = array();
963 $this->categories_info[$cat_id][
'subitem_obj_ids'] = array();
974 $talks = $repository->findByOwnerAndEmployee();
976 return $item->
getId();
988 $ilDB = $DIC[
'ilDB'];
991 $set =
$ilDB->query(
"SELECT * FROM cal_categories " .
993 "AND obj_id = " .
$ilDB->quote($a_user_id,
'integer'));
996 while ($rec =
$ilDB->fetchAssoc($set)) {
997 $rec[
'cat_id'] = (
int) $rec[
'cat_id'];
998 $rec[
'obj_id'] = (
int) $rec[
'obj_id'];
999 $rec[
'type'] = (
int) $rec[
'type'];
1000 $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)
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'))
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.
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