ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDataCollectionDataSet.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
12
16 protected $db;
20 protected $data = array();
26 protected $record_field_ids_2_storage = array();
46 protected $caches
47 = array(
48 'dcl' => array(),
49 'il_dcl_table' => array(),
50 'il_dcl_field' => array(),
51 'il_dcl_field_prop' => array(),
52 'il_dcl_sel_opts' => array(),
53 'il_dcl_record' => array(),
54 'il_dcl_record_field' => array(),
55 'il_dcl_stloc1_value' => array(),
56 'il_dcl_stloc2_value' => array(),
57 'il_dcl_stloc3_value' => array(),
58 'il_dcl_tfield_set' => array(),
59 'il_dcl_tableview' => array(),
60 'il_dcl_tview_set' => array(),
61 );
75 protected $import_record_field_cache = array();
79 protected $user;
83 protected $import_temp_refs = array();
87 protected $import_temp_refs_props = array();
91 protected $import_temp_new_mob_ids = array();
92
93
94 public function __construct()
95 {
96 global $DIC;
97 $ilDB = $DIC['ilDB'];
98 $ilUser = $DIC['ilUser'];
100 $this->db = $ilDB;
101 $this->user = $ilUser;
102 }
103
104
108 public function getSupportedVersions()
109 {
110 return array('4.5.0');
111 }
112
113
122 public function getCache($a_entity)
123 {
124 if (!in_array($a_entity, array_keys($this->caches))) {
125 throw new ilException("Entity '$a_entity' does not exist in Cache");
126 }
127
128 return $this->caches[$a_entity];
129 }
130
131
138 public function getXmlNamespace($a_entity, $a_schema_version)
139 {
140 return 'http://www.ilias.de/xml/Modules/DataCollection/' . $a_entity;
141 }
142
143
151 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
152 {
153 switch ($a_entity) {
154 case 'dcl':
155 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['id'])) {
156 $new_obj = ilObjectFactory::getInstanceByObjId($new_id, false);
157 } else {
158 $new_obj = new ilObjDataCollection();
159 $new_obj->create(true);
160 }
161 $new_obj->setTitle($a_rec['title']);
162 $new_obj->setDescription($a_rec['description']);
163 $new_obj->setApproval($a_rec['approval']);
164 $new_obj->setPublicNotes($a_rec['public_notes']);
165 $new_obj->setNotification($a_rec['notification']);
166 $new_obj->setPublicNotes($a_rec['public_notes']);
167 $new_obj->setOnline(false);
168 $new_obj->setRating($a_rec['rating']);
169 $new_obj->update(); //clone mode, so no table will be created
170 $this->import_dc_object = $new_obj;
171 $a_mapping->addMapping('Modules/DataCollection', 'dcl', $a_rec['id'], $new_obj->getId());
172 break;
173 case 'il_dcl_table':
174 $table = new ilDclTable();//($this->count_imported_tables > 0) ? new ilDclTable() : ilDclCache::getTableCache($this->import_dc_object->getMainTableId());
175 $table->setTitle($a_rec['title']);
176 $table->setObjId($this->import_dc_object->getId());
177 $table->setDescription($a_rec['description']);
178 $table->setAddPerm($a_rec['add_perm']);
179 $table->setEditPerm($a_rec['edit_perm']);
180 $table->setDeletePerm($a_rec['delete_perm']);
181 $table->setEditByOwner($a_rec['edit_by_owner']);
182 $table->setLimited($a_rec['limited']);
183 $table->setLimitStart($a_rec['limit_start']);
184 $table->setLimitEnd($a_rec['limit_end']);
185 $table->setIsVisible($a_rec['is_visible']);
186 $table->setExportEnabled($a_rec['export_enabled']);
187 $table->setImportEnabled($a_rec['import_enabled']);
188 $table->setDefaultSortField($a_rec['default_sort_field_id']);
189 $table->setDefaultSortFieldOrder($a_rec['default_sort_field_order']);
190 $table->setPublicCommentsEnabled($a_rec['public_comments']);
191 $table->setViewOwnRecordsPerm($a_rec['view_own_records_perm']);
192 $table->setDeleteByOwner($a_rec['delete_by_owner']);
193 $table->setSaveConfirmation($a_rec['save_confirmation']);
194 $table->setOrder($a_rec['table_order']);
195 $table->doCreate(false, false); // false => Do not create views! They are imported later
196 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['id'], $table->getId());
197 break;
198 case 'il_dcl_tableview':
199 $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
200 if ($new_table_id) {
201 $tableview = new ilDclTableView();
202 $tableview->setTitle($a_rec['title']);
203 $tableview->setTableId($new_table_id);
204 $tableview->setDescription($a_rec['description']);
205 $tableview->setTableviewOrder($a_rec['tableview_order']);
206 if (!is_array($a_rec['roles'])) {
207 $a_rec['roles'] = json_decode($a_rec['roles']);
208 }
209 $tableview->setRoles($a_rec['roles']);
210 is_null($a_rec['step_vs']) ? $tableview->setStepVs(1) : $tableview->setStepVs($a_rec['step_vs']);
211 is_null($a_rec['step_c']) ? $tableview->setStepC(0) : $tableview->setStepC($a_rec['step_c']);
212 is_null($a_rec['step_e']) ? $tableview->setStepE(0) : $tableview->setStepE($a_rec['step_e']);
213 is_null($a_rec['step_o']) ? $tableview->setStepO(0) : $tableview->setStepO($a_rec['step_o']);
214 is_null($a_rec['step_s']) ? $tableview->setStepS(0) : $tableview->setStepS($a_rec['step_s']);
215 $tableview->create(false); //do not create default setting as they are imported too
216 }
217 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_tableview', $a_rec['id'], $tableview->getId());
218 $a_mapping->addMapping('Services/COPage', 'pg', 'dclf:' . $a_rec['id'], 'dclf:' . $tableview->getId());
219 break;
220 case 'il_dcl_field':
221 $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
222 if ($new_table_id) {
223 $field = new ilDclBaseFieldModel();
224 $field->setTableId($new_table_id);
225 $field->setDatatypeId($a_rec['datatype_id']);
226 $field->setTitle($a_rec['title']);
227 $field->setDescription($a_rec['description']);
228 $field->setUnique($a_rec['is_unique']);
229 $field->doCreate();
230 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['id'], $field->getId());
231 // Check if this field was used as default order by, if so, update to new id
232 $table = ilDclCache::getTableCache($new_table_id);
233 if ($table && $table->getDefaultSortField() == $a_rec['id']) {
234 $table->setDefaultSortField($field->getId());
235 $table->doUpdate();
236 }
237 }
238 break;
239 case 'il_dcl_tfield_set':
240 $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
241 $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field']);
242 if ($new_table_id) {
243 $setting = ilDclTableFieldSetting::getInstance($new_table_id, $new_field_id ? $new_field_id : $a_rec['field']);
244 $setting->setFieldOrder($a_rec['field_order']);
245 $setting->setExportable($a_rec['exportable']);
246 $setting->store();
247 }
248 break;
249 case 'il_dcl_tview_set':
250 $new_tableview_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_tableview', $a_rec['tableview_id']);
251 $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field']);
252 if ($new_tableview_id) {
253 $setting = new ilDclTableViewFieldSetting();
254 $setting->setTableviewId($new_tableview_id);
255 $setting->setVisible($a_rec['visible']);
256 $setting->setField($new_field_id ? $new_field_id : $a_rec['field']);
257 $setting->setInFilter($a_rec['in_filter']);
258 $setting->setFilterValue($a_rec['filter_value'] ? $a_rec['filter_value'] : null);
259 $setting->setFilterChangeable($a_rec['filter_changeable']);
260 is_null($a_rec['required_create']) ? $setting->setRequiredCreate(0) : $setting->setRequiredCreate($a_rec['required_create']);
261 is_null($a_rec['locked_create']) ? $setting->setLockedCreate(0) : $setting->setLockedCreate($a_rec['locked_create']);
262 is_null($a_rec['visible_create']) ? $setting->setVisibleCreate(1) : $setting->setVisibleCreate($a_rec['visible_create']);
263 is_null($a_rec['visible_edit']) ? $setting->setVisibleEdit(1) : $setting->setVisibleEdit($a_rec['visible_edit']);
264 is_null($a_rec['required_edit']) ? $setting->setRequiredEdit(0) : $setting->setRequiredEdit($a_rec['required_edit']);
265 is_null($a_rec['locked_edit']) ? $setting->setLockedEdit(0) : $setting->setLockedEdit($a_rec['locked_edit']);
266 $setting->setDefaultValue($a_rec['default_value']);
267 $setting->create();
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('Services/COPage', 'pg', 'dclf:' . $a_rec['id'], 'dclf:' . $tableview->getId());
293 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['id'], $tableview->getId());
294 } else {
295 $a_mapping->addMapping(
296 'Modules/DataCollection',
297 'il_dcl_view',
298 $a_rec['id'],
299 array('type' => $a_rec['type'], 'table_id' => $new_table_id, 'tableview_id' => $tableview->getId())
300 );
301 }
302 }
303 break;
304 case 'il_dcl_viewdefinition':
305 $map = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['view_id']);
306 $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field']);
307 $field = ($new_field_id) ? $new_field_id : $a_rec['field'];
308 switch ($map['type']) {
309 case 1: //visible
310 $viewfield_setting = ilDclTableViewFieldSetting::getInstance($map['tableview_id'], $field);
311 $viewfield_setting->setVisible($a_rec['is_set']);
312 $viewfield_setting->store();
313 break;
314 case 3: //in_filter
315 $viewfield_setting = ilDclTableViewFieldSetting::getInstance($map['tableview_id'], $field);
316 $viewfield_setting->setInFilter($a_rec['is_set']);
317 $viewfield_setting->store();
318 break;
319 case 4: //exportable
320 $tablefield_setting = ilDclTableFieldSetting::getInstance($map['table_id'], $field);
321 $tablefield_setting->setExportable($a_rec['is_set']);
322 $tablefield_setting->setFieldOrder($a_rec['field_order']);
323 $tablefield_setting->store();
324 break;
325 }
326 break;
327 case 'il_dcl_sel_opts':
328 $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
329 if ($new_field_id) {
330 $opt = new ilDclSelectionOption();
331 $opt->setFieldId($new_field_id);
332 $opt->setOptId($a_rec['opt_id']);
333 $opt->setSorting($a_rec['sorting']);
334 $opt->setValue($a_rec['value']);
335 $opt->store();
336 }
337 break;
338 case 'il_dcl_field_prop':
339 $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
340 if ($new_field_id) {
341 $prop = new ilDclFieldProperty();
342 $prop->setFieldId($new_field_id);
343
344 // OLD IMPORT! Backwards-compatibility
345 $name = $a_rec['name'];
346 if (!isset($name) && isset($a_rec['datatype_prop_id'])) {
347 $properties = array(
348 1 => 'length',
349 2 => 'regex',
350 3 => 'table_id',
351 4 => 'url',
352 5 => 'text_area',
353 6 => 'reference_link',
354 7 => 'width',
355 8 => 'height',
356 9 => 'learning_progress',
357 10 => 'ILIAS_reference_link',
358 11 => 'multiple_selection',
359 12 => 'expression',
360 13 => 'display_action_menu',
361 14 => 'link_detail_page',
362 15 => 'link_detail_page',
363 );
364
365 $name = $properties[$a_rec['datatype_prop_id']];
366 }
367
368 $prop->setName($name);
369 // For field references, we need to get the new field id of the referenced field
370 // If the field_id does not yet exist (e.g. referenced table not yet created), store temp info and fix before finishing import
371 $value = $a_rec['value'];
373
374 if (in_array($prop->getName(), $refs)) {
375 $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['value']);
376 if ($new_field_id === false) {
377 $value = null;
378 } else {
379 $value = $new_field_id;
380 }
381 }
382 $prop->setValue($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('Modules/DataCollection', 'il_dcl_record_field', $a_rec['id'], $record_field->getId());
396 $this->import_record_field_cache[$record_field->getId()] = $record_field;
397 }
398 break;
399 case 'il_dcl_stloc1_value':
400 case 'il_dcl_stloc2_value':
401 case 'il_dcl_stloc3_value':
402 $new_record_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record_field', $a_rec['record_field_id']);
403 if ($new_record_field_id) {
405 $record_field = $this->import_record_field_cache[$new_record_field_id];
406 if (is_object($record_field)) {
407 // Need to rewrite internal references and lookup new objects if MOB or File
408 // For some fieldtypes it's better to reset the value, e.g. ILIAS_REF
409 switch ($record_field->getField()->getDatatypeId()) {
411 // Check if we got a mapping from old object
412 $new_mob_id = $a_mapping->getMapping('Services/MediaObjects', 'mob', $a_rec['value']);
413 $value = ($new_mob_id) ? (int) $new_mob_id : null;
414 $this->import_temp_new_mob_ids[] = $new_mob_id;
415 break;
417 $new_file_id = $a_mapping->getMapping('Modules/File', 'file', $a_rec['value']);
418 $value = ($new_file_id) ? (int) $new_file_id : null;
419 break;
422 // If we are referencing to a record from a table that is not yet created, return value is always false because the record does exist neither
423 // Solution: Temporary store all references and fix them before finishing the import.
424 $new_record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['value']);
425 $this->import_temp_refs[$new_record_field_id] = $a_rec['value'];
426 $value = ($new_record_id) ? (int) $new_record_id : null;
427 break;
429 $value = null;
430 break;
431 default:
432 $value = $a_rec['value'];
433 if ($a_entity == 'il_dcl_stloc3_value' && (is_null($value) || empty($value))) {
434 $value = '0000-00-00 00:00:00';
435 }
436 }
437 $record_field->setValue($value, true);
438 $record_field->doUpdate();
439 }
440 }
441 break;
442 }
443 }
444
445
451 public function beforeFinishImport(ilImportMapping $a_mapping)
452 {
453 foreach ($this->import_temp_new_mob_ids as $new_mob_id) {
454 ilObjMediaObject::_saveUsage($new_mob_id, "dcl:html", $a_mapping->getTargetId());
455 }
456 foreach ($this->import_temp_refs as $record_field_id => $old_record_id) {
457 $new_record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $old_record_id);
458 $value = ($new_record_id) ? (int) $new_record_id : null;
460 $record_field = $this->import_record_field_cache[$record_field_id];
461 $record_field->setValue($value, true);
462 $record_field->doUpdate();
463 }
464 foreach ($this->import_temp_refs_props as $field_prop_id => $old_field_id) {
465 $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $old_field_id);
466 $value = ($new_field_id) ? (int) $new_field_id : null;
467 $field_prop = new ilDclFieldProperty($field_prop_id);
468 $field_prop->setValue($value);
469 $field_prop->update();
470 }
471 }
472
473
482 protected function getTypes($a_entity, $a_version)
483 {
484 switch ($a_entity) {
485 case 'dcl':
486 return array(
487 "id" => "integer",
488 "title" => "text",
489 "description" => "text",
490 'is_online' => 'integer',
491 'rating' => 'integer',
492 'public_notes' => 'integer',
493 'approval' => 'integer',
494 'notification' => 'integer',
495 );
496 case 'il_dcl_table':
497 return array(
498 'id' => 'integer',
499 'obj_id' => 'integer',
500 'title' => 'text',
501 'add_perm' => 'integer',
502 'edit_perm' => 'integer',
503 'delete_perm' => 'integer',
504 'edit_by_owner' => 'integer',
505 'limited' => 'integer',
506 'limit_start' => 'text',
507 'limit_end' => 'text',
508 'is_visible' => 'integer',
509 'export_enabled' => 'integer',
510 'import_enabled' => 'integer',
511 'default_sort_field_id' => 'text',
512 'default_sort_field_order' => 'text',
513 'description' => 'text',
514 'public_comments' => 'integer',
515 'view_own_records_perm' => 'integer',
516 'delete_by_owner' => 'integer',
517 'save_confirmation' => 'integer',
518 'table_order' => 'integer',
519 );
520 case 'il_dcl_tableview':
521 return array(
522 'id' => 'integer',
523 'table_id' => 'integer',
524 'title' => 'text',
525 'roles' => 'text',
526 'step_vs' => 'integer',
527 'step_c' => 'integer',
528 'step_e' => 'integer',
529 'step_o' => 'integer',
530 'step_s' => 'integer',
531 'description' => 'text',
532 'tableview_order' => 'integer',
533 );
534 case 'il_dcl_field':
535 return array(
536 'id' => 'integer',
537 'table_id' => 'integer',
538 'title' => 'text',
539 'description' => 'text',
540 'datatype_id' => 'integer',
541 'is_unique' => 'integer',
542 );
543 case 'il_dcl_tview_set':
544 return array(
545 'id' => 'integer',
546 'tableview_id' => 'integer',
547 'field' => 'text',
548 'visible' => 'integer',
549 'in_filter' => 'integer',
550 'filter_value' => 'text',
551 'filter_changeable' => 'integer',
552 'required_create' => 'integer',
553 'required_edit' => 'integer',
554 'locked_create' => 'integer',
555 'locked_edit' => 'integer',
556 'visible_create' => 'integer',
557 'visible_edit' => 'integer',
558 'default_value' => 'text',
559 );
560 case 'il_dcl_tfield_set':
561 return array(
562 'id' => 'integer',
563 'table_id' => 'integer',
564 'field' => 'text',
565 'field_order' => 'integer',
566 'exportable' => 'integer',
567 );
568 case 'il_dcl_field_prop':
569 return array(
570 'id' => 'integer',
571 'field_id' => 'integer',
572 'name' => 'text',
573 'value' => 'integer',
574 );
575 case 'il_dcl_sel_opts':
576 return array(
577 'id' => 'integer',
578 'field_id' => 'integer',
579 'opt_id' => 'integer',
580 'sorting' => 'integer',
581 'value' => 'text',
582 );
583 case 'il_dcl_record':
584 return array(
585 'id' => 'integer',
586 'table_id' => 'integer',
587 );
588 case 'il_dcl_record_field':
589 return array(
590 'id' => 'integer',
591 'record_id' => 'integer',
592 'field_id' => 'integer',
593 );
594 case 'il_dcl_stloc1_value':
595 return array(
596 'id' => 'integer',
597 'record_field_id' => 'integer',
598 'value' => 'text',
599 );
600 case 'il_dcl_stloc2_value':
601 return array(
602 'id' => 'integer',
603 'record_field_id' => 'integer',
604 'value' => 'text',
605 );
606 case 'il_dcl_stloc3_value':
607 return array(
608 'id' => 'integer',
609 'record_field_id' => 'integer',
610 'value' => 'text',
611 );
612 default:
613 return array();
614 }
615 }
616
617
628 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
629 {
630 if (!$a_rec && !$a_ids) {
631 return false;
632 }
633 switch ($a_entity) {
634 case 'dcl':
635 $set = $this->db->query('SELECT * FROM il_dcl_table WHERE obj_id = ' . $this->db->quote($a_rec['id'], 'integer') . ' ORDER BY id');
636 $ids = $this->buildCache('il_dcl_table', $set);
637
638 return array(
639 'il_dcl_table' => array('ids' => $ids),
640 );
641 break;
642 case 'il_dcl_table':
643 $set = $this->db->query('SELECT * FROM il_dcl_record WHERE table_id = ' . $this->db->quote($a_rec['id'], 'integer'));
644 $ids_records = $this->buildCache('il_dcl_record', $set);
645 $set = $this->db->query('SELECT * FROM il_dcl_field WHERE table_id = ' . $this->db->quote($a_rec['id'], 'integer'));
646 $ids_fields = $this->buildCache('il_dcl_field', $set);
647 $set = $this->db->query('SELECT * FROM il_dcl_tableview WHERE table_id = ' . $this->db->quote($a_rec['id'], 'integer'));
648 $ids_tableviews = $this->buildCache('il_dcl_tableview', $set);
649 $set = $this->db->query('SELECT * FROM il_dcl_tfield_set WHERE table_id = ' . $this->db->quote($a_rec['id'], 'integer'));
650 $ids_tablefield_settings = $this->buildCache('il_dcl_tfield_set', $set);
651
652 return array(
653 'il_dcl_field' => array('ids' => $ids_fields),
654 'il_dcl_record' => array('ids' => $ids_records),
655 'il_dcl_tableview' => array('ids' => $ids_tableviews),
656 'il_dcl_tfield_set' => array('ids' => $ids_tablefield_settings),
657 );
658 case 'il_dcl_field':
659 $set = $this->db->query('SELECT * FROM il_dcl_field_prop WHERE field_id = ' . $this->db->quote($a_rec['id'], 'integer'));
660 $prop_ids = $this->buildCache('il_dcl_field_prop', $set);
661
662 $set = $this->db->query('SELECT * FROM il_dcl_sel_opts WHERE field_id = ' . $this->db->quote($a_rec['id'], 'integer'));
663 $opt_ids = $this->buildCache('il_dcl_sel_opts', $set);
664
665 return array(
666 'il_dcl_field_prop' => array('ids' => $prop_ids),
667 'il_dcl_sel_opts' => array('ids' => $opt_ids),
668 );
669 case 'il_dcl_record':
670 $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)'
671 . ' INNER JOIN il_dcl_datatype AS d ON (f.datatype_id = d.id) ' . ' WHERE rf.record_id = '
672 . $this->db->quote($a_rec['id'], 'integer');
673 $set = $this->db->query($sql);
674 $ids = $this->buildCache('il_dcl_record_field', $set);
675
676 $set = $this->db->query($sql);
677 while ($rec = $this->db->fetchObject($set)) {
678 $this->record_field_ids_2_storage[$rec->id] = ilDclCache::getFieldCache($rec->field_id)->getStorageLocation();
679 }
680 // Also build a cache of all values, no matter in which table they are (il_dcl_stloc(1|2|3)_value)
681 $sql
682 = '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 '
683 . 'LEFT JOIN il_dcl_stloc1_value AS st1 ON (st1.record_field_id = rf.id) '
684 . 'LEFT JOIN il_dcl_stloc2_value AS st2 ON (st2.record_field_id = rf.id) '
685 . 'LEFT JOIN il_dcl_stloc3_value AS st3 ON (st3.record_field_id = rf.id) ' . 'WHERE rf.record_id = '
686 . $this->db->quote($a_rec['id'], 'integer');
687 $set = $this->db->query($sql);
688
689 while ($rec = $this->db->fetchObject($set)) {
690 $stloc = $this->record_field_ids_2_storage[$rec->record_field_id];
691 $value = "value{$stloc}";
692 // Save reocrd field id. Internal ID is not used currently
693 $this->caches["il_dcl_stloc{$stloc}_value"][$rec->record_field_id] = array(
694 'record_field_id' => $rec->record_field_id,
695 'value' => $rec->{$value},
696 );
697 }
698
699 return array(
700 'il_dcl_record_field' => array('ids' => $ids),
701 );
702 case 'il_dcl_tableview':
703 $set = $this->db->query('SELECT * FROM il_dcl_tview_set WHERE tableview_id = ' . $this->db->quote($a_rec['id'], 'integer'));
704 $ids = $this->buildCache('il_dcl_tview_set', $set);
705
706 return array(
707 'il_dcl_tview_set' => array('ids' => $ids),
708 );
709 case 'il_dcl_record_field':
710 $record_field_id = $a_rec['id'];
711 $storage_loc = $this->record_field_ids_2_storage[$record_field_id];
712
713 return array(
714 "il_dcl_stloc{$storage_loc}_value" => array('ids' => array($record_field_id)),
715 );
716 }
717
718 return false;
719 }
720
721
729 public function readData($a_entity, $a_version, $a_ids)
730 {
731 $this->data = array();
732 if (!is_array($a_ids)) {
733 $a_ids = array($a_ids);
734 }
735 $this->_readData($a_entity, $a_ids);
736 }
737
738
745 protected function _readData($a_entity, $a_ids)
746 {
747 switch ($a_entity) {
748 case 'dcl':
749 foreach ($a_ids as $dcl_id) {
750 if (ilObject::_lookupType($dcl_id) == 'dcl') {
751 $obj = new ilObjDataCollection($dcl_id, false);
752 $data = array(
753 'id' => $dcl_id,
754 'title' => $obj->getTitle(),
755 'description' => $obj->getDescription(),
756 'is_online' => $obj->getOnline(),
757 'rating' => $obj->getRating(),
758 'public_notes' => $obj->getPublicNotes(),
759 'approval' => $obj->getApproval(),
760 'notification' => $obj->getNotification(),
761 );
762 $this->caches['dcl'][$dcl_id] = $data;
763 $this->data[] = $data;
764 }
765 }
766 break;
767 default:
768 $data = $this->getCache($a_entity);
769 foreach ($a_ids as $id) {
770 $this->data[] = $data[$id];
771 }
772 }
773 }
774
775
785 protected function buildCache($a_entity, $set)
786 {
787 $fields = array_keys($this->getTypes($a_entity, ''));
788 $ids = array();
789 while ($rec = $this->db->fetchObject($set)) {
790 $data = array();
791 foreach ($fields as $field) {
792 $data[$field] = $rec->{$field};
793 }
794 $id = $rec->id;
795 $this->caches[$a_entity][$id] = $data;
796 $ids[] = $id;
797 }
798
799 return $ids;
800 }
801}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
DataCollection dataset class.
_readData($a_entity, $a_ids)
Build data array, data is read from cache except dcl object itself.
buildCache($a_entity, $set)
Helper method to build cache for data of all entities.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Return dependencies form entities to other entities (in our case these are all the DB relations)
getCache($a_entity)
Get cached data from a given entity.
getTypes($a_entity, $a_version)
Map XML attributes of entities to datatypes (text, integer...)
getXmlNamespace($a_entity, $a_schema_version)
readData($a_entity, $a_version, $a_ids)
Read data from Cache for a given entity and ID(s)
A dataset contains in data in a common structure that can be shared and transformed for different pur...
@classDescription Date and time handling
Class ilDclBaseFieldModel.
Class ilDclBaseRecordModel.
static getTableCache($table_id=0)
static getRecordCache($record_id=0)
static getFieldCache($field_id=0)
Class ilDclFieldProperty.
Class ilDclSelectionOption.
static getInstance($table_id, $field)
Class ilDclTableViewFieldSetting.
static getInstance($tableview_id, $field_id)
Class ilDclTableView.
static createOrGetStandardView($table_id, $create_default_settings=true)
Class ilDclBaseFieldModel.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMapping($a_comp, $a_entity, $a_old_id)
Get a mapping.
getTargetId()
get target id
Class ilObjDataCollection.
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupType($a_id, $a_reference=false)
lookup object type
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilDB
$data
Definition: storeScorm.php:23