ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 ($a_component, $a_event, $a_parameter)
 Handle events like create, update, delete. More...
 
static createCategory ($a_obj, $a_check_existing=false)
 Create a category for a new object (crs,grp, ...) More...
 
static updateCategory ($a_obj)
 Create a category for a new object (crs,grp, ...) More...
 
static createAppointments ($a_obj, $a_appointments)
 Create appointments. More...
 
static deleteAppointments ($a_obj_id, array $a_context_ids=null)
 Delete automatic generated appointments. More...
 
static deleteCategory ($a_obj_id)
 delete category 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
Version
$Id$

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

Member Function Documentation

◆ createAppointments()

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

Create appointments.

public

Parameters

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

References $DIC, ilCalendarCategories\_lookupCategoryIdByObjId(), and ilCalendarCategoryAssignments\addAssignment().

191  {
192  global $DIC;
193 
194  $logger = $DIC->logger()->cal();
195 
196  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
197  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
198  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
199 
200  if (!$cat_id = ilCalendarCategories::_lookupCategoryIdByObjId($a_obj->getId())) {
201  $logger->warning('Cannot find calendar category for obj_id ' . $a_obj->getId());
202  $cat_id = self::createCategory($a_obj);
203  }
204 
205  foreach ($a_appointments as $app_templ) {
206  $app = new ilCalendarEntry();
207  $app->setContextId($app_templ->getContextId());
208  $app->setContextInfo($app_templ->getContextInfo());
209  $app->setTitle($app_templ->getTitle());
210  $app->setSubtitle($app_templ->getSubtitle());
211  $app->setDescription($app_templ->getDescription());
212  $app->setFurtherInformations($app_templ->getInformation());
213  $app->setLocation($app_templ->getLocation());
214  $app->setStart($app_templ->getStart());
215  $app->setEnd($app_templ->getEnd());
216  $app->setFullday($app_templ->isFullday());
217  $app->setAutoGenerated(true);
218  $app->setTranslationType($app_templ->getTranslationType());
219  $app->save();
220 
221  $ass = new ilCalendarCategoryAssignments($app->getEntryId());
222  $ass->addAssignment($cat_id);
223  }
224  }
Model for a calendar entry.
global $DIC
Definition: saml.php:7
static _lookupCategoryIdByObjId($a_obj_id)
lookup category by obj_id
+ Here is the call graph for this function:

◆ createCategory()

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

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

public

Parameters
objectilias object ('crs','grp',...)

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

References $DIC, $lng, ilCalendarCategory\_getInstanceByObjId(), ilCalendarAppointmentColors\_getRandomColorByType(), and ilCalendarCategory\TYPE_OBJ.

141  {
142  global $DIC;
143 
144  $lng = $DIC['lng'];
145 
146  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
147  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentColors.php');
148 
149  // already existing? do update instead
150  if ($a_check_existing &&
151  ilCalendarCategory::_getInstanceByObjId($a_obj->getId())) {
152  return self::updateCategory($a_obj);
153  }
154 
155  $cat = new ilCalendarCategory();
156  $cat->setTitle($a_obj->getTitle() ? $a_obj->getTitle() : $lng->txt('obj_' . $a_obj->getType()));
157  $cat->setType(ilCalendarCategory::TYPE_OBJ);
158  $cat->setColor(ilCalendarAppointmentColors::_getRandomColorByType($a_obj->getType()));
159  $cat->setObjId($a_obj->getId());
160  return $cat->add();
161  }
global $DIC
Definition: saml.php:7
Stores calendar categories.
$lng
static _getInstanceByObjId($a_obj_id)
get instance by obj_id
static _getRandomColorByType($a_type)
get random color entry for type
+ Here is the call graph for this function:

◆ deleteAppointments()

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

Delete automatic generated appointments.

public

Parameters
intobj_id
arraycontext ids

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

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

235  {
236  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
237  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
238 
240  // delete only selected entries
241  if (is_array($a_context_ids)) {
242  $entry = new ilCalendarEntry($app_id);
243  if (!in_array($entry->getContextId(), $a_context_ids)) {
244  continue;
245  }
246  }
247 
249  ilCalendarEntry::_delete($app_id);
250  }
251  }
Model for a calendar entry.
static _delete($a_entry_id)
delete entry
static _getAutoGeneratedAppointmentsByObjId($a_obj_id)
get automatic generated appointments of category
static _deleteByAppointmentId($a_app_id)
Delete appointment assignment.
+ Here is the call graph for this function:

◆ deleteCategory()

