ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilSessionDataSet.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/DataSet/classes/class.ilDataSet.php");
5
14{
18 private $logger = null;
19
23 private $target_id = 0;
24
25 public function __construct()
26 {
27 global $DIC;
28
30 $this->logger = $DIC->logger()->sess();
31 }
32
36 public function setTargetId(int $target_id)
37 {
38 $this->target_id = $target_id;
39 }
40
47 public function getSupportedVersions()
48 {
49 return ['7.0'];
50 //return array("4.1.0", "5.0.0", "5.1.0", '5.4.0', '7.0');
51 }
52
59 public function getXmlNamespace($a_entity, $a_schema_version)
60 {
61 return "http://www.ilias.de/xml/Modules/Session/" . $a_entity;
62 }
63
70 protected function getTypes($a_entity, $a_version)
71 {
72 if ($a_entity == "sess") {
73 switch ($a_version) {
74 case "4.1.0":
75 return array(
76 "Id" => "integer",
77 "Title" => "text",
78 "Description" => "text",
79 "Location" => "text",
80 "TutorName" => "text",
81 "TutorEmail" => "text",
82 "TutorPhone" => "text",
83 "Details" => "text",
84 "Registration" => "integer",
85 "EventStart" => "text",
86 "EventEnd" => "text",
87 "StartingTime" => "integer",
88 "EndingTime" => "integer",
89 "Fulltime" => "integer"
90 );
91 case "5.0.0":
92 return array(
93 "Id" => "integer",
94 "Title" => "text",
95 "Description" => "text",
96 "Location" => "text",
97 "TutorName" => "text",
98 "TutorEmail" => "text",
99 "TutorPhone" => "text",
100 "Details" => "text",
101 "Registration" => "integer",
102 "EventStart" => "text",
103 "EventEnd" => "text",
104 "StartingTime" => "integer",
105 "EndingTime" => "integer",
106 "Fulltime" => "integer",
107 "LimitedRegistration" => "integer",
108 "WaitingList" => "integer",
109 "LimitUsers" => "integer"
110 );
111 case "5.1.0":
112 return array(
113 "Id" => "integer",
114 "Title" => "text",
115 "Description" => "text",
116 "Location" => "text",
117 "TutorName" => "text",
118 "TutorEmail" => "text",
119 "TutorPhone" => "text",
120 "Details" => "text",
121 "Registration" => "integer",
122 "EventStart" => "text",
123 "EventEnd" => "text",
124 "StartingTime" => "integer",
125 "EndingTime" => "integer",
126 "Fulltime" => "integer",
127 "LimitedRegistration" => "integer",
128 "WaitingList" => "integer",
129 "AutoWait" => "integer",
130 "LimitUsers" => "integer",
131 "MinUsers" => "integer"
132 );
133 case "5.4.0":
134 return array(
135 "Id" => "integer",
136 "Title" => "text",
137 "Description" => "text",
138 "Location" => "text",
139 "TutorName" => "text",
140 "TutorEmail" => "text",
141 "TutorPhone" => "text",
142 "Details" => "text",
143 "Registration" => "integer",
144 "EventStart" => "text",
145 "EventEnd" => "text",
146 "StartingTime" => "integer",
147 "EndingTime" => "integer",
148 "Fulltime" => "integer",
149 "LimitedRegistration" => "integer",
150 "WaitingList" => "integer",
151 "AutoWait" => "integer",
152 "LimitUsers" => "integer",
153 "MinUsers" => "integer",
154 'MailMembers' => 'integer',
155 'ShowMembers' => 'integer',
156 'Type' => 'integer'
157 );
158 case "7.0":
159 return array(
160 "Id" => "integer",
161 "Title" => "text",
162 "Description" => "text",
163 "Location" => "text",
164 "TutorName" => "text",
165 "TutorEmail" => "text",
166 "TutorPhone" => "text",
167 "Details" => "text",
168 "Registration" => "integer",
169 "EventStart" => "text",
170 "EventEnd" => "text",
171 "StartingTime" => "integer",
172 "EndingTime" => "integer",
173 "Fulltime" => "integer",
174 "LimitedRegistration" => "integer",
175 "WaitingList" => "integer",
176 "AutoWait" => "integer",
177 "LimitUsers" => "integer",
178 "MinUsers" => "integer",
179 'MailMembers' => 'integer',
180 'ShowMembers' => 'integer',
181 'Type' => 'integer',
182 'ShowCannotPart' => 'integer',
183 'RegistrationNotificationEnabled' => 'integer',
184 'RegistrationNotificationOption' => 'text'
185 );
186 }
187 }
188
189 if ($a_entity == "sess_item") {
190 switch ($a_version) {
191 case "4.1.0":
192 case "5.0.0":
193 case "5.1.0":
194 case "5.4.0":
195 case '7.0':
196 return array(
197 "SessionId" => "integer",
198 "ItemId" => "text",
199 );
200 }
201 }
202 }
203
210 public function readData($a_entity, $a_version, $a_ids, $a_field = "")
211 {
212 global $DIC;
213
214 $ilDB = $DIC['ilDB'];
215
216 if (!is_array($a_ids)) {
217 $a_ids = array($a_ids);
218 }
219
220 if ($a_entity == "sess") {
221 switch ($a_version) {
222 case "4.1.0":
223 $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, od.description description, " .
224 " location, tutor_name, tutor_email, tutor_phone, details, registration, " .
225 " e_start event_start, e_end event_end, starting_time, ending_time, fulltime " .
226 " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
227 " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
228 "WHERE " .
229 $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
230 break;
231 case "5.0.0":
232 $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, odes.description description, " .
233 " location, tutor_name, tutor_email, tutor_phone, details, reg_type registration, " .
234 " reg_limited limited_registration, reg_waiting_list waiting_list, " .
235 " reg_limit_users limit_users, " .
236 " e_start event_start, e_end event_end, starting_time, ending_time, fulltime " .
237 " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
238 " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
239 " JOIN object_description odes ON (ev.obj_id = odes.obj_id) " .
240 "WHERE " .
241 $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
242 break;
243 case "5.1.0":
244 $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, odes.description description, " .
245 " location, tutor_name, tutor_email, tutor_phone, details, reg_type registration, " .
246 " reg_limited limited_registration, reg_waiting_list waiting_list, reg_auto_wait auto_wait, " .
247 " reg_limit_users limit_users, reg_min_users min_users, " .
248 " e_start event_start, e_end event_end, starting_time, ending_time, fulltime " .
249 " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
250 " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
251 " JOIN object_description odes ON (ev.obj_id = odes.obj_id) " .
252 "WHERE " .
253 $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
254 break;
255 case "5.4.0":
256 $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, odes.description description, " .
257 " location, tutor_name, tutor_email, tutor_phone, details, reg_type registration, " .
258 " reg_limited limited_registration, reg_waiting_list waiting_list, reg_auto_wait auto_wait, " .
259 " reg_limit_users limit_users, reg_min_users min_users, " .
260 " e_start event_start, e_end event_end, starting_time, ending_time, fulltime, mail_members, show_members " .
261 " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
262 " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
263 " JOIN object_description odes ON (ev.obj_id = odes.obj_id) " .
264 "WHERE " .
265 $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
266
267 $this->readDidacticTemplateType($a_ids);
268 break;
269 case "7.0":
270 $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, odes.description description, " .
271 " location, tutor_name, tutor_email, tutor_phone, details, reg_type registration, " .
272 " reg_limited limited_registration, reg_waiting_list waiting_list, reg_auto_wait auto_wait, " .
273 " reg_limit_users limit_users, reg_min_users min_users, " .
274 " e_start event_start, e_end event_end, starting_time, ending_time, fulltime, mail_members, show_members, " .
275 " show_cannot_part, reg_notification registration_notification_enabled, " .
276 " notification_opt registration_notification_option " .
277 " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
278 " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
279 " JOIN object_description odes ON (ev.obj_id = odes.obj_id) " .
280 "WHERE " .
281 $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
282
283 $this->readDidacticTemplateType($a_ids);
284 break;
285 }
286 }
287
288 if ($a_entity == "sess_item") {
289 switch ($a_version) {
290 case "4.1.0":
291 case "5.0.0":
292 case "5.1.0":
293 case '5.4.0':
294 case '7.0':
295 $this->getDirectDataFromQuery($q = "SELECT event_id session_id, item_id " .
296 " FROM event_items " .
297 "WHERE " .
298 $ilDB->in("event_id", $a_ids, false, "integer"));
299 break;
300 }
301 }
302 }
303
310 public function getXmlRecord($a_entity, $a_version, $a_set)
311 {
312 if ($a_entity == "sess") {
313 // convert server dates to utc
314 if (!$a_set["Fulltime"]) {
315 // nothing has to be done here, since the dates are already stored in UTC
316 #$start = new ilDateTime($a_set["EventStart"], IL_CAL_DATETIME);
317 #$a_set["EventStart"] = $start->get(IL_CAL_DATETIME,'','UTC');
318 #$end = new ilDateTime($a_set["EventEnd"], IL_CAL_DATETIME);
319 #$a_set["EventEnd"] = $end->get(IL_CAL_DATETIME,'','UTC');
320 }
321 }
322 if ($a_entity == "sess_item") {
323 // make ref id an object id
324 $a_set["ItemId"] = ilObject::_lookupObjId($a_set["ItemId"]);
325 }
326 return $a_set;
327 }
328
329
330
334 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
335 {
336 switch ($a_entity) {
337 case "sess":
338 return array(
339 "sess_item" => array("ids" => $a_rec["Id"])
340 );
341 }
342
343 return false;
344 }
345
346
353 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
354 {
355 switch ($a_entity) {
356 case "sess":
357 include_once("./Modules/Session/classes/class.ilObjSession.php");
358 include_once("./Modules/Session/classes/class.ilSessionAppointment.php");
359
360 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
361 $refs = ilObject::_getAllReferences($new_id);
362 $newObj = ilObjectFactory::getInstanceByRefId(end($refs), false);
363 } else {
364 $this->logger->debug('Session creation without existing instance');
365 $newObj = new ilObjSession();
366 $newObj->setType("sess");
367 $newObj->create(true);
368 }
369 $newObj->setTitle($a_rec["Title"]);
370 $newObj->setDescription($a_rec["Description"]);
371 $newObj->setLocation($a_rec["Location"]);
372 $newObj->setName($a_rec["TutorName"]);
373 $newObj->setPhone($a_rec["TutorPhone"]);
374 $newObj->setEmail($a_rec["TutorEmail"]);
375 $newObj->setDetails($a_rec["Details"]);
376
377 switch ($a_schema_version) {
378 case '5.4.0':
379 case '7.0':
380 if (isset($a_rec['MailMembers'])) {
381 $newObj->setMailToMembersType($a_rec['MailMembers']);
382 }
383 if (isset($a_rec['ShowMembers'])) {
384 $newObj->setShowMembers($a_rec['ShowMembers']);
385 }
386 if (isset($a_rec['ShowCannotPart'])) {
387 $newObj->enableCannotParticipateOption((bool) $a_rec['ShowCannotPart']);
388 }
389 if (isset($a_rec['RegistrationNotificationEnabled'])) {
390 $newObj->setRegistrationNotificationEnabled((bool) $a_rec['RegistrationNotificationEnabled']);
391 }
392 if (isset($a_rec['RegistrationNotificationOption'])) {
393 $newObj->setRegistrationNotificationOption((string) $a_rec['RegistrationNotificationOption']);
394 }
395 $this->applyDidacticTemplate($newObj, $a_rec['Type']);
396 // no break
397 case "5.0.0":
398 case "5.1.0":
399 $newObj->setRegistrationType($a_rec["Registration"]);
400
401 $newObj->enableRegistrationUserLimit($a_rec["LimitedRegistration"]);
402 $newObj->setRegistrationMaxUsers($a_rec["LimitUsers"]);
403 $newObj->enableRegistrationWaitingList($a_rec["WaitingList"]);
404
405 if (isset($a_rec["MinUsers"])) {
406 $newObj->setRegistrationMinUsers($a_rec["MinUsers"]);
407 }
408
409 if (isset($a_rec["AutoWait"])) {
410 $newObj->setWaitingListAutoFill($a_rec["AutoWait"]);
411 }
412 break;
413 }
414
415 $newObj->update(true);
416
417 $start = new ilDateTime($a_rec["EventStart"], IL_CAL_DATETIME, "UTC");
418 $end = new ilDateTime($a_rec["EventEnd"], IL_CAL_DATETIME, "UTC");
419//echo "<br>".$start->get(IL_CAL_UNIX);
420//echo "<br>".$start->get(IL_CAL_DATETIME);
422 $app->setStart($a_rec["EventStart"]);
423 $app->setEnd($a_rec["EventEnd"]);
424 $app->setStartingTime($start->get(IL_CAL_UNIX));
425 $app->setEndingTime($end->get(IL_CAL_UNIX));
426 $app->toggleFullTime($a_rec["Fulltime"]);
427 $app->setSessionId($newObj->getId());
428 $app->create();
429
430 //$newObj->setAppointments(array($app));
431 //$newObj->update();
432
433 $this->current_obj = $newObj;
434 $a_mapping->addMapping("Modules/Session", "sess", $a_rec["Id"], $newObj->getId());
435 $a_mapping->addMapping('Services/Object', 'objs', $a_rec['Id'], $newObj->getId());
436 $a_mapping->addMapping('Services/AdvancedMetaData', 'parent', $a_rec['Id'], $newObj->getId());
437 $a_mapping->addMapping(
438 "Services/MetaData",
439 "md",
440 $a_rec["Id"] . ":0:sess",
441 $newObj->getId() . ":0:sess"
442 );
443
444
445//var_dump($a_mapping->mappings["Services/News"]["news_context"]);
446 break;
447
448 case "sess_item":
449
450 if ($obj_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['ItemId'])) {
451 $ref_id = current(ilObject::_getAllReferences($obj_id));
452 include_once './Modules/Session/classes/class.ilEventItems.php';
453 $evi = new ilEventItems($this->current_obj->getId());
454 $evi->addItem($ref_id);
455 $evi->update();
456 }
457 break;
458 }
459 }
460
464 protected function readDidacticTemplateType($a_obj_ids)
465 {
466 $ref_ids = [];
467 $counter = 0;
468 foreach ($a_obj_ids as $obj_id) {
469 $ref_ids = ilObject::_getAllReferences($obj_id);
470 foreach ($ref_ids as $ref_id) {
472 $this->data[$counter++]['Type'] = (int) $tpl_id;
473 break;
474 }
475 }
476 }
477
482 protected function applyDidacticTemplate(ilObject $rep_object, $tpl_id)
483 {
484 $this->logger->debug('Apply didactic template');
485
486 if ((int) $tpl_id == 0) {
487 $this->logger->debug('Default permissions');
488 // Default template
489 return;
490 }
491
492 $templates = ilDidacticTemplateSettings::getInstanceByObjectType('sess')->getTemplates();
493 foreach ($templates as $template) {
494 if ($template->isAutoGenerated()) {
495 $this->logger->debug('Apply first auto generated');
496 $rep_object->applyDidacticTemplate($template->getId());
497 }
498 }
499 }
500}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
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 lookupTemplateId($a_ref_id)
Lookup template id @global ilDB $ilDB.
static getInstanceByObjectType($a_obj_type)
Get instance by obj type.
class ilEvent
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
static _getAllReferences($a_id)
get all reference ids of object
applyDidacticTemplate($a_tpl_id)
Apply template.
class ilSessionAppointment
Session data set class.
readDidacticTemplateType($a_obj_ids)
getTypes($a_entity, $a_version)
Get field types for entity.
getSupportedVersions()
Get supported versions.
applyDidacticTemplate(ilObject $rep_object, $tpl_id)
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
getXmlRecord($a_entity, $a_version, $a_set)
Get xml record (export)
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
setTargetId(int $target_id)
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
$app
Definition: cli.php:38
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilDB