ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCalendarDataSet.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/DataSet/classes/class.ilDataSet.php");
5
14{
21 public function getSupportedVersions()
22 {
23 return array("4.3.0");
24 }
25
32 function getXmlNamespace($a_entity, $a_schema_version)
33 {
34 return "http://www.ilias.de/xml/Services/Calendar/".$a_entity;
35 }
36
43 protected function getTypes($a_entity, $a_version)
44 {
45 // calendar
46 if ($a_entity == "calendar")
47 {
48 switch ($a_version)
49 {
50 case "4.3.0":
51 return array (
52 "CatId" => "integer",
53 "ObjId" => "text",
54 "Title" => "text",
55 "Color" => "text",
56 "Type" => "integer"
57 );
58 }
59 }
60
61 // calendar entry
62 if ($a_entity == "cal_entry")
63 {
64 switch ($a_version)
65 {
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 "IsMilestone" => "integer",
81 "Completion" => "integer",
82 "Notification" => "integer"
83 );
84 }
85 }
86
87 // calendar/entry assignment
88 if ($a_entity == "cal_assignment")
89 {
90 switch ($a_version)
91 {
92 case "4.3.0":
93 return array (
94 "CatId" => "integer",
95 "EntryId" => "integer"
96 );
97 }
98 }
99
100 // recurrence rule
101 if ($a_entity == "recurrence_rule")
102 {
103 switch ($a_version)
104 {
105 case "4.3.0":
106 return array (
107 "RuleId" => "integer",
108 "EntryId" => "integer",
109 "CalRecurrence" => "integer",
110 "FreqType" => "text",
111 "FreqUntilDate" => "text",
112 "FreqUntilCount" => "integer",
113 "Intervall" => "integer",
114 "Byday" => "text",
115 "Byweekno" => "text",
116 "Bymonth" => "text",
117 "Bymonthday" => "text",
118 "Byyearday" => "text",
119 "Bysetpos" => "text",
120 "Weekstart" => "text"
121 );
122 }
123 }
124 }
125
132 function readData($a_entity, $a_version, $a_ids, $a_field = "")
133 {
134 global $ilDB;
135
136 if (!is_array($a_ids))
137 {
138 $a_ids = array($a_ids);
139 }
140
141 // calendar
142 if ($a_entity == "calendar")
143 {
144 switch ($a_version)
145 {
146 case "4.3.0":
147 $this->getDirectDataFromQuery("SELECT cat_id, obj_id, title, color, type ".
148 " FROM cal_categories ".
149 " WHERE ".
150 $ilDB->in("cat_id", $a_ids, false, "integer"));
151 break;
152 }
153 }
154
155 // cal assignments
156 if ($a_entity == "cal_assignment")
157 {
158 switch ($a_version)
159 {
160 case "4.3.0":
161 $this->getDirectDataFromQuery("SELECT cat_id, cal_id entry_id ".
162 " FROM cal_cat_assignments ".
163 " WHERE ".
164 $ilDB->in("cat_id", $a_ids, false, "integer"));
165 break;
166 }
167 }
168
169 // cal entries
170 if ($a_entity == "cal_entry")
171 {
172 switch ($a_version)
173 {
174 case "4.3.0":
175 $this->getDirectDataFromQuery("SELECT cal_id id, title, subtitle, description, location, fullday, ".
176 " starta, enda, informations, auto_generated, context_id, translation_type, is_milestone, completion, notification ".
177 " FROM cal_entries ".
178 " WHERE ".
179 $ilDB->in("cal_id", $a_ids, false, "integer"));
180 break;
181 }
182 }
183
184
185 // recurrence_rule
186 if ($a_entity == "recurrence_rule")
187 {
188 switch ($a_version)
189 {
190 case "4.3.0":
191 $this->getDirectDataFromQuery("SELECT rule_id, cal_id entry_id, cal_recurrence, freq_type, freq_until_date, freq_until_count, ".
192 " intervall, byday, byweekno, bymonth, bymonthday, byyearday, bysetpos, weekstart ".
193 " FROM cal_recurrence_rules ".
194 " WHERE ".
195 $ilDB->in("cal_id", $a_ids, false, "integer"));
196 break;
197 }
198 }
199 }
200
204 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
205 {
206 switch ($a_entity)
207 {
208 case "calendar":
209 include_once("./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php");
210 $assignmnts = ilCalendarCategoryAssignments::_getAssignedAppointments(array($a_rec["CatId"]));
211 $entries = array();
212 foreach ($assignmnts as $cal_id)
213 {
214 $entries[$cal_id] = $cal_id;
215 }
216 return array (
217 "cal_entry" => array("ids" => $entries),
218 "cal_assignment" => array("ids" => $a_rec["CatId"])
219 );
220 case "cal_entry":
221 return array (
222 "recurrence_rule" => array("ids" => $a_rec["Id"])
223 );
224 }
225
226 return false;
227 }
228
235 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
236 {
237 switch ($a_entity)
238 {
239 case "calendar":
240 // please note: we currently only support private user calendars to
241 // be imported
242 if ($a_rec["Type"] == 1)
243 {
244 $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["ObjId"]);
245 if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr")
246 {
247 include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
248 $category = new ilCalendarCategory(0);
249 $category->setTitle($a_rec["Title"]);
250 $category->setColor($a_rec["Color"]);
251 $category->setType(ilCalendarCategory::TYPE_USR);
252 $category->setObjId($usr_id);
253 $category->add();
254 $a_mapping->addMapping("Services/Calendar", "calendar", $a_rec["CatId"],
255 $category->getCategoryID());
256 }
257 }
258 break;
259
260 case "cal_entry":
261 // please note: we currently only support private user calendars to
262 // be imported
263 if ((int) $a_rec["ContextId"] == 0)
264 {
265 include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
266 $entry = new ilCalendarEntry(0);
267 $entry->setTitle($a_rec["Title"]);
268 $entry->setSubtitle($a_rec["Subtitle"]);
269 $entry->setDescription($a_rec["Description"]);
270 $entry->setLocation($a_rec["Location"]);
271 $entry->setFullday($a_rec["Fullday"]);
272 if ($a_rec["Starta"] != "")
273 {
274 $entry->setStart(new ilDateTime($a_rec["Starta"], IL_CAL_DATETIME, 'UTC'));
275 }
276 if ($a_rec["Enda"] != "")
277 {
278 $entry->setEnd(new ilDateTime($a_rec["Enda"], IL_CAL_DATETIME, 'UTC'));
279 }
280 $entry->setFurtherInformations($a_rec["Informations"]);
281 $entry->setAutoGenerated($a_rec["AutoGenerated"]);
282 $entry->setContextId($a_rec["ContextId"]);
283 $entry->setMilestone($a_rec["Milestone"]);
284 $entry->setCompletion($a_rec["Completion"]);
285 $entry->setTranslationType($a_rec["TranslationType"]);
286 $entry->enableNotification($a_rec["Notification"]);
287 $entry->save();
288 $a_mapping->addMapping("Services/Calendar", "cal_entry", $a_rec["Id"],
289 $entry->getEntryId());
290 }
291 break;
292
293 case "cal_assignment":
294 $cat_id = $a_mapping->getMapping("Services/Calendar", "calendar", $a_rec["CatId"]);
295 $entry_id = $a_mapping->getMapping("Services/Calendar", "cal_entry", $a_rec["EntryId"]);
296 if ($cat_id > 0 && $entry_id > 0)
297 {
298 include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
299 $ass = new ilCalendarCategoryAssignments($entry_id);
300 $ass->addAssignment($cat_id);
301 }
302 break;
303
304 case "recurrence_rule":
305 $entry_id = $a_mapping->getMapping("Services/Calendar", "cal_entry", $a_rec["EntryId"]);
306 if ($entry_id > 0)
307 {
308 include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
309 $rec = new ilCalendarRecurrence();
310 $rec->setEntryId($entry_id);
311 $rec->setRecurrence($a_rec["CalRecurrence"]);
312 $rec->setFrequenceType($a_rec["FreqType"]);
313 if ($a_rec["FreqUntilDate"] != "")
314 {
315 $rec->setFrequenceUntilDate(new ilDateTime($a_rec["FreqUntilDate"], IL_CAL_DATETIME));
316 }
317 $rec->setFrequenceUntilCount($a_rec["FreqUntilCount"]);
318 $rec->setInterval($a_rec["Interval"]);
319 $rec->setBYDAY($a_rec["Byday"]);
320 $rec->setBYWEEKNO($a_rec["Byweekno"]);
321 $rec->setBYMONTH($a_rec["Bymonth"]);
322 $rec->setBYMONTHDAY($a_rec["Bymonthday"]);
323 $rec->setBYYEARDAY($a_rec["Byyearday"]);
324 $rec->setBYSETPOS($a_rec["Bysetpos"]);
325 $rec->setWeekstart($a_rec["Weekstart"]);
326 $rec->save();
327 $a_mapping->addMapping("Services/Calendar", "recurrence_rule", $a_rec["RuleId"],
328 $rec->getRecurrenceId());
329 }
330 break;
331 }
332 }
333}
334?>
const IL_CAL_DATETIME
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.
Stores calendar categories.
Calendar data set class.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
getSupportedVersions()
Get supported versions.
getTypes($a_entity, $a_version)
Get field types for entity.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
Model for a calendar entry.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getDirectDataFromQuery($a_query, $a_convert_to_leading_upper=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
@classDescription Date and time handling
static _lookupType($a_id, $a_reference=false)
lookup object type
global $ilDB