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