ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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 192 of file class.ilCalendarAppEventListener.php.

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

193  {
194  global $ilLog;
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  {
202  $ilLog->write(__METHOD__.': Cannot find calendar category for obj_id '.$a_obj->getId());
203  $cat_id = self::createCategory($a_obj);
204  }
205 
206  foreach($a_appointments as $app_templ)
207  {
208  $app = new ilCalendarEntry();
209  $app->setContextId($app_templ->getContextId());
210  $app->setTitle($app_templ->getTitle());
211  $app->setSubtitle($app_templ->getSubtitle());
212  $app->setDescription($app_templ->getDescription());
213  $app->setFurtherInformations($app_templ->getInformation());
214  $app->setLocation($app_templ->getLocation());
215  $app->setStart($app_templ->getStart());
216  $app->setEnd($app_templ->getEnd());
217  $app->setFullday($app_templ->isFullday());
218  $app->setAutoGenerated(true);
219  $app->setTranslationType($app_templ->getTranslationType());
220  $app->save();
221 
222  $ass = new ilCalendarCategoryAssignments($app->getEntryId());
223  $ass->addAssignment($cat_id);
224  }
225  }
Model for a calendar entry.
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 142 of file class.ilCalendarAppEventListener.php.

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

143  {
144  global $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 &&
152  {
153  return self::updateCategory($a_obj);
154  }
155 
156  $cat = new ilCalendarCategory();
157  $cat->setTitle($a_obj->getTitle() ? $a_obj->getTitle() : $lng->txt('obj_'.$a_obj->getType()));
158  $cat->setType(ilCalendarCategory::TYPE_OBJ);
159  $cat->setColor(ilCalendarAppointmentColors::_getRandomColorByType($a_obj->getType()));
160  $cat->setObjId($a_obj->getId());
161  return $cat->add();
162  }
Stores calendar categories.
static _getInstanceByObjId($a_obj_id)
get instance by obj_id
global $lng
Definition: privfeed.php:40
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 235 of file class.ilCalendarAppEventListener.php.

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

236  {
237  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
238  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
239 
241  {
242  // delete only selected entries
243  if(is_array($a_context_ids))
244  {
245  $entry = new ilCalendarEntry($app_id);
246  if(!in_array($entry->getContextId(), $a_context_ids))
247  {
248  continue;
249  }
250  }
251 
253  ilCalendarEntry::_delete($app_id);
254  }
255  }
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 265 of file class.ilCalendarAppEventListener.php.

References $ilLog, and ilCalendarCategories\_lookupCategoryIdByObjId().

266  {
267  global $ilLog;
268 
269  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
270 
271  if(!$cat_id = ilCalendarCategories::_lookupCategoryIdByObjId($a_obj_id))
272  {
273  $ilLog->write(__METHOD__.': Cannot find calendar category for obj_id '.$a_obj_id);
274  return false;
275  }
276 
277  $category = new ilCalendarCategory($cat_id);
278  $category->delete();
279 
280  }
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 $ilLog, $ilUser, ilCalendarCategories\deletePDItemsCache(), and ilCalendarCategories\deleteRepositoryCache().

47  {
48  global $ilLog,$ilUser;
49 
50  $delete_cache = false;
51 
52  switch($a_component)
53  {
54  case 'Modules/Session':
55  case 'Modules/Group':
56  case 'Modules/Course':
57  switch($a_event)
58  {
59  case 'create':
60  $ilLog->write(__METHOD__.': Handling create event');
61  self::createCategory($a_parameter['object']);
62  self::createAppointments($a_parameter['object'],$a_parameter['appointments']);
63  $delete_cache = true;
64  break;
65 
66  case 'update':
67  $ilLog->write(__METHOD__.': Handling update event');
68  self::updateCategory($a_parameter['object']);
69  self::deleteAppointments($a_parameter['obj_id']);
70  self::createAppointments($a_parameter['object'],$a_parameter['appointments']);
71  $delete_cache = true;
72  break;
73 
74  case 'delete':
75  $ilLog->write(__METHOD__.': Handling delete event');
76  self::deleteCategory($a_parameter['obj_id']);
77  $delete_cache = true;
78  break;
79  }
80  break;
81 
82  case 'Services/Booking':
83  switch($a_event)
84  {
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  {
97  case 'createAssignment':
98  $ilLog->write(__METHOD__.': Handling create event (exercise assignment)');
99  self::createCategory($a_parameter['object'],true); // exercise category could already exist
100  self::createAppointments($a_parameter['object'],$a_parameter['appointments']);
101  $delete_cache = true;
102  break;
103 
104  case 'updateAssignment':
105  $ilLog->write(__METHOD__.': Handling update event (exercise assignment)');
106  self::createCategory($a_parameter['object'],true); // different life-cycle than ilObject
107  self::deleteAppointments($a_parameter['obj_id'],$a_parameter['context_ids']);
108  self::createAppointments($a_parameter['object'],$a_parameter['appointments']);
109  $delete_cache = true;
110  break;
111 
112  case 'deleteAssignment':
113  $ilLog->write(__METHOD__.': Handling delete event (exercise assignment)');
114  self::deleteAppointments($a_parameter['obj_id'],$a_parameter['context_ids']);
115  $delete_cache = true;
116  break;
117 
118  case 'delete':
119  $ilLog->write(__METHOD__.': Handling delete event');
120  self::deleteCategory($a_parameter['obj_id']);
121  $delete_cache = true;
122  break;
123  }
124  break;
125  }
126 
127  if($delete_cache)
128  {
129  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
132  }
133  }
static deletePDItemsCache($a_usr_id)
Delete cache (add remove desktop item)
static deleteRepositoryCache($a_usr_id)
Delete cache.
global $ilUser
Definition: imgupload.php:15
+ 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 171 of file class.ilCalendarAppEventListener.php.

References ilCalendarCategory\_getInstanceByObjId().

172  {
173  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
174  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentColors.php');
175 
176  if($cat = ilCalendarCategory::_getInstanceByObjId($a_obj->getId()))
177  {
178  $cat->setTitle($a_obj->getTitle());
179  $cat->update();
180  }
181  return true;
182  }
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: