ILIAS  release_8 Revision v8.24
class.ilSessionDataSet.php
Go to the documentation of this file.
1<?php
2
20declare(strict_types=1);
21
30{
31 protected ilLogger $logger;
32 protected string $target_id = "";
34
35 public function __construct()
36 {
37 global $DIC;
38
40 $this->logger = $DIC->logger()->sess();
41 }
42
43 public function setTargetId(string $target_id): void
44 {
45 $this->target_id = $target_id;
46 }
47
48 public function getSupportedVersions(): array
49 {
50 return ['7.0'];
51 //return array("4.1.0", "5.0.0", "5.1.0", '5.4.0', '7.0');
52 }
53
54 protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
55 {
56 return "http://www.ilias.de/xml/Modules/Session/" . $a_entity;
57 }
58
59 protected function getTypes(string $a_entity, string $a_version): array
60 {
61 if ($a_entity == "sess") {
62 switch ($a_version) {
63 case "4.1.0":
64 return array(
65 "Id" => "integer",
66 "Title" => "text",
67 "Description" => "text",
68 "Location" => "text",
69 "TutorName" => "text",
70 "TutorEmail" => "text",
71 "TutorPhone" => "text",
72 "Details" => "text",
73 "Registration" => "integer",
74 "EventStart" => "text",
75 "EventEnd" => "text",
76 "StartingTime" => "integer",
77 "EndingTime" => "integer",
78 "Fulltime" => "integer"
79 );
80 case "5.0.0":
81 return array(
82 "Id" => "integer",
83 "Title" => "text",
84 "Description" => "text",
85 "Location" => "text",
86 "TutorName" => "text",
87 "TutorEmail" => "text",
88 "TutorPhone" => "text",
89 "Details" => "text",
90 "Registration" => "integer",
91 "EventStart" => "text",
92 "EventEnd" => "text",
93 "StartingTime" => "integer",
94 "EndingTime" => "integer",
95 "Fulltime" => "integer",
96 "LimitedRegistration" => "integer",
97 "WaitingList" => "integer",
98 "LimitUsers" => "integer"
99 );
100 case "5.1.0":
101 return array(
102 "Id" => "integer",
103 "Title" => "text",
104 "Description" => "text",
105 "Location" => "text",
106 "TutorName" => "text",
107 "TutorEmail" => "text",
108 "TutorPhone" => "text",
109 "Details" => "text",
110 "Registration" => "integer",
111 "EventStart" => "text",
112 "EventEnd" => "text",
113 "StartingTime" => "integer",
114 "EndingTime" => "integer",
115 "Fulltime" => "integer",
116 "LimitedRegistration" => "integer",
117 "WaitingList" => "integer",
118 "AutoWait" => "integer",
119 "LimitUsers" => "integer",
120 "MinUsers" => "integer"
121 );
122 case "5.4.0":
123 return array(
124 "Id" => "integer",
125 "Title" => "text",
126 "Description" => "text",
127 "Location" => "text",
128 "TutorName" => "text",
129 "TutorEmail" => "text",
130 "TutorPhone" => "text",
131 "Details" => "text",
132 "Registration" => "integer",
133 "EventStart" => "text",
134 "EventEnd" => "text",
135 "StartingTime" => "integer",
136 "EndingTime" => "integer",
137 "Fulltime" => "integer",
138 "LimitedRegistration" => "integer",
139 "WaitingList" => "integer",
140 "AutoWait" => "integer",
141 "LimitUsers" => "integer",
142 "MinUsers" => "integer",
143 'MailMembers' => 'integer',
144 'ShowMembers' => 'integer',
145 'Type' => 'integer'
146 );
147 case "7.0":
148 return array(
149 "Id" => "integer",
150 "Title" => "text",
151 "Description" => "text",
152 "Location" => "text",
153 "TutorName" => "text",
154 "TutorEmail" => "text",
155 "TutorPhone" => "text",
156 "Details" => "text",
157 "Registration" => "integer",
158 "EventStart" => "text",
159 "EventEnd" => "text",
160 "StartingTime" => "integer",
161 "EndingTime" => "integer",
162 "Fulltime" => "integer",
163 "LimitedRegistration" => "integer",
164 "WaitingList" => "integer",
165 "AutoWait" => "integer",
166 "LimitUsers" => "integer",
167 "MinUsers" => "integer",
168 'MailMembers' => 'integer',
169 'ShowMembers' => 'integer',
170 'Type' => 'integer',
171 'ShowCannotPart' => 'integer',
172 'RegistrationNotificationEnabled' => 'integer',
173 'RegistrationNotificationOption' => 'text'
174 );
175 }
176 }
177
178 if ($a_entity == "sess_item") {
179 switch ($a_version) {
180 case "4.1.0":
181 case "5.0.0":
182 case "5.1.0":
183 case "5.4.0":
184 case '7.0':
185 return array(
186 "SessionId" => "integer",
187 "ItemId" => "text",
188 );
189 }
190 }
191
192 return [];
193 }
194
195 public function readData(string $a_entity, string $a_version, array $a_ids): void
196 {
198
199 if ($a_entity == "sess") {
200 switch ($a_version) {
201 case "4.1.0":
202 $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, od.description description, " .
203 " location, tutor_name, tutor_email, tutor_phone, details, registration, " .
204 " e_start event_start, e_end event_end, starting_time, ending_time, fulltime " .
205 " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
206 " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
207 "WHERE " .
208 $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
209 break;
210 case "5.0.0":
211 $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, odes.description description, " .
212 " location, tutor_name, tutor_email, tutor_phone, details, reg_type registration, " .
213 " reg_limited limited_registration, reg_waiting_list waiting_list, " .
214 " reg_limit_users limit_users, " .
215 " e_start event_start, e_end event_end, starting_time, ending_time, fulltime " .
216 " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
217 " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
218 " JOIN object_description odes ON (ev.obj_id = odes.obj_id) " .
219 "WHERE " .
220 $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
221 break;
222 case "5.1.0":
223 $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, odes.description description, " .
224 " location, tutor_name, tutor_email, tutor_phone, details, reg_type registration, " .
225 " reg_limited limited_registration, reg_waiting_list waiting_list, reg_auto_wait auto_wait, " .
226 " reg_limit_users limit_users, reg_min_users min_users, " .
227 " e_start event_start, e_end event_end, starting_time, ending_time, fulltime " .
228 " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
229 " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
230 " JOIN object_description odes ON (ev.obj_id = odes.obj_id) " .
231 "WHERE " .
232 $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
233 break;
234 case "5.4.0":
235 $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, odes.description description, " .
236 " location, tutor_name, tutor_email, tutor_phone, details, reg_type registration, " .
237 " reg_limited limited_registration, reg_waiting_list waiting_list, reg_auto_wait auto_wait, " .
238 " reg_limit_users limit_users, reg_min_users min_users, " .
239 " e_start event_start, e_end event_end, starting_time, ending_time, fulltime, mail_members, show_members " .
240 " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
241 " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
242 " JOIN object_description odes ON (ev.obj_id = odes.obj_id) " .
243 "WHERE " .
244 $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
245
246 $this->readDidacticTemplateType($a_ids);
247 break;
248 case "7.0":
249 $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, odes.description description, " .
250 " location, tutor_name, tutor_email, tutor_phone, details, reg_type registration, " .
251 " reg_limited limited_registration, reg_waiting_list waiting_list, reg_auto_wait auto_wait, " .
252 " reg_limit_users limit_users, reg_min_users min_users, " .
253 " e_start event_start, e_end event_end, starting_time, ending_time, fulltime, mail_members, show_members, " .
254 " show_cannot_part, reg_notification registration_notification_enabled, " .
255 " notification_opt registration_notification_option " .
256 " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
257 " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
258 " JOIN object_description odes ON (ev.obj_id = odes.obj_id) " .
259 "WHERE " .
260 $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
261
262 $this->readDidacticTemplateType($a_ids);
263 break;
264 }
265 }
266
267 if ($a_entity == "sess_item") {
268 switch ($a_version) {
269 case "4.1.0":
270 case "5.0.0":
271 case "5.1.0":
272 case '5.4.0':
273 case '7.0':
274 $this->getDirectDataFromQuery($q = "SELECT event_id session_id, item_id " .
275 " FROM event_items " .
276 "WHERE " .
277 $ilDB->in("event_id", $a_ids, false, "integer"));
278 break;
279 }
280 }
281 }
282
283 public function getXmlRecord(string $a_entity, string $a_version, array $a_set): array
284 {
285 if ($a_entity == "sess") {
286 // convert server dates to utc
287 if (!$a_set["Fulltime"]) {
288 // nothing has to be done here, since the dates are already stored in UTC
289 #$start = new ilDateTime($a_set["EventStart"], IL_CAL_DATETIME);
290 #$a_set["EventStart"] = $start->get(IL_CAL_DATETIME,'','UTC');
291 #$end = new ilDateTime($a_set["EventEnd"], IL_CAL_DATETIME);
292 #$a_set["EventEnd"] = $end->get(IL_CAL_DATETIME,'','UTC');
293 }
294 }
295 if ($a_entity == "sess_item") {
296 // make ref id an object id
297 $a_set["ItemId"] = ilObject::_lookupObjId((int) ($a_set["ItemId"] ?? 0));
298 }
299 return $a_set;
300 }
301
302 protected function getDependencies(
303 string $a_entity,
304 string $a_version,
305 ?array $a_rec = null,
306 ?array $a_ids = null
307 ): array {
308 switch ($a_entity) {
309 case "sess":
310 return array(
311 "sess_item" => array("ids" => ($a_rec["Id"] ?? ''))
312 );
313 }
314
315 return [];
316 }
317
318 public function importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version): void
319 {
320 switch ($a_entity) {
321 case "sess":
322 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
323 $refs = ilObject::_getAllReferences((int) $new_id);
324 $newObj = ilObjectFactory::getInstanceByRefId(end($refs), false);
325 } else {
326 $this->logger->debug('Session creation without existing instance');
327 $newObj = new ilObjSession();
328 $newObj->setType("sess");
329 $newObj->create(true);
330 }
331 $newObj->setTitle((string) ($a_rec["Title"] ?? ''));
332 $newObj->setDescription((string) ($a_rec["Description"] ?? ''));
333 $newObj->setLocation((string) ($a_rec["Location"] ?? ''));
334 $newObj->setName((string) ($a_rec["TutorName"] ?? ''));
335 $newObj->setPhone((string) ($a_rec["TutorPhone"] ?? ''));
336 $newObj->setEmail((string) ($a_rec["TutorEmail"] ?? ''));
337 $newObj->setDetails((string) ($a_rec["Details"] ?? ''));
338
339 switch ($a_schema_version) {
340 case '5.4.0':
341 case '7.0':
342 if (isset($a_rec['MailMembers'])) {
343 $newObj->setMailToMembersType((int) $a_rec['MailMembers']);
344 }
345 if (isset($a_rec['ShowMembers'])) {
346 $newObj->setShowMembers((bool) $a_rec['ShowMembers']);
347 }
348 if (isset($a_rec['ShowCannotPart'])) {
349 $newObj->enableCannotParticipateOption((bool) $a_rec['ShowCannotPart']);
350 }
351 if (isset($a_rec['RegistrationNotificationEnabled'])) {
352 $newObj->setRegistrationNotificationEnabled((bool) $a_rec['RegistrationNotificationEnabled']);
353 }
354 if (isset($a_rec['RegistrationNotificationOption'])) {
355 $newObj->setRegistrationNotificationOption((string) $a_rec['RegistrationNotificationOption']);
356 }
357 $this->applyDidacticTemplate($newObj, (int) $a_rec['Type']);
358 // no break
359 case "5.0.0":
360 case "5.1.0":
361 $newObj->setRegistrationType((int) ($a_rec["Registration"] ?? 0));
362
363 $newObj->enableRegistrationUserLimit((int) ($a_rec["LimitedRegistration"] ?? 0));
364 $newObj->setRegistrationMaxUsers((int) ($a_rec["LimitUsers"] ?? 0));
365 $newObj->enableRegistrationWaitingList((bool) ($a_rec["WaitingList"] ?? false));
366
367 if (isset($a_rec["MinUsers"])) {
368 $newObj->setRegistrationMinUsers((int) ($a_rec["MinUsers"] ?? 0));
369 }
370
371 if (isset($a_rec["AutoWait"])) {
372 $newObj->setWaitingListAutoFill((bool) ($a_rec["AutoWait"] ?? false));
373 }
374 break;
375 case '5.4.0':
376 case '7.0':
377 if (isset($a_rec['MailMembers'])) {
378 $newObj->setMailToMembersType((int) ($a_rec['MailMembers'] ?? 0));
379 }
380 if (isset($a_rec['ShowMembers'])) {
381 $newObj->setShowMembers((bool) ($a_rec['ShowMembers'] ?? false));
382 }
383 if (isset($a_rec['ShowCannotPart'])) {
384 $newObj->enableCannotParticipateOption((bool) ($a_rec['show_cannot_part'] ?? false));
385 break;
386 }
387 $this->applyDidacticTemplate($newObj, (int) ($a_rec['Type'] ?? 0));
388 break;
389 }
390
391 $newObj->update(true);
392
393 $start = new ilDateTime($a_rec["EventStart"], IL_CAL_DATETIME, "UTC");
394 $end = new ilDateTime($a_rec["EventEnd"], IL_CAL_DATETIME, "UTC");
396 $app->setStart($start);
397 $app->setEnd($end);
398 $app->setStartingTime($start->get(IL_CAL_UNIX));
399 $app->setEndingTime($end->get(IL_CAL_UNIX));
400 $app->toggleFullTime((bool) ($a_rec["Fulltime"] ?? false));
401 $app->setSessionId($newObj->getId());
402 $app->create();
403
404 $this->current_obj = $newObj;
405 $a_mapping->addMapping("Modules/Session", "sess", $a_rec["Id"], (string) $newObj->getId());
406 $a_mapping->addMapping('Services/Object', 'objs', $a_rec['Id'], (string) $newObj->getId());
407 $a_mapping->addMapping('Services/AdvancedMetaData', 'parent', $a_rec['Id'], (string) $newObj->getId());
408 $a_mapping->addMapping(
409 "Services/MetaData",
410 "md",
411 $a_rec["Id"] . ":0:sess",
412 $newObj->getId() . ":0:sess"
413 );
414 break;
415
416 case "sess_item":
417 if ($obj_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['ItemId'])) {
418 $ref_id = current(ilObject::_getAllReferences((int) $obj_id));
419 $evi = new ilEventItems($this->current_obj->getId());
420 $evi->addItem($ref_id);
421 $evi->update();
422 }
423 break;
424 }
425 }
426
430 protected function readDidacticTemplateType(array $a_obj_ids): void
431 {
432 $ref_ids = [];
433 $counter = 0;
434 foreach ($a_obj_ids as $obj_id) {
435 $ref_ids = ilObject::_getAllReferences((int) $obj_id);
436 foreach ($ref_ids as $ref_id) {
438 $this->data[$counter++]['Type'] = $tpl_id;
439 break;
440 }
441 }
442 }
443
444 protected function applyDidacticTemplate(ilObject $rep_object, int $tpl_id): void
445 {
446 $this->logger->debug('Apply didactic template');
447
448 if ($tpl_id == 0) {
449 $this->logger->debug('Default permissions');
450 // Default template
451 return;
452 }
453
454 $templates = ilDidacticTemplateSettings::getInstanceByObjectType('sess')->getTemplates();
455 foreach ($templates as $template) {
456 if ($template->isAutoGenerated()) {
457 $this->logger->debug('Apply first auto generated');
458 $rep_object->applyDidacticTemplate($template->getId());
459 }
460 }
461 }
462}
const IL_CAL_UNIX
const IL_CAL_DATETIME
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 ...
ilDBInterface $db
@classDescription Date and time handling
static getInstanceByObjectType(string $a_obj_type)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
Component logger with individual log levels by component id.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getAllReferences(int $id)
get all reference ids for object ID
applyDidacticTemplate(int $tpl_id)
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Session data set class.
readData(string $a_entity, string $a_version, array $a_ids)
Read data from DB.
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
getXmlRecord(string $a_entity, string $a_version, array $a_set)
Get xml record for version.
readDidacticTemplateType(array $a_obj_ids)
getXmlNamespace(string $a_entity, string $a_schema_version)
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
Needs to be overwritten for import use case.
setTargetId(string $target_id)
applyDidacticTemplate(ilObject $rep_object, int $tpl_id)
getTypes(string $a_entity, string $a_version)
Get (abstract) types for (abstract) field names.
$app
Definition: cli.php:39
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc