ILIAS  release_8 Revision v8.24
ilCalendarAppEventListener Class Reference

Handles events (create,update,delete) for autmatic generated calendar events from course, groups, ... More...

+ Inheritance diagram for ilCalendarAppEventListener:
+ Collaboration diagram for ilCalendarAppEventListener:

Static Public Member Functions

static handleEvent (string $a_component, string $a_event, array $a_parameter)
 Handle events like create, update, delete @access public. More...
 
static createCategory (ilObject $a_obj, bool $a_check_existing=false)
 Create a category for a new object (crs,grp, ...) More...
 
static updateCategory (ilObject $a_obj)
 Update category for a object (crs,grp, ...) More...
 
static createAppointments (ilObject $a_obj, array $a_appointments)
 Create appointments. More...
 
static deleteAppointments (int $a_obj_id, ?array $a_context_ids=null)
 Delete automatic generated appointments. More...
 
static deleteCategory (int $a_obj_id)
 delete category More...
 
static handleEvent (string $a_component, string $a_event, array $a_parameter)
 Handle an event in a listener. More...
 

Detailed Description

Handles events (create,update,delete) for autmatic generated calendar events from course, groups, ...

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 33 of file class.ilCalendarAppEventListener.php.

Member Function Documentation

◆ createAppointments()

static ilCalendarAppEventListener::createAppointments ( ilObject  $a_obj,
array  $a_appointments 
)
static

Create appointments.

Parameters
ilObject
ilCalendarAppointmentTemplate[]
Returns
void

Definition at line 168 of file class.ilCalendarAppEventListener.php.

168 : void
169 {
170 global $DIC;
171
172 $logger = $DIC->logger()->cal();
173
174 if (!$cat_id = ilCalendarCategories::_lookupCategoryIdByObjId($a_obj->getId())) {
175 $logger->warning('Cannot find calendar category for obj_id ' . $a_obj->getId());
176 $cat_id = self::createCategory($a_obj);
177 }
178
179 foreach ($a_appointments as $app_templ) {
180 $app = new ilCalendarEntry();
181 $app->setContextId($app_templ->getContextId());
182 $app->setContextInfo($app_templ->getContextInfo());
183 $app->setTitle($app_templ->getTitle());
184 $app->setSubtitle($app_templ->getSubtitle());
185 $app->setDescription($app_templ->getDescription());
186 $app->setFurtherInformations($app_templ->getInformation());
187 $app->setLocation($app_templ->getLocation());
188 $app->setStart($app_templ->getStart());
189 $app->setEnd($app_templ->getEnd());
190 $app->setFullday($app_templ->isFullday());
191 $app->setAutoGenerated(true);
192 $app->setTranslationType($app_templ->getTranslationType());
193 $app->save();
194
195 $ass = new ilCalendarCategoryAssignments($app->getEntryId());
196 $ass->addAssignment($cat_id);
197 }
198 }
static createCategory(ilObject $a_obj, bool $a_check_existing=false)
Create a category for a new object (crs,grp, ...)
static _lookupCategoryIdByObjId(int $a_obj_id)
lookup category by obj_id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$app
Definition: cli.php:39
global $DIC
Definition: feed.php:28

References $app, $DIC, ilCalendarCategories\_lookupCategoryIdByObjId(), createCategory(), and ilObject\getId().

Referenced by handleEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createCategory()

static ilCalendarAppEventListener::createCategory ( ilObject  $a_obj,
bool  $a_check_existing = false 
)
static

Create a category for a new object (crs,grp, ...)

Definition at line 130 of file class.ilCalendarAppEventListener.php.

130 : int
131 {
132 global $DIC;
133
134 $lng = $DIC->language();
135
136 // already existing? do update instead
137 if ($a_check_existing &&
139 return self::updateCategory($a_obj);
140 }
141 $cat = new ilCalendarCategory();
142 $cat->setTitle($a_obj->getTitle() ? $a_obj->getTitle() : $lng->txt('obj_' . $a_obj->getType()));
143 $cat->setType(ilCalendarCategory::TYPE_OBJ);
145 $cat->setObjId($a_obj->getId());
146 return $cat->add();
147 }
static updateCategory(ilObject $a_obj)
Update category for a object (crs,grp, ...)
Stores calendar categories.
static _getInstanceByObjId(int $a_obj_id)
get instance by obj_id
$lng

References $DIC, $lng, ilCalendarCategory\_getInstanceByObjId(), ilCalendarAppointmentColors\_getRandomColorByType(), ilObject\getId(), ilObject\getTitle(), ilObject\getType(), ilCalendarCategory\TYPE_OBJ, and updateCategory().

Referenced by createAppointments(), and handleEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteAppointments()

static ilCalendarAppEventListener::deleteAppointments ( int  $a_obj_id,
?array  $a_context_ids = null 
)
static

Delete automatic generated appointments.

Definition at line 203 of file class.ilCalendarAppEventListener.php.

204 {
206 // delete only selected entries
207 if (is_array($a_context_ids)) {
208 $entry = new ilCalendarEntry($app_id);
209 if (!in_array($entry->getContextId(), $a_context_ids)) {
210 continue;
211 }
212 }
215 }
216 }
static _getAutoGeneratedAppointmentsByObjId(int $a_obj_id)
get automatic generated appointments of category
static _deleteByAppointmentId(int $a_app_id)
Delete appointment assignment.
static _delete(int $a_entry_id)