static ilCalendarAppEventListener::deleteCategory (   $a_obj_id)
static

delete category

public

Parameters

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

References $DIC, and ilCalendarCategories\_lookupCategoryIdByObjId().

262  {
263  global $DIC;
264 
265  $logger = $DIC->logger()->cal();
266 
267  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
268 
269  if (!$cat_id = ilCalendarCategories::_lookupCategoryIdByObjId($a_obj_id)) {
270  $logger->warning('Cannot find calendar category for obj_id ' . $a_obj_id);
271  return false;
272  }
273 
274  $category = new ilCalendarCategory($cat_id);
275  $category->delete();
276  }
global $DIC
Definition: saml.php:7
static _lookupCategoryIdByObjId($a_obj_id)
lookup category by obj_id
Stores calendar categories.
+ Here is the call graph for this function:

◆ handleEvent()

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

Handle events like create, update, delete.

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 46 of file class.ilCalendarAppEventListener.php.

References $DIC, $ilUser, ilCalendarCategories\deletePDItemsCache(), and ilCalendarCategories\deleteRepositoryCache().

47  {
48  global $DIC;
49 
50  $logger = $DIC->logger()->cal();
51  $ilUser = $DIC['ilUser'];
52 
53  $delete_cache = false;
54 
55  switch ($a_component) {
56  case 'Modules/Session':
57  case 'Modules/Group':
58  case 'Modules/Course':
59  switch ($a_event) {
60  case 'create':
61  $logger->debug('Handling create event');
62  self::createCategory($a_parameter['object']);
63  self::createAppointments($a_parameter['object'], $a_parameter['appointments']);
64  $delete_cache = true;
65  break;
66 
67  case 'update':
68  $logger->debug('Handling update event');
69  self::updateCategory($a_parameter['object']);
70  self::deleteAppointments($a_parameter['obj_id']);
71  self::createAppointments($a_parameter['object'], $a_parameter['appointments']);
72  $delete_cache = true;
73  break;
74 
75  case 'delete':
76  $logger->debug('Handling delete event');
77  self::deleteCategory($a_parameter['obj_id']);
78  $delete_cache = true;
79  break;
80  }
81  break;
82 
83  case 'Services/Booking':
84  switch ($a_event) {
85  case 'create':
86  break;
87  case 'update':
88  break;
89  case 'delete':
90  break;
91  }
92  break;
93 
94  case 'Modules/Exercise':
95  switch ($a_event) {
96  case 'createAssignment':
97  $logger->debug('Handling create event (exercise assignment)');
98  self::createCategory($a_parameter['object'], true); // exercise category could already exist
99  self::createAppointments($a_parameter['object'], $a_parameter['appointments']);
100  $delete_cache = true;
101  break;
102 
103  case 'updateAssignment':
104  $logger->debug('Handling update event (exercise assignment)');
105  self::createCategory($a_parameter['object'], true); // different life-cycle than ilObject
106  self::deleteAppointments($a_parameter['obj_id'], $a_parameter['context_ids']);
107  self::createAppointments($a_parameter['object'], $a_parameter['appointments']);
108  $delete_cache = true;
109  break;
110 
111  case 'deleteAssignment':
112  $logger->debug('Handling delete event (exercise assignment)');
113  self::deleteAppointments($a_parameter['obj_id'], $a_parameter['context_ids']);
114  $delete_cache = true;
115  break;
116 
117  case 'delete':
118  $logger->debug(':Handling delete event');
119  self::deleteCategory($a_parameter['obj_id']);
120  $delete_cache = true;
121  break;
122  }
123  break;
124  }
125 
126  if ($delete_cache) {
127  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
130  }
131  }
global $DIC
Definition: saml.php:7
static deletePDItemsCache($a_usr_id)
Delete cache (add remove desktop item)
static deleteRepositoryCache($a_usr_id)
Delete cache.
$ilUser
Definition: imgupload.php:18
+ Here is the call graph for this function:

◆ updateCategory()

static ilCalendarAppEventListener::updateCategory (   $a_obj)
static

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

public

Parameters
objectilias object ('crs','grp',...)

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

References ilCalendarCategory\_getInstanceByObjId().

171  {
172  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
173  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentColors.php');
174 
175  if ($cat = ilCalendarCategory::_getInstanceByObjId($a_obj->getId())) {
176  $cat->setTitle($a_obj->getTitle());
177  $cat->update();
178  }
179  return true;
180  }
static _getInstanceByObjId($a_obj_id)
get instance by obj_id
+ Here is the call graph for this function:

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