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