References ilCalendarEntry\_delete(), ilCalendarCategoryAssignments\_deleteByAppointmentId(), and ilCalendarCategoryAssignments\_getAutoGeneratedAppointmentsByObjId().

Referenced by handleEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteCategory()

static ilCalendarAppEventListener::deleteCategory ( int  $a_obj_id)
static

delete category

Definition at line 221 of file class.ilCalendarAppEventListener.php.

221 : void
222 {
223 global $DIC;
224
225 $logger = $DIC->logger()->cal();
226
227 if (!$cat_id = ilCalendarCategories::_lookupCategoryIdByObjId($a_obj_id)) {
228 $logger->warning('Cannot find calendar category for obj_id ' . $a_obj_id);
229 return;
230 }
231
232 $category = new ilCalendarCategory($cat_id);
233 $category->delete();
234 }

References $DIC, and ilCalendarCategories\_lookupCategoryIdByObjId().

Referenced by handleEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleEvent()

static ilCalendarAppEventListener::handleEvent ( string  $a_component,
string  $a_event,
array  $a_parameter 
)
static

Handle events like create, update, delete @access public.

Parameters
string$a_componentcomponent, e.g. "Modules/Forum" or "Services/User"
string$a_eventevent e.g. "createUser", "updateUser", "deleteUser", ...
array$a_parameterparameter array (assoc), array("name" => ..., "phone_office" => ...) *

Implements ilAppEventListener.

Definition at line 43 of file class.ilCalendarAppEventListener.php.

43 : void
44 {
45 global $DIC;
46
47 $logger = $DIC->logger()->cal();
48 $ilUser = $DIC->user();
49
50 $delete_cache = false;
51 switch ($a_component) {
52 case 'Modules/Session':
53 case 'Modules/Group':
54 case 'Modules/Course':
55 case 'Modules/EmployeeTalk':
56 switch ($a_event) {
57 case 'create':
58 $logger->debug('Handling create event');
59 self::createCategory($a_parameter['object']);
60 self::createAppointments($a_parameter['object'], $a_parameter['appointments']);
61 $delete_cache = true;
62 break;
63
64 case 'update':
65 $logger->debug('Handling update event');
66 self::updateCategory($a_parameter['object']);
67 self::deleteAppointments($a_parameter['obj_id']);
68 self::createAppointments($a_parameter['object'], $a_parameter['appointments']);
69 $delete_cache = true;
70 break;
71
72 case 'delete':
73 $logger->debug('Handling delete event');
74 self::deleteCategory($a_parameter['obj_id']);
75 $delete_cache = true;
76 break;
77 }
78 break;
79
80 case 'Services/Booking':
81 switch ($a_event) {
82 case 'create':
83 case 'delete':
84 case 'update':
85 break;
86 }
87 break;
88
89 case 'Modules/Exercise':
90 switch ($a_event) {
91 case 'createAssignment':
92 $logger->debug('Handling create event (exercise assignment)');
93 self::createCategory($a_parameter['object'], true); // exercise category could already exist
94 self::createAppointments($a_parameter['object'], $a_parameter['appointments']);
95 $delete_cache = true;
96 break;
97
98 case 'updateAssignment':
99 $logger->debug('Handling update event (exercise assignment)');
100 self::createCategory($a_parameter['object'], true); // different life-cycle than ilObject
101 self::deleteAppointments($a_parameter['obj_id'], $a_parameter['context_ids']);
102 self::createAppointments($a_parameter['object'], $a_parameter['appointments']);
103 $delete_cache = true;
104 break;
105
106 case 'deleteAssignment':
107 $logger->debug('Handling delete event (exercise assignment)');
108 self::deleteAppointments($a_parameter['obj_id'], $a_parameter['context_ids']);
109 $delete_cache = true;
110 break;
111
112 case 'delete':
113 $logger->debug(':Handling delete event');
114 self::deleteCategory($a_parameter['obj_id']);
115 $delete_cache = true;
116 break;
117 }
118 break;
119 }
120
121 if ($delete_cache) {
124 }
125 }
static deleteCategory(int $a_obj_id)
delete category
static createAppointments(ilObject $a_obj, array $a_appointments)
Create appointments.
static deleteAppointments(int $a_obj_id, ?array $a_context_ids=null)
Delete automatic generated appointments.
static deleteRepositoryCache(int $a_usr_id)
Delete cache.
static deletePDItemsCache(int $a_usr_id)
Delete cache (add remove desktop item)
$ilUser
Definition: imgupload.php:34

References $DIC, $ilUser, createAppointments(), createCategory(), deleteAppointments(), deleteCategory(), ilCalendarCategories\deletePDItemsCache(), ilCalendarCategories\deleteRepositoryCache(), and updateCategory().

+ Here is the call graph for this function:

◆ updateCategory()

static ilCalendarAppEventListener::updateCategory ( ilObject  $a_obj)
static

Update category for a object (crs,grp, ...)

Definition at line 152 of file class.ilCalendarAppEventListener.php.

152 : int
153 {
154 if ($cat = ilCalendarCategory::_getInstanceByObjId($a_obj->getId())) {
155 $cat->setTitle($a_obj->getTitle());
156 $cat->update();
157 return $cat->getCategoryID();
158 }
159 return 0;
160 }

References ilCalendarCategory\_getInstanceByObjId(), ilObject\getId(), and ilObject\getTitle().

Referenced by createCategory(), and handleEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: