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