ILIAS  release_8 Revision v8.24
class.ilDataCollectionDataSet.php
Go to the documentation of this file.
1<?php
2
20{
25 protected array $record_field_ids_2_storage = [];
42 protected array $caches
43 = [
44 'dcl' => [],
45 'il_dcl_table' => [],
46 'il_dcl_field' => [],
47 'il_dcl_field_prop' => [],
48 'il_dcl_sel_opts' => [],
49 'il_dcl_record' => [],
50 'il_dcl_record_field' => [],
51 'il_dcl_stloc1_value' => [],
52 'il_dcl_stloc2_value' => [],
53 'il_dcl_stloc3_value' => [],
54 'il_dcl_stloc1_default' => [],
55 'il_dcl_stloc2_default' => [],
56 'il_dcl_stloc3_default' => [],
57 'il_dcl_tfield_set' => [],
58 'il_dcl_tableview' => [],
59 'il_dcl_tview_set' => [],
60 ];
61
63
67 protected array $import_record_field_cache = [];
68 protected ilObjUser $user;
69 protected array $import_temp_refs = [];
70 protected array $import_temp_refs_props = [];
71 protected array $import_temp_new_mob_ids = [];
72
73 public function __construct()
74 {
75 global $DIC;
77 $this->db = $DIC->database();
78 $this->user = $DIC->user();
79 }
80
81 public function getSupportedVersions(): array
82 {
83 return ['4.5.0', '8.13'];
84 }
85
90 public function getCache(string $a_entity): array
91 {
92 if (!in_array($a_entity, array_keys($this->caches))) {
93 throw new ilException("Entity '$a_entity' does not exist in Cache");
94 }
95
96 return $this->caches[$a_entity];
97 }
98
99 protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
100 {
101 return 'https://www.ilias.de/xml/Modules/DataCollection/' . $a_entity;
102 }
103
104 public function importRecord(
105 string $a_entity,
106 array $a_types,
107 array $a_rec,
108 ilImportMapping $a_mapping,
109 string $a_schema_version
110 ): void {
111 foreach ($a_rec as $key => &$value) {
112 $array = json_decode($value, true);
113 if ($key === 'title' || $key === 'description') {
114 $value = strip_tags($value, ilObjectGUI::ALLOWED_TAGS_IN_TITLE_AND_DESCRIPTION);
115 } elseif (is_array($array)) {
116 $value = json_encode($this->escapeArray($array));
117 } else {
118 $value = htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'utf-8');
119 }
120 }
121 switch ($a_entity) {
122 case 'dcl':
123 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['id'])) {
124 $new_obj = ilObjectFactory::getInstanceByObjId($new_id, false);
125 } else {
126 $new_obj = new ilObjDataCollection();
127 $new_obj->create(true);
128 }
129 $new_obj->setTitle($a_rec['title']);
130 $new_obj->setDescription($a_rec['description']);
131 $new_obj->setApproval($a_rec['approval']);
132 $new_obj->setPublicNotes($a_rec['public_notes']);
133 $new_obj->setNotification($a_rec['notification']);
134 $new_obj->setPublicNotes($a_rec['public_notes']);
135 $new_obj->setOnline(false);
136 $new_obj->setRating($a_rec['rating']);
137 $new_obj->update(); //clone mode, so no table will be created
138 $this->import_dc_object = $new_obj;
139 $a_mapping->addMapping('Modules/DataCollection', 'dcl', $a_rec['id'], $new_obj->getId());
140 break;
141 case 'il_dcl_table':
142 $table = new ilDclTable();
143 $table->setTitle($a_rec['title']);
144 $table->setObjId($this->import_dc_object->getId());
145 $table->setDescription($a_rec['description']);
146 $table->setAddPerm($a_rec['add_perm']);
147 $table->setEditPerm($a_rec['edit_perm']);
148 $table->setDeletePerm($a_rec['delete_perm']);
149 $table->setEditByOwner($a_rec['edit_by_owner']);
150 $table->setLimited($a_rec['limited']);
151 $table->setLimitStart($a_rec['limit_start']);
152 $table->setLimitEnd($a_rec['limit_end']);
153 $table->setIsVisible($a_rec['is_visible']);
154 $table->setExportEnabled($a_rec['export_enabled']);
155 $table->setImportEnabled($a_rec['import_enabled']);
156 $table->setDefaultSortField($a_rec['default_sort_field_id']);
157 $table->setDefaultSortFieldOrder($a_rec['default_sort_field_order']);
158 $table->setPublicCommentsEnabled($a_rec['public_comments']);
159 $table->setViewOwnRecordsPerm($a_rec['view_own_records_perm']);
160 $table->setDeleteByOwner($a_rec['delete_by_owner']);
161 $table->setSaveConfirmation($a_rec['save_confirmation']);
162 $table->setOrder($a_rec['table_order']);
163 $table->doCreate(false, false); // false => Do not create views! They are imported later
164 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['id'], $table->getId());
165 break;
166 case 'il_dcl_tableview':
167 $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
168 if ($new_table_id) {
169 $tableview = new ilDclTableView();
170 $tableview->setTitle($a_rec['title']);
171 $tableview->setTableId($new_table_id);
172 $tableview->setDescription($a_rec['description']);
173 $tableview->setTableviewOrder($a_rec['tableview_order']);
174 if (!is_array($a_rec['roles'])) {
175 $a_rec['roles'] = json_decode($a_rec['roles']);
176 }
177 $tableview->setRoles($a_rec['roles']);
178
179 $step_is_null = !array_key_exists('step_vs', $a_rec) || is_null($a_rec['step_vs']);
180 $step_is_null ? $tableview->setStepVs(1) : $tableview->setStepVs($a_rec['step_vs']);
181
182 $step_is_null = !array_key_exists('step_c', $a_rec) || is_null($a_rec['step_c']);
183 $step_is_null ? $tableview->setStepC(0) : $tableview->setStepC($a_rec['step_c']);
184
185 $step_is_null = !array_key_exists('step_e', $a_rec) || is_null($a_rec['step_e']);
186 $step_is_null ? $tableview->setStepE(0) : $tableview->setStepE($a_rec['step_e']);
187
188 $step_is_null = !array_key_exists('step_o', $a_rec) || is_null($a_rec['step_o']);
189 $step_is_null ? $tableview->setStepO(0) : $tableview->setStepO($a_rec['step_o']);
190
191 $step_is_null = !array_key_exists('step_s', $a_rec) || is_null($a_rec['step_s']);
192 $step_is_null ? $tableview->setStepS(0) : $tableview->setStepS($a_rec['step_s']);
193
194 $tableview->create(false); //do not create default setting as they are imported too
195 }
196 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_tableview', $a_rec['id'], $tableview->getId());
197 $a_mapping->addMapping('Services/COPage', 'pg', 'dclf:' . $a_rec['id'], 'dclf:' . $tableview->getId());
198 break;
199 case 'il_dcl_field':
200 $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
201 if ($new_table_id) {
202 $datatype_id = $a_rec['datatype_id'];
203 $datatype = $a_rec['datatype_title'] ?? null;
204 $datatypes = ilDclDatatype::getAllDatatype();
205 if ($datatype !== null && ilDclFieldTypePlugin::isPluginDatatype($datatype)) {
206 $datatype_id = null;
207 foreach ($datatypes as $dt) {
208 if ($dt->getTitle() === $datatype) {
209 $datatype_id = $dt->getId();
210 }
211 }
212 }
213 if (in_array($datatype_id, array_keys($datatypes))) {
214 $field = new ilDclBaseFieldModel();
215 $field->setTableId($new_table_id);
216 $field->setDatatypeId($datatype_id);
217 $field->setTitle($a_rec['title']);
218 $field->setDescription($a_rec['description']);
219 $field->setUnique($a_rec['is_unique']);
220 $field->doCreate();
221 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['id'], $field->getId());
222 // Check if this field was used as default order by, if so, update to new id
223 $table = ilDclCache::getTableCache($new_table_id);
224 if ($table && $table->getDefaultSortField() == $a_rec['id']) {
225 $table->setDefaultSortField($field->getId());
226 $table->doUpdate();
227 }
228 }
229 }
230 break;
231 case 'il_dcl_tfield_set':
232 $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
233 $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field']);
234 if ($new_table_id && $new_field_id) {
236 $new_table_id,
237 $new_field_id
238 );
239 $setting->setFieldOrder($a_rec['field_order']);
240 $setting->setExportable($a_rec['exportable']);
241 $setting->store();
242 }
243 break;
244 case 'il_dcl_tview_set':
245 $new_tableview_id = $a_mapping->getMapping(
246 'Modules/DataCollection',
247 'il_dcl_tableview',
248 $a_rec['tableview_id']
249 );
250 $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field']);
251 if ($new_tableview_id) {
252 $setting = new ilDclTableViewFieldSetting();
253 $setting->setTableviewId($new_tableview_id);
254 $setting->setVisible($a_rec['visible']);
255 $setting->setField($new_field_id ?: $a_rec['field']);
256 $setting->setInFilter($a_rec['in_filter']);
257 $setting->setFilterValue($a_rec['filter_value'] ?: null);
258 $setting->setFilterChangeable($a_rec['filter_changeable']);
259 $setting->setRequiredCreate($a_rec['required_create'] ?? 0);
260 $setting->setLockedCreate($a_rec['locked_create'] ?? 0);
261 $setting->setVisibleCreate($a_rec['visible_create'] ?? 1);
262 $setting->setVisibleEdit($a_rec['visible_edit'] ?? 1);
263 $setting->setRequiredEdit($a_rec['required_edit'] ?? 0);
264 $setting->setLockedEdit($a_rec['locked_edit'] ?? 0);
265 $setting->setDefaultValue($a_rec['default_value'] ?? null);
266 $setting->create();
267 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_tview_set', $a_rec['id'], $setting->getId());
268 }
269 break;
270 case 'il_dcl_record':
271 $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
272 if ($new_table_id) {
273 $record = new ilDclBaseRecordModel();
274 $record->setTableId($new_table_id);
275 $datetime = new ilDateTime(time(), IL_CAL_UNIX);
276 $record->setCreateDate($datetime);
277 $record->setLastUpdate($datetime);
278 $record->setOwner($this->user->getId());
279 $record->setLastEditBy($this->user->getId());
280 $record->doCreate();
281 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['id'], $record->getId());
282 }
283 break;
284 case 'il_dcl_view':
285 $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
286 if ($new_table_id) {
287 //if import contains il_dcl_view, it must origin from an earlier ILIAS Version and therefore contains no tableviews
288 //->create standard view
289 $tableview = ilDclTableView::createOrGetStandardView($new_table_id);
290 if ($a_rec['type'] == 0 && $a_rec['formtype'] == 0) { //set page_object to tableview
291 // This mapping is needed for the import handled by Services/COPage
292 $a_mapping->addMapping(
293 'Services/COPage',
294 'pg',
295 'dclf:' . $a_rec['id'],
296 'dclf:' . $tableview->getId()
297 );
298 $a_mapping->addMapping(
299 'Modules/DataCollection',
300 'il_dcl_view',
301 $a_rec['id'],
302 $tableview->getId()
303 );
304 } else {
305 $a_mapping->addMapping(
306 'Modules/DataCollection',
307 'il_dcl_view',
308 $a_rec['id'],
309 json_encode(['type' => $a_rec['type'],
310 'table_id' => $new_table_id,
311 'tableview_id' => $tableview->getId()
312 ])
313 );
314 }
315 }
316 break;
317 case 'il_dcl_viewdefinition':
318 $map = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['view_id']);
319 $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field']);
320 $field = ($new_field_id) ?: $a_rec['field'];
321 switch ($map['type']) {
322 case 1: //visible
323 $viewfield_setting = ilDclTableViewFieldSetting::getInstance($map['tableview_id'], $field);
324 $viewfield_setting->setVisible($a_rec['is_set']);
325 $viewfield_setting->store();
326 break;
327 case 3: //in_filter
328 $viewfield_setting = ilDclTableViewFieldSetting::getInstance($map['tableview_id'], $field);
329 $viewfield_setting->setInFilter($a_rec['is_set']);
330 $viewfield_setting->store();
331 break;
332 case 4: //exportable
333 $tablefield_setting = ilDclTableFieldSetting::getInstance($map['table_id'], $field);
334 $tablefield_setting->setExportable($a_rec['is_set']);
335 $tablefield_setting->setFieldOrder($a_rec['field_order']);
336 $tablefield_setting->store();
337 break;
338 }
339 break;
340 case 'il_dcl_sel_opts':
341 $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
342 if ($new_field_id) {
343 $opt = new ilDclSelectionOption();
344 $opt->setFieldId($new_field_id);
345 $opt->setOptId($a_rec['opt_id']);
346 $opt->setSorting($a_rec['sorting']);
347 $opt->setValue($a_rec['value']);
348 $opt->store();
349 }
350 break;
351 case 'il_dcl_field_prop':
352 $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
353 if ($new_field_id) {
354 $prop = new ilDclFieldProperty();
355 $prop->setFieldId($new_field_id);
356
357 // OLD IMPORT! Backwards-compatibility
358 $name = $a_rec['name'];
359 if (!isset($name) && isset($a_rec['datatype_prop_id'])) {
360 $properties = [
361 1 => 'length',
362 2 => 'regex',
363 3 => 'table_id',
364 4 => 'url',
365 5 => 'text_area',
366 6 => 'reference_link',
367 7 => 'width',
368 8 => 'height',
369 9 => 'learning_progress',
370 10 => 'ILIAS_reference_link',
371 11 => 'multiple_selection',
372 12 => 'expression',
373 13 => 'display_action_menu',
374 14 => 'link_detail_page',
375 15 => 'link_detail_page',
376 ];
377
378 $name = $properties[$a_rec['datatype_prop_id']];
379 }
380
381 $prop->setName($name);
382 $prop->setValue($a_rec['value']);
383 $prop->save();
384 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_field_prop', $a_rec['id'], $prop->getId());
385 $this->import_temp_refs_props[$prop->getId()] = $a_rec['value'];
386 }
387 break;
388 case 'il_dcl_record_field':
389 $record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['record_id']);
390 $field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
391 if ($record_id && $field_id) {
392 $record = ilDclCache::getRecordCache($record_id);
393 $field = ilDclCache::getFieldCache($field_id);
394 $record_field = new ilDclBaseRecordFieldModel($record, $field);
395 $a_mapping->addMapping(
396 'Modules/DataCollection',
397 'il_dcl_record_field',
398 $a_rec['id'],
399 $record_field->getId()
400 );
401 $this->import_record_field_cache[$record_field->getId()] = $record_field;
402 }
403 break;
404 case 'il_dcl_stloc1_value':
405 case 'il_dcl_stloc2_value':
406 case 'il_dcl_stloc3_value':
407 $new_record_field_id = $a_mapping->getMapping(
408 'Modules/DataCollection',
409 'il_dcl_record_field',
410 $a_rec['record_field_id']
411 );
412 if ($new_record_field_id) {
414 $record_field = $this->import_record_field_cache[$new_record_field_id];
415 if (is_object($record_field)) {
416 // Need to rewrite internal references and lookup new objects if MOB or File
417 // For some fieldtypes it's better to reset the value, e.g. ILIAS_REF
418 switch ($record_field->getField()->getDatatypeId()) {
420 // Check if we got a mapping from old object
421 $new_mob_id = $a_mapping->getMapping('Services/MediaObjects', 'mob', $a_rec['value']);
422 $value = ($new_mob_id) ? (int) $new_mob_id : null;
423 $this->import_temp_new_mob_ids[] = $new_mob_id;
424 break;
426 $new_file_id = $a_mapping->getMapping('Modules/File', 'file', $a_rec['value']);
427 $value = ($new_file_id) ? (int) $new_file_id : null;
428 break;
431 $value = $a_rec['value'];
432 $decode = json_decode($a_rec['value']);
433 if (is_array($decode)) {
434 foreach ($decode as $id) {
435 $this->import_temp_refs[$new_record_field_id][] = $id;
436 }
437 } else {
438 $this->import_temp_refs[$new_record_field_id] = $value;
439 }
440 break;
442 $value = null;
443 break;
445 $value = $a_rec['value'];
446 if ($value == '0000-00-00 00:00:00') {
447 $value = null;
448 }
449 break;
451 if (version_compare($a_schema_version, "8.13") < 0) {
452 $a_rec['value'] = str_replace('&lt;br /&gt;', '', $a_rec['value']);
453 }
454 // no break
455 default:
456 $value = $a_rec['value'];
457 if ($a_entity == 'il_dcl_stloc3_value' && empty($value)) {
458 $value = null;
459 }
460 }
461 $record_field->setValue($value, true);
462 $record_field->doUpdate();
463 }
464 }
465 break;
466 case 'il_dcl_stloc1_default':
467 case 'il_dcl_stloc2_default':
468 case 'il_dcl_stloc3_default':
469
470 $tview_set_id = $a_mapping->getMapping(
471 'Modules/DataCollection',
472 'il_dcl_tview_set',
473 $a_rec['tview_set_id']
474 );
475
476 if ($tview_set_id) {
477 $value = $a_rec['value'];
478 if ($value) {
479 $stloc_default = (new ilDclDefaultValueFactory())->createByTableName($a_entity);
481 $value = (int) $value;
482 }
483 $stloc_default->setValue($value);
484 $stloc_default->setTviewSetId($tview_set_id);
485 $stloc_default->create();
486 }
487 }
488 break;
489 }
490 }
491
492 protected function escapeArray(array $array): array
493 {
494 $new = [];
495 foreach ($array as $key => $value) {
496 $newkey = $key;
497 if (is_string($key)) {
498 $newkey = htmlspecialchars($key, ENT_QUOTES | ENT_SUBSTITUTE, 'utf-8');
499 }
500 $newvalue = $value;
501 if (is_string($value)) {
502 $newvalue = htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'utf-8');
503 }
504 if (is_array($value)) {
505 $newvalue = $this->escapeArray($value);
506 }
507 $new[$newkey] = $newvalue;
508 }
509 return $new;
510 }
511
516 public function beforeFinishImport(ilImportMapping $a_mapping): void
517 {
518 foreach ($this->import_temp_new_mob_ids as $new_mob_id) {
519 if ($new_mob_id) {
520 ilObjMediaObject::_saveUsage($new_mob_id, "dcl:html", $a_mapping->getTargetId());
521 }
522 }
523 foreach ($this->import_temp_refs as $record_field_id => $old_record_id) {
524 if (is_array($old_record_id)) {
525 $new_record_id = [];
526 foreach ($old_record_id as $id) {
527 $new_record_id[] = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $id);
528 }
529 $value = $new_record_id;
530 } else {
531 $value = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $old_record_id);
532 }
534 $record_field = $this->import_record_field_cache[$record_field_id];
535 $record_field->setValue($value, true);
536 $record_field->doUpdate();
537 }
538 foreach ($this->import_temp_refs_props as $field_prop_id => $prop_value) {
539 $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $prop_value);
540 $value = ($new_field_id) ? (int) $new_field_id : $prop_value;
541
542 $field_prop = new ilDclFieldProperty($field_prop_id);
543 $field_prop->setValue($value);
544 $field_prop->update();
545 }
546 }
547
551 protected function getTypes(string $a_entity, string $a_version): array
552 {
553 switch ($a_entity) {
554 case 'dcl':
555 return [
556 "id" => "integer",
557 "title" => "text",
558 "description" => "text",
559 'is_online' => 'integer',
560 'rating' => 'integer',
561 'public_notes' => 'integer',
562 'approval' => 'integer',
563 'notification' => 'integer',
564 ];
565 case 'il_dcl_table':
566 return [
567 'id' => 'integer',
568 'obj_id' => 'integer',
569 'title' => 'text',
570 'add_perm' => 'integer',
571 'edit_perm' => 'integer',
572 'delete_perm' => 'integer',
573 'edit_by_owner' => 'integer',
574 'limited' => 'integer',
575 'limit_start' => 'text',
576 'limit_end' => 'text',
577 'is_visible' => 'integer',
578 'export_enabled' => 'integer',
579 'import_enabled' => 'integer',
580 'default_sort_field_id' => 'text',
581 'default_sort_field_order' => 'text',
582 'description' => 'text',
583 'public_comments' => 'integer',
584 'view_own_records_perm' => 'integer',
585 'delete_by_owner' => 'integer',
586 'save_confirmation' => 'integer',
587 'table_order' => 'integer',
588 ];
589 case 'il_dcl_tableview':
590 return [
591 'id' => 'integer',
592 'table_id' => 'integer',
593 'title' => 'text',
594 'roles' => 'text',
595 'step_vs' => 'integer',
596 'step_c' => 'integer',
597 'step_e' => 'integer',
598 'step_o' => 'integer',
599 'step_s' => 'integer',
600 'description' => 'text',
601 'tableview_order' => 'integer',
602 ];
603 case 'il_dcl_field':
604 return [
605 'id' => 'integer',
606 'table_id' => 'integer',
607 'title' => 'text',
608 'description' => 'text',
609 'datatype_id' => 'integer',
610 'datatype_title' => 'text',
611 'is_unique' => 'integer',
612 ];
613 case 'il_dcl_tview_set':
614 return [
615 'id' => 'integer',
616 'tableview_id' => 'integer',
617 'field' => 'text',
618 'visible' => 'integer',
619 'in_filter' => 'integer',
620 'filter_value' => 'text',
621 'filter_changeable' => 'integer',
622 'required_create' => 'integer',
623 'required_edit' => 'integer',
624 'locked_create' => 'integer',
625 'locked_edit' => 'integer',
626 'visible_create' => 'integer',
627 'visible_edit' => 'integer',
628 'default_value' => 'text',
629 ];
630 case 'il_dcl_tfield_set':
631 return [
632 'id' => 'integer',
633 'table_id' => 'integer',
634 'field' => 'text',
635 'field_order' => 'integer',
636 'exportable' => 'integer',
637 ];
638 case 'il_dcl_field_prop':
639 return [
640 'id' => 'integer',
641 'field_id' => 'integer',
642 'name' => 'text',
643 'value' => 'integer',
644 ];
645 case 'il_dcl_sel_opts':
646 return [
647 'id' => 'integer',
648 'field_id' => 'integer',
649 'opt_id' => 'integer',
650 'sorting' => 'integer',
651 'value' => 'text',
652 ];
653 case 'il_dcl_record':
654 return [
655 'id' => 'integer',
656 'table_id' => 'integer',
657 ];
658 case 'il_dcl_record_field':
659 return [
660 'id' => 'integer',
661 'record_id' => 'integer',
662 'field_id' => 'integer',
663 ];
664 case 'il_dcl_stloc1_value':
665 case 'il_dcl_stloc2_value':
666 case 'il_dcl_stloc3_value':
667 return [
668 'id' => 'integer',
669 'record_field_id' => 'integer',
670 'value' => 'text',
671 ];
672 case 'il_dcl_stloc1_default':
673 case 'il_dcl_stloc2_default':
674 case 'il_dcl_stloc3_default':
675 return [
676 'id' => 'integer',
677 'tview_set_id' => 'integer',
678 'value' => 'text',
679 ];
680 default:
681 return [];
682 }
683 }
684
693 protected function getDependencies(
694 string $a_entity,
695 string $a_version,
696 ?array $a_rec = null,
697 ?array $a_ids = null
698 ): array {
699 if (!$a_rec && !$a_ids) {
700 return [];
701 }
702 switch ($a_entity) {
703 case 'dcl':
704 $set = $this->db->query('SELECT * FROM il_dcl_table WHERE obj_id = ' . $this->db->quote(
705 $a_rec['id'],
706 'integer'
707 ) . ' ORDER BY id');
708 $ids = $this->buildCache('il_dcl_table', $set);
709
710 return [
711 'il_dcl_table' => ['ids' => $ids],
712 ];
713 case 'il_dcl_table':
714 $set = $this->db->query('SELECT * FROM il_dcl_record WHERE table_id = ' . $this->db->quote(
715 $a_rec['id'],
716 'integer'
717 ));
718 $ids_records = $this->buildCache('il_dcl_record', $set);
719 $set = $this->db->query('SELECT il_dcl_field.*, il_dcl_datatype.title as datatype_title FROM il_dcl_field INNER JOIN il_dcl_datatype ON il_dcl_field.datatype_id = il_dcl_datatype.id WHERE table_id = ' . $this->db->quote(
720 $a_rec['id'],
721 'integer'
722 ));
723 $ids_fields = $this->buildCache('il_dcl_field', $set);
724 $set = $this->db->query('SELECT * FROM il_dcl_tableview WHERE table_id = ' . $this->db->quote(
725 $a_rec['id'],
726 'integer'
727 ));
728 $ids_tableviews = $this->buildCache('il_dcl_tableview', $set);
729 $set = $this->db->query('SELECT * FROM il_dcl_tfield_set WHERE table_id = ' . $this->db->quote(
730 $a_rec['id'],
731 'integer'
732 ));
733 $ids_tablefield_settings = $this->buildCache('il_dcl_tfield_set', $set);
734
735 return [
736 'il_dcl_field' => ['ids' => $ids_fields],
737 'il_dcl_record' => ['ids' => $ids_records],
738 'il_dcl_tableview' => ['ids' => $ids_tableviews],
739 'il_dcl_tfield_set' => ['ids' => $ids_tablefield_settings],
740 ];
741 case 'il_dcl_field':
742 $set = $this->db->query('SELECT * FROM il_dcl_field_prop WHERE field_id = ' . $this->db->quote(
743 $a_rec['id'],
744 'integer'
745 ));
746 $prop_ids = $this->buildCache('il_dcl_field_prop', $set);
747
748 $set = $this->db->query('SELECT * FROM il_dcl_sel_opts WHERE field_id = ' . $this->db->quote(
749 $a_rec['id'],
750 'integer'
751 ));
752 $opt_ids = $this->buildCache('il_dcl_sel_opts', $set);
753
754 return [
755 'il_dcl_field_prop' => ['ids' => $prop_ids],
756 'il_dcl_sel_opts' => ['ids' => $opt_ids],
757 ];
758 case 'il_dcl_record':
759 $sql = 'SELECT rf.*, d.storage_location FROM il_dcl_record_field AS rf' . ' INNER JOIN il_dcl_field AS f ON (f.id = rf.field_id)'
760 . ' INNER JOIN il_dcl_datatype AS d ON (f.datatype_id = d.id) ' . ' WHERE rf.record_id = '
761 . $this->db->quote($a_rec['id'], 'integer');
762 $set = $this->db->query($sql);
763 $ids = $this->buildCache('il_dcl_record_field', $set);
764
765 $set = $this->db->query($sql);
766 while ($rec = $this->db->fetchObject($set)) {
767 $this->record_field_ids_2_storage[$rec->id] = ilDclCache::getFieldCache($rec->field_id)->getStorageLocation();
768 }
769 // Also build a cache of all values, no matter in which table they are (il_dcl_stloc(1|2|3)_value)
770 $sql
771 = 'SELECT rf.id AS record_field_id, st1.value AS value1, st2.value AS value2, st3.value AS value3 FROM il_dcl_record_field AS rf '
772 . 'LEFT JOIN il_dcl_stloc1_value AS st1 ON (st1.record_field_id = rf.id) '
773 . 'LEFT JOIN il_dcl_stloc2_value AS st2 ON (st2.record_field_id = rf.id) '
774 . 'LEFT JOIN il_dcl_stloc3_value AS st3 ON (st3.record_field_id = rf.id) ' . 'WHERE rf.record_id = '
775 . $this->db->quote($a_rec['id'], 'integer');
776 $set = $this->db->query($sql);
777
778 while ($rec = $this->db->fetchObject($set)) {
779 $stloc = $this->record_field_ids_2_storage[$rec->record_field_id];
780 $value = null;
781 if ($stloc != 0) {
782 $value = "value{$stloc}";
783 $value = $rec->{$value};
784 }
785 // Save reocrd field id. Internal ID is not used currently
786 $this->caches["il_dcl_stloc{$stloc}_value"][$rec->record_field_id] = [
787 'record_field_id' => $rec->record_field_id,
788 'value' => $value,
789 ];
790 }
791
792 return [
793 'il_dcl_record_field' => ['ids' => $ids],
794 ];
795 case 'il_dcl_tableview':
796 $set = $this->db->query('SELECT * FROM il_dcl_tview_set WHERE tableview_id = ' . $this->db->quote(
797 $a_rec['id'],
798 'integer'
799 ));
800 $ids = $this->buildCache('il_dcl_tview_set', $set);
801
802 return [
803 'il_dcl_tview_set' => ['ids' => $ids],
804 ];
805 case 'il_dcl_tview_set':
806 if (!(int) $a_rec['field'] > 0) {
807 break;
808 }
809 // Also build a cache of all values, no matter in which table they are (il_dcl_stloc(1|2|3)_value)
810 $sql
811 = '
812 SELECT tview_set.id AS tview_set_id, st1.value AS value1, st2.value AS value2, st3.value AS value3,
813 st1.id AS id1, st2.id AS id2, st3.id AS id3
814 FROM il_dcl_tview_set AS tview_set
815 LEFT JOIN il_dcl_stloc1_default AS st1 ON (st1.tview_set_id = tview_set.id)
816 LEFT JOIN il_dcl_stloc2_default AS st2 ON (st2.tview_set_id = tview_set.id)
817 LEFT JOIN il_dcl_stloc3_default AS st3 ON (st3.tview_set_id = tview_set.id)
818 WHERE tview_set.id = ' . $this->db->quote($a_rec['id'], 'integer');
819 $set = $this->db->query($sql);
820
821 while ($rec = $this->db->fetchObject($set)) {
822 $stloc = ilDclCache::getFieldCache($a_rec['field'])->getStorageLocation();
823 if ($stloc != 0) {
824 $value_str = "value{$stloc}";
825 $value = $rec->{$value_str};
826 $id_str = "id{$stloc}";
827 $id = $rec->{$id_str};
828 $tview_set_id = $rec->tview_set_id;
829
830 // Save reocrd field id. Internal ID is not used currently
831 $this->caches["il_dcl_stloc{$stloc}_default"][$rec->tview_set_id] = [
832 'id' => $id,
833 'tview_set_id' => $rec->tview_set_id,
834 'value' => $value,
835 ];
836
837 return [
838 "il_dcl_stloc{$stloc}_default" => ['ids' => [$tview_set_id]],
839 ];
840 }
841 }
842 break;
843 case 'il_dcl_record_field':
844 $record_field_id = $a_rec['id'];
845 $storage_loc = $this->record_field_ids_2_storage[$record_field_id];
846
847 return [
848 "il_dcl_stloc{$storage_loc}_value" => ['ids' => [$record_field_id]],
849 ];
850 }
851
852 return [];
853 }
854
859 public function readData(string $a_entity, string $a_version, array $a_ids): void
860 {
861 $this->data = [];
862 $this->_readData($a_entity, $a_ids);
863 }
864
870 protected function _readData(string $a_entity, array $a_ids): void
871 {
872 switch ($a_entity) {
873 case 'dcl':
874 foreach ($a_ids as $dcl_id) {
875 if (ilObject::_lookupType($dcl_id) === 'dcl') {
876 $obj = new ilObjDataCollection((int) $dcl_id, false);
877 $data = [
878 'id' => $dcl_id,
879 'title' => $obj->getTitle(),
880 'description' => $obj->getDescription(),
881 'is_online' => $obj->getOnline(),
882 'rating' => $obj->getRating(),
883 'public_notes' => $obj->getPublicNotes(),
884 'approval' => $obj->getApproval(),
885 'notification' => $obj->getNotification(),
886 ];
887 $this->caches['dcl'][$dcl_id] = $data;
888 $this->data[] = $data;
889 }
890 }
891 break;
892 default:
893 $data = $this->getCache($a_entity);
894 foreach ($a_ids as $id) {
895 $this->data[] = $data[$id];
896 }
897 }
898 }
899
907 protected function buildCache(string $a_entity, object $set): array
908 {
909 $fields = array_keys($this->getTypes($a_entity, ''));
910 $ids = [];
911 while ($rec = $this->db->fetchObject($set)) {
912 $data = [];
913 foreach ($fields as $field) {
914 $data[$field] = $rec->{$field};
915 }
916 $id = $rec->id;
917 $this->caches[$a_entity][$id] = $data;
918 $ids[] = $id;
919 }
920
921 return $ids;
922 }
923}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getXmlNamespace(string $a_entity, string $a_schema_version)
_readData(string $a_entity, array $a_ids)
Build data array, data is read from cache except dcl object itself.
buildCache(string $a_entity, object $set)
Helper method to build cache for data of all entities.
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
Return dependencies form entities to other entities (in our case these are all the DB relations)
readData(string $a_entity, string $a_version, array $a_ids)
Read data from Cache for a given entity and ID(s)
array $import_record_field_cache
Caches ilDclBaseRecordFieldModel objects.
getCache(string $a_entity)
Get cached data from a given entity.
getTypes(string $a_entity, string $a_version)
Map XML attributes of entities to datatypes (text, integer...)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
@classDescription Date and time handling
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...
static getRecordCache(?int $record_id)
static getFieldCache(int $field_id=0)
static getTableCache(int $table_id=null)
static getAllDatatype(bool $force=false)
Get all possible Datatypes.
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...
static isPluginDatatype(string $datatype)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(int $table_id, string $field)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(int $tableview_id, int $field_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static createOrGetStandardView(int $table_id, bool $create_default_settings=true)
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...
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.
User class.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
const ALLOWED_TAGS_IN_TITLE_AND_DESCRIPTION
static _lookupType(int $id, bool $reference=false)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193