ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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  "Notification" => "integer"
67  );
68  }
69  }
70 
71  // calendar/entry assignment
72  if ($a_entity == "cal_assignment") {
73  switch ($a_version) {
74  case "4.3.0":
75  return array(
76  "CatId" => "integer",
77  "EntryId" => "integer"
78  );
79  }
80  }
81 
82  // recurrence rule
83  if ($a_entity == "recurrence_rule") {
84  switch ($a_version) {
85  case "4.3.0":
86  return array(
87  "RuleId" => "integer",
88  "EntryId" => "integer",
89  "CalRecurrence" => "integer",
90  "FreqType" => "text",
91  "FreqUntilDate" => "text",
92  "FreqUntilCount" => "integer",
93  "Intervall" => "integer",
94  "Byday" => "text",
95  "Byweekno" => "text",
96  "Bymonth" => "text",
97  "Bymonthday" => "text",
98  "Byyearday" => "text",
99  "Bysetpos" => "text",
100  "Weekstart" => "text"
101  );
102  }
103  }
104  return [];
105  }
106 
110  public function readData(string $a_entity, string $a_version, array $a_ids): void
111  {
112  if (!is_array($a_ids)) {
113  $a_ids = array($a_ids);
114  }
115 
116  // calendar
117  if ($a_entity == "calendar") {
118  switch ($a_version) {
119  case "4.3.0":
120  $this->getDirectDataFromQuery("SELECT cat_id, obj_id, title, color, type " .
121  " FROM cal_categories " .
122  " WHERE " .
123  $this->db->in("cat_id", $a_ids, false, "integer"));
124  break;
125  }
126  }
127 
128  // cal assignments
129  if ($a_entity == "cal_assignment") {
130  switch ($a_version) {
131  case "4.3.0":
132  $this->getDirectDataFromQuery("SELECT cat_id, cal_id entry_id " .
133  " FROM cal_cat_assignments " .
134  " WHERE " .
135  $this->db->in("cat_id", $a_ids, false, "integer"));
136  break;
137  }
138  }
139 
140  // cal entries
141  if ($a_entity == "cal_entry") {
142  switch ($a_version) {
143  case "4.3.0":
144  $this->getDirectDataFromQuery("SELECT cal_id id, title, subtitle, description, location, fullday, " .
145  " starta, enda, informations, auto_generated, context_id, translation_type, notification " .
146  " FROM cal_entries " .
147  " WHERE " .
148  $this->db->in("cal_id", $a_ids, false, "integer"));
149  break;
150  }
151  }
152 
153  // recurrence_rule
154  if ($a_entity == "recurrence_rule") {
155  switch ($a_version) {
156  case "4.3.0":
157  $this->getDirectDataFromQuery("SELECT rule_id, cal_id entry_id, cal_recurrence, freq_type, freq_until_date, freq_until_count, " .
158  " intervall, byday, byweekno, bymonth, bymonthday, byyearday, bysetpos, weekstart " .
159  " FROM cal_recurrence_rules " .
160  " WHERE " .
161  $this->db->in("cal_id", $a_ids, false, "integer"));
162  break;
163  }
164  }
165  }
166 
170  protected function getDependencies(
171  string $a_entity,
172  string $a_version,
173  ?array $a_rec = null,
174  ?array $a_ids = null
175  ): array {
176  switch ($a_entity) {
177  case "calendar":
178  $assignmnts = ilCalendarCategoryAssignments::_getAssignedAppointments(array($a_rec["CatId"] ?? []));
179  $entries = array();
180  foreach ($assignmnts as $cal_id) {
181  $entries[$cal_id] = $cal_id;
182  }
183  return array(
184  "cal_entry" => array("ids" => $entries),
185  "cal_assignment" => array("ids" => $a_rec["CatId"] ?? null)
186  );
187  case "cal_entry":
188  return array(
189  "recurrence_rule" => array("ids" => $a_rec["Id"] ?? null)
190  );
191  }
192 
193  return [];
194  }
195 
199  public function importRecord(
200  string $a_entity,
201  array $a_types,
202  array $a_rec,
203  ilImportMapping $a_mapping,
204  string $a_schema_version
205  ): void {
206  switch ($a_entity) {
207  case "calendar":
208  // please note: we currently only support private user calendars to
209  // be imported
210  if (($a_rec["Type"] ?? 0) == 1) {
211  $usr_id = (int) $a_mapping->getMapping("Services/User", "usr", $a_rec["ObjId"]);
212  if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") {
213  $category = new ilCalendarCategory(0);
214  $category->setTitle((string) $a_rec["Title"]);
215  $category->setColor((string) $a_rec["Color"]);
216  $category->setType((int) ilCalendarCategory::TYPE_USR);
217  $category->setObjId((int) $usr_id);
218  $category->add();
219  $a_mapping->addMapping(
220  "Services/Calendar",
221  "calendar",
222  $a_rec["CatId"],
223  (string) $category->getCategoryID()
224  );
225  }
226  }
227  break;
228 
229  case "cal_entry":
230  // please note: we currently only support private user calendars to
231  // be imported
232  if ((int) ($a_rec["ContextId"] ?? 0) == 0) {
233  $entry = new ilCalendarEntry(0);
234  $entry->setTitle((string) $a_rec["Title"]);
235  $entry->setSubtitle((string) $a_rec["Subtitle"]);
236  $entry->setDescription((string) $a_rec["Description"]);
237  $entry->setLocation((string) $a_rec["Location"]);
238  $entry->setFullday((bool) $a_rec["Fullday"]);
239  if ($a_rec["Starta"] != "") {
240  $entry->setStart(new ilDateTime($a_rec["Starta"], IL_CAL_DATETIME, 'UTC'));
241  }
242  if (($a_rec["Enda"] ?? '') != "") {
243  $entry->setEnd(new ilDateTime($a_rec["Enda"], IL_CAL_DATETIME, 'UTC'));
244  }
245  $entry->setFurtherInformations((string) ($a_rec["Informations"] ?? ''));
246  $entry->setAutoGenerated((bool) ($a_rec["AutoGenerated"] ?? false));
247  $entry->setContextId((int) ($a_rec["ContextId"] ?? 0));
248  $entry->setTranslationType((int) ($a_rec["TranslationType"] ?? 0));
249  $entry->enableNotification((bool) ($a_rec["Notification"] ?? false));
250  $entry->save();
251  $a_mapping->addMapping(
252  "Services/Calendar",
253  "cal_entry",
254  $a_rec["Id"],
255  (string) $entry->getEntryId()
256  );
257  }
258  break;
259 
260  case "cal_assignment":
261  $cat_id = (int) $a_mapping->getMapping("Services/Calendar", "calendar", $a_rec["CatId"]);
262  $entry_id = (int) $a_mapping->getMapping("Services/Calendar", "cal_entry", $a_rec["EntryId"]);
263  if ($cat_id > 0 && $entry_id > 0) {
264  $ass = new ilCalendarCategoryAssignments($entry_id);
265  $ass->addAssignment($cat_id);
266  }
267  break;
268 
269  case "recurrence_rule":
270  $entry_id = $a_mapping->getMapping("Services/Calendar", "cal_entry", $a_rec["EntryId"]);
271  if ($entry_id > 0) {
272  $rec = new ilCalendarRecurrence();
273  $rec->setEntryId((int) $entry_id);
274  $rec->setRecurrence((int) $a_rec["CalRecurrence"]);
275  $rec->setFrequenceType((string) $a_rec["FreqType"]);
276  if ($a_rec["FreqUntilDate"] != "") {
277  $rec->setFrequenceUntilDate(new ilDateTime((string) $a_rec["FreqUntilDate"], IL_CAL_DATETIME));
278  }
279  $rec->setFrequenceUntilCount((int) $a_rec["FreqUntilCount"]);
280  $rec->setInterval((int) ($a_rec["Interval"] ?? 0));
281  $rec->setBYDAY((string) ($a_rec["Byday"] ?? ''));
282  $rec->setBYWEEKNO((string) ($a_rec["Byweekno"] ?? ''));
283  $rec->setBYMONTH((string) ($a_rec["Bymonth"] ?? ''));
284  $rec->setBYMONTHDAY((string) ($a_rec["Bymonthday"] ?? ''));
285  $rec->setBYYEARDAY((string) ($a_rec["Byyearday"] ?? ''));
286  $rec->setBYSETPOS((string) ($a_rec["Bysetpos"] ?? ''));
287  $rec->setWeekstart((string) ($a_rec["Weekstart"] ?? ''));
288  $rec->save();
289  $a_mapping->addMapping(
290  "Services/Calendar",
291  "recurrence_rule",
292  $a_rec["RuleId"],
293  (string) $rec->getRecurrenceId()
294  );
295  }
296  break;
297  }
298  }
299 }
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)
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)
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)