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