ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 
12 {
13 
17  protected $db;
21  protected $data = array();
47  protected $caches = 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  );
65  protected $import_dc_object;
69  protected $count_imported_tables = 0;
79  protected $user;
83  protected $import_temp_refs = array();
92 
93 
94  public function __construct()
95  {
96  global $DIC;
97  $ilDB = $DIC['ilDB'];
98  $ilUser = $DIC['ilUser'];
99  parent::__construct();
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  $tableview->create(false); //do not create default setting as they are imported too
211  }
212  $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_tableview', $a_rec['id'], $tableview->getId());
213  $a_mapping->addMapping('Services/COPage', 'pg', 'dclf:' . $a_rec['id'], 'dclf:' . $tableview->getId());
214  break;
215  case 'il_dcl_field':
216  $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
217  if ($new_table_id) {
218  $field = new ilDclBaseFieldModel();
219  $field->setTableId($new_table_id);
220  $field->setDatatypeId($a_rec['datatype_id']);
221  $field->setTitle($a_rec['title']);
222  $field->setDescription($a_rec['description']);
223  $field->setRequired($a_rec['required']);
224  $field->setUnique($a_rec['is_unique']);
225  $field->setLocked($a_rec['is_locked']);
226  $field->doCreate();
227  $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['id'], $field->getId());
228  // Check if this field was used as default order by, if so, update to new id
229  $table = ilDclCache::getTableCache($new_table_id);
230  if ($table && $table->getDefaultSortField() == $a_rec['id']) {
231  $table->setDefaultSortField($field->getId());
232  $table->doUpdate();
233  }
234  }
235  break;
236  case 'il_dcl_tfield_set':
237  $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
238  $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field']);
239  if ($new_table_id) {
240  $setting = ilDclTableFieldSetting::getInstance($new_table_id, $new_field_id ? $new_field_id : $a_rec['field']);
241  $setting->setFieldOrder($a_rec['field_order']);
242  $setting->setExportable($a_rec['exportable']);
243  $setting->store();
244  }
245  break;
246  case 'il_dcl_tview_set':
247  $new_tableview_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_tableview', $a_rec['tableview_id']);
248  $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field']);
249  if ($new_tableview_id) {
250  $setting = new ilDclTableViewFieldSetting();
251  $setting->setTableviewId($new_tableview_id);
252  $setting->setVisible($a_rec['visible']);
253  $setting->setField($new_field_id ? $new_field_id : $a_rec['field']);
254  $setting->setInFilter($a_rec['in_filter']);
255  $setting->setFilterValue($a_rec['filter_value'] ? $a_rec['filter_value'] : null);
256  $setting->setFilterChangeable($a_rec['filter_changeable']);
257  $setting->create();
258  }
259  break;
260  case 'il_dcl_record':
261  $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
262  if ($new_table_id) {
263  $record = new ilDclBaseRecordModel();
264  $record->setTableId($new_table_id);
265  $datetime = new ilDateTime(time(), IL_CAL_UNIX);
266  $record->setCreateDate($datetime);
267  $record->setLastUpdate($datetime);
268  $record->setOwner($this->user->getId());
269  $record->setLastEditBy($this->user->getId());
270  $record->doCreate();
271  $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['id'], $record->getId());
272  }
273  break;
274  case 'il_dcl_view':
275  $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
276  if ($new_table_id) {
277  //if import contains il_dcl_view, it must origin from an earlier ILIAS Version and therefore contains no tableviews
278  //->create standard view
279  $tableview = ilDclTableView::createOrGetStandardView($new_table_id);
280  if ($a_rec['type'] == 0 && $a_rec['formtype'] == 0) { //set page_object to tableview
281  // This mapping is needed for the import handled by Services/COPage
282  $a_mapping->addMapping('Services/COPage', 'pg', 'dclf:' . $a_rec['id'], 'dclf:' . $tableview->getId());
283  $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['id'], $tableview->getId());
284  } else {
285  $a_mapping->addMapping(
286  'Modules/DataCollection',
287  'il_dcl_view',
288  $a_rec['id'],
289  array('type' => $a_rec['type'], 'table_id' => $new_table_id, 'tableview_id' => $tableview->getId())
290  );
291  }
292  }
293  break;
294  case 'il_dcl_viewdefinition':
295  $map = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['view_id']);
296  $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field']);
297  $field = ($new_field_id) ? $new_field_id : $a_rec['field'];
298  switch ($map['type']) {
299  case 1: //visible
300  $viewfield_setting = ilDclTableViewFieldSetting::getInstance($map['tableview_id'], $field);
301  $viewfield_setting->setVisible($a_rec['is_set']);
302  $viewfield_setting->store();
303  break;
304  case 3: //in_filter
305  $viewfield_setting = ilDclTableViewFieldSetting::getInstance($map['tableview_id'], $field);
306  $viewfield_setting->setInFilter($a_rec['is_set']);
307  $viewfield_setting->store();
308  break;
309  case 4: //exportable
310  $tablefield_setting = ilDclTableFieldSetting::getInstance($map['table_id'], $field);
311  $tablefield_setting->setExportable($a_rec['is_set']);
312  $tablefield_setting->setFieldOrder($a_rec['field_order']);
313  $tablefield_setting->store();
314  break;
315 
316  }
317  break;
318  case 'il_dcl_sel_opts':
319  $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
320  if ($new_field_id) {
321  $opt = new ilDclSelectionOption();
322  $opt->setFieldId($new_field_id);
323  $opt->setOptId($a_rec['opt_id']);
324  $opt->setSorting($a_rec['sorting']);
325  $opt->setValue($a_rec['value']);
326  $opt->store();
327  }
328  break;
329  case 'il_dcl_field_prop':
330  $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
331  if ($new_field_id) {
332  $prop = new ilDclFieldProperty();
333  $prop->setFieldId($new_field_id);
334 
335  // OLD IMPORT! Backwards-compatibility
336  $name = $a_rec['name'];
337  if (!isset($name) && isset($a_rec['datatype_prop_id'])) {
338  $properties = array(
339  1 => 'length',
340  2 => 'regex',
341  3 => 'table_id',
342  4 => 'url',
343  5 => 'text_area',
344  6 => 'reference_link',
345  7 => 'width',
346  8 => 'height',
347  9 => 'learning_progress',
348  10 => 'ILIAS_reference_link',
349  11 => 'multiple_selection',
350  12 => 'expression',
351  13 => 'display_action_menu',
352  14 => 'link_detail_page',
353  15 => 'link_detail_page'
354  );
355 
356  $name = $properties[$a_rec['datatype_prop_id']];
357  }
358 
359  $prop->setName($name);
360  // For field references, we need to get the new field id of the referenced field
361  // If the field_id does not yet exist (e.g. referenced table not yet created), store temp info and fix before finishing import
362  $value = $a_rec['value'];
364  $fix_refs = false;
365 
366  if (in_array($prop->getName(), $refs)) {
367  $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['value']);
368  if ($new_field_id === false) {
369  $value = null;
370  $fix_refs = true;
371  } else {
372  $value = $new_field_id;
373  }
374  }
375  $prop->setValue($value);
376  $prop->save();
377  $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_field_prop', $a_rec['id'], $prop->getId());
378  if ($fix_refs) {
379  $this->import_temp_refs_props[$prop->getId()] = $a_rec['value'];
380  }
381  }
382  break;
383  case 'il_dcl_record_field':
384  $record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['record_id']);
385  $field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
386  if ($record_id && $field_id) {
387  $record = ilDclCache::getRecordCache($record_id);
388  $field = ilDclCache::getFieldCache($field_id);
389  $record_field = new ilDclBaseRecordFieldModel($record, $field);
390  $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_record_field', $a_rec['id'], $record_field->getId());
391  $this->import_record_field_cache[$record_field->getId()] = $record_field;
392  }
393  break;
394  case 'il_dcl_stloc1_value':
395  case 'il_dcl_stloc2_value':
396  case 'il_dcl_stloc3_value':
397  $new_record_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record_field', $a_rec['record_field_id']);
398  if ($new_record_field_id) {
400  $record_field = $this->import_record_field_cache[$new_record_field_id];
401  if (is_object($record_field)) {
402  // Need to rewrite internal references and lookup new objects if MOB or File
403  // For some fieldtypes it's better to reset the value, e.g. ILIAS_REF
404  switch ($record_field->getField()->getDatatypeId()) {
406  // Check if we got a mapping from old object
407  $new_mob_id = $a_mapping->getMapping('Services/MediaObjects', 'mob', $a_rec['value']);
408  $value = ($new_mob_id) ? (int) $new_mob_id : null;
409  $this->import_temp_new_mob_ids[] = $new_mob_id;
410  break;
412  $new_file_id = $a_mapping->getMapping('Modules/File', 'file', $a_rec['value']);
413  $value = ($new_file_id) ? (int) $new_file_id : null;
414  break;
417  // 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
418  // Solution: Temporary store all references and fix them before finishing the import.
419  $new_record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['value']);
420  if ($new_record_id === false) {
421  $this->import_temp_refs[$new_record_field_id] = $a_rec['value'];
422  }
423  $value = ($new_record_id) ? (int) $new_record_id : null;
424  break;
426  $value = null;
427  break;
428  default:
429  $value = $a_rec['value'];
430  if ($a_entity == 'il_dcl_stloc3_value' && (is_null($value) || empty($value))) {
431  $value = '0000-00-00 00:00:00';
432  }
433  }
434  $record_field->setValue($value, true);
435  $record_field->doUpdate();
436  }
437  }
438  break;
439  }
440  }
441 
442 
448  public function beforeFinishImport(ilImportMapping $a_mapping)
449  {
450  foreach ($this->import_temp_new_mob_ids as $new_mob_id) {
451  ilObjMediaObject::_saveUsage($new_mob_id, "dcl:html", $a_mapping->getTargetId());
452  }
453  foreach ($this->import_temp_refs as $record_field_id => $old_record_id) {
454  $new_record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $old_record_id);
455  $value = ($new_record_id) ? (int) $new_record_id : null;
457  $record_field = $this->import_record_field_cache[$record_field_id];
458  $record_field->setValue($value, true);
459  $record_field->doUpdate();
460  }
461  foreach ($this->import_temp_refs_props as $field_prop_id => $old_field_id) {
462  $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $old_field_id);
463  $value = ($new_field_id) ? (int) $new_field_id : null;
464  $field_prop = new ilDclFieldProperty($field_prop_id);
465  $field_prop->setValue($value);
466  $field_prop->update();
467  }
468  }
469 
470 
479  protected function getTypes($a_entity, $a_version)
480  {
481  switch ($a_entity) {
482  case 'dcl':
483  return array(
484  "id" => "integer",
485  "title" => "text",
486  "description" => "text",
487  'is_online' => 'integer',
488  'rating' => 'integer',
489  'public_notes' => 'integer',
490  'approval' => 'integer',
491  'notification' => 'integer',
492  );
493  case 'il_dcl_table':
494  return array(
495  'id' => 'integer',
496  'obj_id' => 'integer',
497  'title' => 'text',
498  'add_perm' => 'integer',
499  'edit_perm' => 'integer',
500  'delete_perm' => 'integer',
501  'edit_by_owner' => 'integer',
502  'limited' => 'integer',
503  'limit_start' => 'text',
504  'limit_end' => 'text',
505  'is_visible' => 'integer',
506  'export_enabled' => 'integer',
507  'import_enabled' => 'integer',
508  'default_sort_field_id' => 'text',
509  'default_sort_field_order' => 'text',
510  'description' => 'text',
511  'public_comments' => 'integer',
512  'view_own_records_perm' => 'integer',
513  'delete_by_owner' => 'integer',
514  'save_confirmation' => 'integer',
515  'table_order' => 'integer',
516  );
517  case 'il_dcl_tableview':
518  return array(
519  'id' => 'integer',
520  'table_id' => 'integer',
521  'title' => 'text',
522  'roles' => 'text',
523  'description' => 'text',
524  'tableview_order' => 'integer',
525  );
526  case 'il_dcl_field':
527  return array(
528  'id' => 'integer',
529  'table_id' => 'integer',
530  'title' => 'text',
531  'description' => 'text',
532  'datatype_id' => 'integer',
533  'required' => 'integer',
534  'is_unique' => 'integer',
535  'is_locked' => 'integer',
536  );
537  case 'il_dcl_tview_set':
538  return array(
539  'id' => 'integer',
540  'tableview_id' => 'integer',
541  'field' => 'text',
542  'visible' => 'integer',
543  'in_filter' => 'integer',
544  'filter_value' => 'text',
545  'filter_changeable' => 'integer',
546  );
547  case 'il_dcl_tfield_set':
548  return array(
549  'id' => 'integer',
550  'table_id' => 'integer',
551  'field' => 'text',
552  'field_order' => 'integer',
553  'exportable' => 'integer',
554  );
555  case 'il_dcl_field_prop':
556  return array(
557  'id' => 'integer',
558  'field_id' => 'integer',
559  'name' => 'text',
560  'value' => 'integer',
561  );
562  case 'il_dcl_sel_opts':
563  return array(
564  'id' => 'integer',
565  'field_id' => 'integer',
566  'opt_id' => 'integer',
567  'sorting' => 'integer',
568  'value' => 'text',
569  );
570  case 'il_dcl_record':
571  return array(
572  'id' => 'integer',
573  'table_id' => 'integer',
574  );
575  case 'il_dcl_record_field':
576  return array(
577  'id' => 'integer',
578  'record_id' => 'integer',
579  'field_id' => 'integer',
580  );
581  case 'il_dcl_stloc1_value':
582  return array(
583  'id' => 'integer',
584  'record_field_id' => 'integer',
585  'value' => 'text',
586  );
587  case 'il_dcl_stloc2_value':
588  return array(
589  'id' => 'integer',
590  'record_field_id' => 'integer',
591  'value' => 'text',
592  );
593  case 'il_dcl_stloc3_value':
594  return array(
595  'id' => 'integer',
596  'record_field_id' => 'integer',
597  'value' => 'text',
598  );
599  default:
600  return array();
601  }
602  }
603 
604 
615  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
616  {
617  if (!$a_rec && !$a_ids) {
618  return false;
619  }
620  switch ($a_entity) {
621  case 'dcl':
622  $set = $this->db->query('SELECT * FROM il_dcl_table WHERE obj_id = ' . $this->db->quote($a_rec['id'], 'integer') . ' ORDER BY id');
623  $ids = $this->buildCache('il_dcl_table', $set);
624 
625  return array(
626  'il_dcl_table' => array( 'ids' => $ids ),
627  );
628  break;
629  case 'il_dcl_table':
630  $set = $this->db->query('SELECT * FROM il_dcl_record WHERE table_id = ' . $this->db->quote($a_rec['id'], 'integer'));
631  $ids_records = $this->buildCache('il_dcl_record', $set);
632  $set = $this->db->query('SELECT * FROM il_dcl_field WHERE table_id = ' . $this->db->quote($a_rec['id'], 'integer'));
633  $ids_fields = $this->buildCache('il_dcl_field', $set);
634  $set = $this->db->query('SELECT * FROM il_dcl_tableview WHERE table_id = ' . $this->db->quote($a_rec['id'], 'integer'));
635  $ids_tableviews = $this->buildCache('il_dcl_tableview', $set);
636  $set = $this->db->query('SELECT * FROM il_dcl_tfield_set WHERE table_id = ' . $this->db->quote($a_rec['id'], 'integer'));
637  $ids_tablefield_settings = $this->buildCache('il_dcl_tfield_set', $set);
638 
639  return array(
640  'il_dcl_field' => array( 'ids' => $ids_fields ),
641  'il_dcl_record' => array( 'ids' => $ids_records ),
642  'il_dcl_tableview' => array( 'ids' => $ids_tableviews ),
643  'il_dcl_tfield_set' => array( 'ids' => $ids_tablefield_settings ),
644  );
645  case 'il_dcl_field':
646  $set = $this->db->query('SELECT * FROM il_dcl_field_prop WHERE field_id = ' . $this->db->quote($a_rec['id'], 'integer'));
647  $prop_ids = $this->buildCache('il_dcl_field_prop', $set);
648 
649  $set = $this->db->query('SELECT * FROM il_dcl_sel_opts WHERE field_id = ' . $this->db->quote($a_rec['id'], 'integer'));
650  $opt_ids = $this->buildCache('il_dcl_sel_opts', $set);
651 
652  return array(
653  'il_dcl_field_prop' => array( 'ids' => $prop_ids ),
654  'il_dcl_sel_opts' => array( 'ids' => $opt_ids ),
655  );
656  case 'il_dcl_record':
657  $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)'
658  . ' INNER JOIN il_dcl_datatype AS d ON (f.datatype_id = d.id) ' . ' WHERE rf.record_id = '
659  . $this->db->quote($a_rec['id'], 'integer');
660  $set = $this->db->query($sql);
661  $ids = $this->buildCache('il_dcl_record_field', $set);
662 
663  $set = $this->db->query($sql);
664  while ($rec = $this->db->fetchObject($set)) {
665  $this->record_field_ids_2_storage[$rec->id] = ilDclCache::getFieldCache($rec->field_id)->getStorageLocation();
666  }
667  // Also build a cache of all values, no matter in which table they are (il_dcl_stloc(1|2|3)_value)
668  $sql =
669  '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 '
670  . 'LEFT JOIN il_dcl_stloc1_value AS st1 ON (st1.record_field_id = rf.id) '
671  . 'LEFT JOIN il_dcl_stloc2_value AS st2 ON (st2.record_field_id = rf.id) '
672  . 'LEFT JOIN il_dcl_stloc3_value AS st3 ON (st3.record_field_id = rf.id) ' . 'WHERE rf.record_id = '
673  . $this->db->quote($a_rec['id'], 'integer');
674  $set = $this->db->query($sql);
675 
676  while ($rec = $this->db->fetchObject($set)) {
677  $stloc = $this->record_field_ids_2_storage[$rec->record_field_id];
678  $value = "value{$stloc}";
679  // Save reocrd field id. Internal ID is not used currently
680  $this->caches["il_dcl_stloc{$stloc}_value"][$rec->record_field_id] = array(
681  'record_field_id' => $rec->record_field_id,
682  'value' => $rec->{$value}
683  );
684  }
685 
686  return array(
687  'il_dcl_record_field' => array( 'ids' => $ids )
688  );
689  case 'il_dcl_tableview':
690  $set = $this->db->query('SELECT * FROM il_dcl_tview_set WHERE tableview_id = ' . $this->db->quote($a_rec['id'], 'integer'));
691  $ids = $this->buildCache('il_dcl_tview_set', $set);
692 
693  return array(
694  'il_dcl_tview_set' => array( 'ids' => $ids )
695  );
696  case 'il_dcl_record_field':
697  $record_field_id = $a_rec['id'];
698  $storage_loc = $this->record_field_ids_2_storage[$record_field_id];
699 
700  return array(
701  "il_dcl_stloc{$storage_loc}_value" => array( 'ids' => array( $record_field_id ) )
702  );
703  }
704 
705  return false;
706  }
707 
708 
716  public function readData($a_entity, $a_version, $a_ids)
717  {
718  $this->data = array();
719  if (!is_array($a_ids)) {
720  $a_ids = array( $a_ids );
721  }
722  $this->_readData($a_entity, $a_ids);
723  }
724 
725 
732  protected function _readData($a_entity, $a_ids)
733  {
734  switch ($a_entity) {
735  case 'dcl':
736  foreach ($a_ids as $dcl_id) {
737  if (ilObject::_lookupType($dcl_id) == 'dcl') {
738  $obj = new ilObjDataCollection($dcl_id, false);
739  $data = array(
740  'id' => $dcl_id,
741  'title' => $obj->getTitle(),
742  'description' => $obj->getDescription(),
743  'is_online' => $obj->getOnline(),
744  'rating' => $obj->getRating(),
745  'public_notes' => $obj->getPublicNotes(),
746  'approval' => $obj->getApproval(),
747  'notification' => $obj->getNotification(),
748  );
749  $this->caches['dcl'][$dcl_id] = $data;
750  $this->data[] = $data;
751  }
752  }
753  break;
754  default:
755  $data = $this->getCache($a_entity);
756  foreach ($a_ids as $id) {
757  $this->data[] = $data[$id];
758  }
759  }
760  }
761 
762 
772  protected function buildCache($a_entity, $set)
773  {
774  $fields = array_keys($this->getTypes($a_entity, ''));
775  $ids = array();
776  while ($rec = $this->db->fetchObject($set)) {
777  $data = array();
778  foreach ($fields as $field) {
779  $data[$field] = $rec->{$field};
780  }
781  $id = $rec->id;
782  $this->caches[$a_entity][$id] = $data;
783  $ids[] = $id;
784  }
785 
786  return $ids;
787  }
788 }
Add some data
getMapping($a_comp, $a_entity, $a_old_id)
Get a mapping.
_readData($a_entity, $a_ids)
Build data array, data is read from cache except dcl object itself.
Class ilDclBaseFieldModel.
static getInstance($table_id, $field)
readData($a_entity, $a_version, $a_ids)
Read data from Cache for a given entity and ID(s)
global $DIC
Definition: saml.php:7
static getFieldCache($field_id=0)
Class ilDclFieldProperty.
if(!array_key_exists('StateId', $_REQUEST)) $id
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.
const IL_CAL_UNIX
static getTableCache($table_id=0)
Class ilDclBaseFieldModel.
user()
Definition: user.php:4
Class ilDclTableViewFieldSetting.
static getInstance($tableview_id, $field_id)
if($format !==null) $name
Definition: metadata.php:146
buildCache($a_entity, $set)
Helper method to build cache for data of all entities.
DataCollection dataset class.
static getRecordCache($record_id=0)
Class ilDclTableView.
Date and time handling
$ilUser
Definition: imgupload.php:18
getTargetId()
get target id
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static createOrGetStandardView($table_id, $create_default_settings=true)
Class ilDclBaseRecordModel.
global $ilDB
Class ilDclSelectionOption.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
getTypes($a_entity, $a_version)
Map XML attributes of entities to datatypes (text, integer...)
if(empty($password)) $table
Definition: pwgen.php:24
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getXmlNamespace($a_entity, $a_schema_version)
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.
Class ilObjDataCollection.