ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCalendarDataSet.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
5 
13 {
17  public function getSupportedVersions(): array
18  {
19  return array("4.3.0");
20  }
21 
25  protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
26  {
27  return "http://www.ilias.de/xml/Services/Calendar/" . $a_entity;
28  }
29 
33  protected function getTypes(string $a_entity, string $a_version): array
34  {
35  // calendar
36  if ($a_entity == "calendar") {
37  switch ($a_version) {
38  case "4.3.0":
39  return array(
40  "CatId" => "integer",
41  "ObjId" => "text",
42  "Title" => "text",
43  "Color" => "text",
44  "Type" => "integer"
45  );
46  }
47  }
48 
49  // calendar entry
50  if ($a_entity == "cal_entry") {
51  switch ($a_version) {
52  case "4.3.0":
53  return array(
54  "Id" => "integer",
55  "Title" => "text",
56  "Subtitle" => "text",
57  "Description" => "text",
58  "Location" => "text",
59  "Fullday" => "integer",
60  "Starta" => "text",
61  "Enda" => "text",
62  "Informations" => "text",
63  "AutoGenerated" => "integer",
64  "ContextId" => "integer",
65  "TranslationType" => "integer",
66  "IsMilestone" => "integer",
67  "Completion" => "integer",
68  "Notification" => "integer"
69  );
70  }
71  }
72 
73  // calendar/entry assignment
74  if ($a_entity == "cal_assignment") {
75  switch ($a_version) {
76  case "4.3.0":
77  return array(
78  "CatId" => "integer",
79  "EntryId" => "integer"
80  );
81  }
82  }
83 
84  // recurrence rule
85  if ($a_entity == "recurrence_rule") {
86  switch ($a_version) {
87  case "4.3.0":
88  return array(
89  "RuleId" => "integer",
90  "EntryId" => "integer",
91  "CalRecurrence" => "integer",
92  "FreqType" => "text",
93  "FreqUntilDate" => "text",
94  "FreqUntilCount" => "integer",
95  "Intervall" => "integer",
96  "Byday" => "text",
97  "Byweekno" => "text",
98  "Bymonth" => "text",
99  "Bymonthday" => "text",
100  "Byyearday" => "text",
101  "Bysetpos" => "text",
102  "Weekstart" => "text"
103  );
104  }
105  }
106  return [];
107  }
108 
112  public function readData(string $a_entity, string $a_version, array $a_ids): void
113  {
114  global $DIC;
115 
116  $ilDB = $DIC['ilDB'];
117 
118  if (!is_array($a_ids)) {
119  $a_ids = array($a_ids);
120  }
121 
122  // calendar
123  if ($a_entity == "calendar") {
124  switch ($a_version) {
125  case "4.3.0":
126  $this->getDirectDataFromQuery("SELECT cat_id, obj_id, title, color, type " .
127  " FROM cal_categories " .
128  " WHERE " .
129  $this->db->in("cat_id", $a_ids, false, "integer"));
130  break;
131  }
132  }
133 
134  // cal assignments
135  if ($a_entity == "cal_assignment") {
136  switch ($a_version) {
137  case "4.3.0":
138  $this->getDirectDataFromQuery("SELECT cat_id, cal_id entry_id " .
139  " FROM cal_cat_assignments " .
140  " WHERE " .
141  $this->db->in("cat_id", $a_ids, false, "integer"));
142  break;
143  }
144  }
145 
146  // cal entries
147  if ($a_entity == "cal_entry") {
148  switch ($a_version) {
149  case "4.3.0":
150  $this->getDirectDataFromQuery("SELECT cal_id id, title, subtitle, description, location, fullday, " .
151  " starta, enda, informations, auto_generated, context_id, translation_type, is_milestone, completion, notification " .
152  " FROM cal_entries " .
153  " WHERE " .
154  $this->db->in("cal_id", $a_ids, false, "integer"));
155  break;
156  }
157  }
158 
159  // recurrence_rule
160  if ($a_entity == "recurrence_rule") {
161  switch ($a_version) {
162  case "4.3.0":
163  $this->getDirectDataFromQuery("SELECT rule_id, cal_id entry_id, cal_recurrence, freq_type, freq_until_date, freq_until_count, " .
164  " intervall, byday, byweekno, bymonth, bymonthday, byyearday, bysetpos, weekstart " .
165  " FROM cal_recurrence_rules " .
166  " WHERE " .
167  $this->db->in("cal_id", $a_ids, false, "integer"));
168  break;
169  }
170  }
171  }
172 
176  protected function getDependencies(
177  string $a_entity,
178  string $a_version,
179  ?array $a_rec = null,
180  ?array $a_ids = null
181  ): array {
182  switch ($a_entity) {
183  case "calendar":
184  $assignmnts = ilCalendarCategoryAssignments::_getAssignedAppointments(array($a_rec["CatId"] ?? []));
185  $entries = array();
186  foreach ($assignmnts as $cal_id) {
187  $entries[$cal_id] = $cal_id;
188  }
189  return array(
190  "cal_entry" => array("ids" => $entries),
191  "cal_assignment" => array("ids" => $a_rec["CatId"] ?? null)
192  );
193  case "cal_entry":
194  return array(
195  "recurrence_rule" => array("ids" => $a_rec["Id"] ?? null)
196  );
197  }
198 
199  return [];
200  }
201 
205  public function importRecord(
206  string $a_entity,
207  array $a_types,
208  array $a_rec,
209  ilImportMapping $a_mapping,
210  string $a_schema_version
211  ): void {
212  switch ($a_entity) {
213  case "calendar":
214  // please note: we currently only support private user calendars to
215  // be imported
216  if (($a_rec["Type"] ?? 0) == 1) {
217  $usr_id = (int) $a_mapping->getMapping("Services/User", "usr", $a_rec["ObjId"]);
218  if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") {
219  $category = new ilCalendarCategory(0);
220  $category->setTitle((string) $a_rec["Title"]);
221  $category->setColor((string) $a_rec["Color"]);
222  $category->setType((int) ilCalendarCategory::TYPE_USR);
223  $category->setObjId((int) $usr_id);
224  $category->add();
225  $a_mapping->addMapping(
226  "Services/Calendar",
227  "calendar",
228  $a_rec["CatId"],
229  (string) $category->getCategoryID()
230  );
231  }
232  }
233  break;
234 
235  case "cal_entry":
236  // please note: we currently only support private user calendars to
237  // be imported
238  if ((int) ($a_rec["ContextId"] ?? 0) == 0) {
239  $entry = new ilCalendarEntry(0);
240  $entry->setTitle((string) $a_rec["Title"]);
241  $entry->setSubtitle((string) $a_rec["Subtitle"]);
242  $entry->setDescription((string) $a_rec["Description"]);
243  $entry->setLocation((string) $a_rec["Location"]);
244  $entry->setFullday((bool) $a_rec["Fullday"]);
245  if ($a_rec["Starta"] != "") {
246  $entry->setStart(new ilDateTime($a_rec["Starta"], IL_CAL_DATETIME, 'UTC'));
247  }
248  if (($a_rec["Enda"] ?? '') != "") {
249  $entry->setEnd(new ilDateTime($a_rec["Enda"], IL_CAL_DATETIME, 'UTC'));
250  }
251  $entry->setFurtherInformations((string) ($a_rec["Informations"] ?? ''));
252  $entry->setAutoGenerated((bool) ($a_rec["AutoGenerated"] ?? false));
253  $entry->setContextId((int) ($a_rec["ContextId"] ?? 0));
254  $entry->setMilestone((bool) ($a_rec["Milestone"] ?? false));
255  $entry->setCompletion((int) ($a_rec["Completion"] ?? 0));
256  $entry->setTranslationType((int) ($a_rec["TranslationType"] ?? 0));
257  $entry->enableNotification((bool) ($a_rec["Notification"] ?? false));
258  $entry->save();
259  $a_mapping->addMapping(
260  "Services/Calendar",
261  "cal_entry",
262  $a_rec["Id"],
263  (string) $entry->getEntryId()
264  );
265  }
266  break;
267 
268  case "cal_assignment":
269  $cat_id = (int) $a_mapping->getMapping("Services/Calendar", "calendar", $a_rec["CatId"]);
270  $entry_id = (int) $a_mapping->getMapping("Services/Calendar", "cal_entry", $a_rec["EntryId"]);
271  if ($cat_id > 0 && $entry_id > 0) {
272  $ass = new ilCalendarCategoryAssignments($entry_id);
273  $ass->addAssignment($cat_id);
274  }
275  break;
276 
277  case "recurrence_rule":
278  $entry_id = $a_mapping->getMapping("Services/Calendar", "cal_entry", $a_rec["EntryId"]);
279  if ($entry_id > 0) {
280  $rec = new ilCalendarRecurrence();
281  $rec->setEntryId((int) $entry_id);
282  $rec->setRecurrence((int) $a_rec["CalRecurrence"]);
283  $rec->setFrequenceType((string) $a_rec["FreqType"]);
284  if ($a_rec["FreqUntilDate"] != "") {
285  $rec->setFrequenceUntilDate(new ilDateTime((string) $a_rec["FreqUntilDate"], IL_CAL_DATETIME));
286  }
287  $rec->setFrequenceUntilCount((int) $a_rec["FreqUntilCount"]);
288  $rec->setInterval((int) ($a_rec["Interval"] ?? 0));
289  $rec->setBYDAY((string) ($a_rec["Byday"] ?? ''));
290  $rec->setBYWEEKNO((string) ($a_rec["Byweekno"] ?? ''));
291  $rec->setBYMONTH((string) ($a_rec["Bymonth"] ?? ''));
292  $rec->setBYMONTHDAY((string) ($a_rec["Bymonthday"] ?? ''));
293  $rec->setBYYEARDAY((string) ($a_rec["Byyearday"] ?? ''));
294  $rec->setBYSETPOS((string) ($a_rec["Bysetpos"] ?? ''));
295  $rec->setWeekstart((string) ($a_rec["Weekstart"] ?? ''));
296  $rec->save();
297  $a_mapping->addMapping(
298  "Services/Calendar",
299  "recurrence_rule",
300  $a_rec["RuleId"],
301  (string) $rec->getRecurrenceId()
302  );
303  }
304  break;
305  }
306  }
307 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_DATETIME
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getXmlNamespace(string $a_entity, string $a_schema_version)
getTypes(string $a_entity, string $a_version)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readData(string $a_entity, string $a_version, array $a_ids)
Stores calendar categories.
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
global $DIC
Definition: feed.php:28
Calendar data set class.
getMapping(string $a_comp, string $a_entity, string $a_old_id)
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
getDirectDataFromQuery(string $a_query, bool $a_convert_to_leading_upper=true, bool $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
static _getAssignedAppointments(array $a_cat_id)
Get assigned apointments.
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)