4 require_once(
"./Services/DataSet/classes/class.ilDataSet.php");
5 require_once(
'./Modules/DataCollection/classes/Helpers/class.ilDclCache.php');
6 require_once(
'class.ilObjDataCollection.php');
51 'il_dcl_table' =>
array(),
52 'il_dcl_field' =>
array(),
53 'il_dcl_field_prop' =>
array(),
54 'il_dcl_record' =>
array(),
55 'il_dcl_record_field' =>
array(),
56 'il_dcl_stloc1_value' =>
array(),
57 'il_dcl_stloc2_value' =>
array(),
58 'il_dcl_stloc3_value' =>
array(),
59 'il_dcl_tfield_set' =>
array(),
60 'il_dcl_tableview' =>
array(),
61 'il_dcl_tview_set' =>
array(),
99 parent::__construct();
109 return array(
'4.5.0' );
122 if (!in_array($a_entity, array_keys($this->caches))) {
123 throw new ilException(
"Entity '$a_entity' does not exist in Cache");
126 return $this->caches[$a_entity];
137 return 'http://www.ilias.de/xml/Modules/DataCollection/' . $a_entity;
148 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version) {
151 if($new_id = $a_mapping->getMapping(
'Services/Container',
'objs',$a_rec[
'id']))
158 $new_obj->create(
true);
160 $new_obj->setTitle($a_rec[
'title']);
161 $new_obj->setDescription($a_rec[
'description']);
162 $new_obj->setApproval($a_rec[
'approval']);
163 $new_obj->setPublicNotes($a_rec[
'public_notes']);
164 $new_obj->setNotification($a_rec[
'notification']);
165 $new_obj->setPublicNotes($a_rec[
'public_notes']);
166 $new_obj->setOnline(
false);
167 $new_obj->setRating($a_rec[
'rating']);
169 $this->import_dc_object = $new_obj;
170 $a_mapping->addMapping(
'Modules/DataCollection',
'dcl', $a_rec[
'id'], $new_obj->getId());
174 $table->setTitle($a_rec[
'title']);
175 $table->setObjId($this->import_dc_object->getId());
176 $table->setDescription($a_rec[
'description']);
177 $table->setAddPerm($a_rec[
'add_perm']);
178 $table->setEditPerm($a_rec[
'edit_perm']);
179 $table->setDeletePerm($a_rec[
'delete_perm']);
180 $table->setEditByOwner($a_rec[
'edit_by_owner']);
181 $table->setLimited($a_rec[
'limited']);
182 $table->setLimitStart($a_rec[
'limit_start']);
183 $table->setLimitEnd($a_rec[
'limit_end']);
184 $table->setIsVisible($a_rec[
'is_visible']);
185 $table->setExportEnabled($a_rec[
'export_enabled']);
186 $table->setImportEnabled($a_rec[
'import_enabled']);
187 $table->setDefaultSortField($a_rec[
'default_sort_field_id']);
188 $table->setDefaultSortFieldOrder($a_rec[
'default_sort_field_order']);
189 $table->setPublicCommentsEnabled($a_rec[
'public_comments']);
190 $table->setViewOwnRecordsPerm($a_rec[
'view_own_records_perm']);
191 $table->setDeleteByOwner($a_rec[
'delete_by_owner']);
192 $table->setSaveConfirmation($a_rec[
'save_confirmation']);
193 $table->setOrder($a_rec[
'table_order']);
194 $table->doCreate(
false,
false);
195 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_table', $a_rec[
'id'], $table->getId());
197 case 'il_dcl_tableview':
198 $new_table_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_table', $a_rec[
'table_id']);
201 $tableview->setTitle($a_rec[
'title']);
202 $tableview->setTableId($new_table_id);
203 $tableview->setDescription($a_rec[
'description']);
204 $tableview->setTableviewOrder($a_rec[
'tableview_order']);
205 if(!is_array($a_rec[
'roles']))
206 $a_rec[
'roles'] = json_decode($a_rec[
'roles']);
207 $tableview->setRoles($a_rec[
'roles']);
208 $tableview->create(
false);
210 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_tableview', $a_rec[
'id'], $tableview->getId());
211 $a_mapping->addMapping(
'Services/COPage',
'pg',
'dclf:'.$a_rec[
'id'],
'dclf:'.$tableview->getId());
214 $new_table_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_table', $a_rec[
'table_id']);
217 $field->setTableId($new_table_id);
218 $field->setDatatypeId($a_rec[
'datatype_id']);
219 $field->setTitle($a_rec[
'title']);
220 $field->setDescription($a_rec[
'description']);
221 $field->setRequired($a_rec[
'required']);
222 $field->setUnique($a_rec[
'is_unique']);
223 $field->setLocked($a_rec[
'is_locked']);
225 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_field', $a_rec[
'id'], $field->getId());
228 if ($table && $table->getDefaultSortField() == $a_rec[
'id']) {
229 $table->setDefaultSortField($field->getId());
234 case 'il_dcl_tfield_set':
235 $new_table_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_table', $a_rec[
'table_id']);
236 $new_field_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_field', $a_rec[
'field']);
239 $setting->setFieldOrder($a_rec[
'field_order']);
240 $setting->setExportable($a_rec[
'exportable']);
244 case 'il_dcl_tview_set':
245 $new_tableview_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_tableview', $a_rec[
'tableview_id']);
246 $new_field_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_field', $a_rec[
'field']);
247 if ($new_tableview_id) {
249 $setting->setTableviewId($new_tableview_id);
250 $setting->setVisible($a_rec[
'visible']);
251 $setting->setField($new_field_id ? $new_field_id : $a_rec[
'field']);
252 $setting->setInFilter($a_rec[
'in_filter']);
253 $setting->setFilterValue($a_rec[
'filter_value'] ? $a_rec[
'filter_value'] : null);
254 $setting->setFilterChangeable($a_rec[
'filter_changeable']);
258 case 'il_dcl_record':
259 $new_table_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_table', $a_rec[
'table_id']);
262 $record->setTableId($new_table_id);
264 $record->setCreateDate($datetime);
265 $record->setLastUpdate($datetime);
266 $record->setOwner($this->
user->getId());
267 $record->setLastEditBy($this->
user->getId());
269 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_record', $a_rec[
'id'], $record->getId());
273 $new_table_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_table', $a_rec[
'table_id']);
278 if ($a_rec[
'type'] == 0 && $a_rec[
'formtype'] == 0) {
280 $a_mapping->addMapping(
'Services/COPage',
'pg',
'dclf:' . $a_rec[
'id'],
'dclf:' . $tableview->getId());
281 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_view', $a_rec[
'id'], $tableview->getId());
283 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_view', $a_rec[
'id'],
284 array(
'type' => $a_rec[
'type'],
'table_id' => $new_table_id,
'tableview_id' => $tableview->getId()));
288 case 'il_dcl_viewdefinition':
289 $map = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_view', $a_rec[
'view_id']);
290 $new_field_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_field', $a_rec[
'field']);
291 $field = ($new_field_id) ? $new_field_id : $a_rec[
'field'];
292 switch ($map[
'type']) {
295 $viewfield_setting->setVisible($a_rec[
'is_set']);
296 $viewfield_setting->store();
300 $viewfield_setting->setInFilter($a_rec[
'is_set']);
301 $viewfield_setting->store();
305 $tablefield_setting->setExportable($a_rec[
'is_set']);
306 $tablefield_setting->setFieldOrder($a_rec[
'field_order']);
307 $tablefield_setting->store();
312 case 'il_dcl_field_prop':
313 $new_field_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_field', $a_rec[
'field_id']);
316 $prop->setFieldId($new_field_id);
319 $name = $a_rec[
'name'];
320 if(!isset($name) && isset($a_rec[
'datatype_prop_id'])) {
327 6 =>
'reference_link',
330 9 =>
'learning_progress',
331 10 =>
'ILIAS_reference_link',
332 11 =>
'multiple_selection',
334 13 =>
'display_action_menu',
335 14 =>
'link_detail_page',
336 15 =>
'link_detail_page' 339 $name = $properties[$a_rec[
'datatype_prop_id']];
342 $prop->setName($name);
345 $value = $a_rec[
'value'];
349 if (in_array($prop->getName(), $refs)) {
350 $new_field_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_field', $a_rec[
'value']);
351 if ($new_field_id ===
false) {
355 $value = $new_field_id;
358 $prop->setValue($value);
360 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_field_prop', $a_rec[
'id'], $prop->getId());
362 $this->import_temp_refs_props[$prop->getId()] = $a_rec[
'value'];
366 case 'il_dcl_record_field':
367 $record_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_record', $a_rec[
'record_id']);
368 $field_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_field', $a_rec[
'field_id']);
369 if ($record_id && $field_id) {
373 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_record_field', $a_rec[
'id'], $record_field->getId());
374 $this->import_record_field_cache[$record_field->getId()] = $record_field;
377 case 'il_dcl_stloc1_value':
378 case 'il_dcl_stloc2_value':
379 case 'il_dcl_stloc3_value':
380 $new_record_field_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_record_field', $a_rec[
'record_field_id']);
381 if ($new_record_field_id) {
383 $record_field = $this->import_record_field_cache[$new_record_field_id];
384 if (is_object($record_field)) {
387 switch ($record_field->getField()->getDatatypeId()) {
390 $new_mob_id = $a_mapping->getMapping(
'Services/MediaObjects',
'mob', $a_rec[
'value']);
391 $value = ($new_mob_id) ? (
int)$new_mob_id : NULL;
392 $this->import_temp_new_mob_ids[] = $new_mob_id;
395 $new_file_id = $a_mapping->getMapping(
'Modules/File',
'file', $a_rec[
'value']);
396 $value = ($new_file_id) ? (
int)$new_file_id : NULL;
402 $new_record_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_record', $a_rec[
'value']);
403 if ($new_record_id ===
false) {
404 $this->import_temp_refs[$new_record_field_id] = $a_rec[
'value'];
406 $value = ($new_record_id) ? (
int)$new_record_id : NULL;
412 $value = $a_rec[
'value'];
413 if ($a_entity ==
'il_dcl_stloc3_value' && (is_null($value) || empty($value))) {
414 $value =
'0000-00-00 00:00:00';
417 $record_field->setValue($value,
true);
418 $record_field->doUpdate();
432 foreach ($this->import_temp_new_mob_ids as $new_mob_id) {
435 foreach ($this->import_temp_refs as $record_field_id => $old_record_id) {
436 $new_record_id = $a_mapping->
getMapping(
'Modules/DataCollection',
'il_dcl_record', $old_record_id);
437 $value = ($new_record_id) ? (
int)$new_record_id : NULL;
439 $record_field = $this->import_record_field_cache[$record_field_id];
440 $record_field->setValue($value,
true);
441 $record_field->doUpdate();
443 foreach ($this->import_temp_refs_props as $field_prop_id => $old_field_id) {
444 $new_field_id = $a_mapping->
getMapping(
'Modules/DataCollection',
'il_dcl_field', $old_field_id);
445 $value = ($new_field_id) ? (
int)$new_field_id : NULL;
447 $field_prop->setValue($value);
448 $field_prop->update();
461 protected function getTypes($a_entity, $a_version) {
467 "description" =>
"text",
468 'is_online' =>
'integer',
469 'rating' =>
'integer',
470 'public_notes' =>
'integer',
471 'approval' =>
'integer',
472 'notification' =>
'integer',
477 'obj_id' =>
'integer',
479 'add_perm' =>
'integer',
480 'edit_perm' =>
'integer',
481 'delete_perm' =>
'integer',
482 'edit_by_owner' =>
'integer',
483 'limited' =>
'integer',
484 'limit_start' =>
'text',
485 'limit_end' =>
'text',
486 'is_visible' =>
'integer',
487 'export_enabled' =>
'integer',
488 'import_enabled' =>
'integer',
489 'default_sort_field_id' =>
'text',
490 'default_sort_field_order' =>
'text',
491 'description' =>
'text',
492 'public_comments' =>
'integer',
493 'view_own_records_perm' =>
'integer',
494 'delete_by_owner' =>
'integer',
495 'save_confirmation' =>
'integer',
496 'table_order' =>
'integer',
498 case 'il_dcl_tableview':
501 'table_id' =>
'integer',
504 'description' =>
'text',
505 'tableview_order' =>
'integer',
510 'table_id' =>
'integer',
512 'description' =>
'text',
513 'datatype_id' =>
'integer',
514 'required' =>
'integer',
515 'is_unique' =>
'integer',
516 'is_locked' =>
'integer',
518 case 'il_dcl_tview_set':
521 'tableview_id' =>
'integer',
523 'visible' =>
'integer',
524 'in_filter' =>
'integer',
525 'filter_value' =>
'text',
526 'filter_changeable' =>
'integer',
528 case 'il_dcl_tfield_set':
531 'table_id' =>
'integer',
533 'field_order' =>
'integer',
534 'exportable' =>
'integer',
536 case 'il_dcl_field_prop':
539 'field_id' =>
'integer',
541 'value' =>
'integer',
543 case 'il_dcl_record':
546 'table_id' =>
'integer',
548 case 'il_dcl_record_field':
551 'record_id' =>
'integer',
552 'field_id' =>
'integer',
554 case 'il_dcl_stloc1_value':
557 'record_field_id' =>
'integer',
560 case 'il_dcl_stloc2_value':
563 'record_field_id' =>
'integer',
566 case 'il_dcl_stloc3_value':
569 'record_field_id' =>
'integer',
589 if (!$a_rec && !$a_ids) {
594 $set = $this->db->query(
'SELECT * FROM il_dcl_table WHERE obj_id = ' . $this->db->quote($a_rec[
'id'],
'integer') .
' ORDER BY id');
595 $ids = $this->
buildCache(
'il_dcl_table', $set);
598 'il_dcl_table' =>
array(
'ids' => $ids ),
602 $set = $this->db->query(
'SELECT * FROM il_dcl_record WHERE table_id = ' . $this->db->quote($a_rec[
'id'],
'integer'));
603 $ids_records = $this->
buildCache(
'il_dcl_record', $set);
604 $set = $this->db->query(
'SELECT * FROM il_dcl_field WHERE table_id = ' . $this->db->quote($a_rec[
'id'],
'integer'));
605 $ids_fields = $this->
buildCache(
'il_dcl_field', $set);
606 $set = $this->db->query(
'SELECT * FROM il_dcl_tableview WHERE table_id = ' . $this->db->quote($a_rec[
'id'],
'integer'));
607 $ids_tableviews = $this->
buildCache(
'il_dcl_tableview', $set);
608 $set = $this->db->query(
'SELECT * FROM il_dcl_tfield_set WHERE table_id = ' . $this->db->quote($a_rec[
'id'],
'integer'));
609 $ids_tablefield_settings = $this->
buildCache(
'il_dcl_tfield_set', $set);
612 'il_dcl_field' =>
array(
'ids' => $ids_fields ),
613 'il_dcl_record' =>
array(
'ids' => $ids_records ),
614 'il_dcl_tableview' =>
array(
'ids' => $ids_tableviews ),
615 'il_dcl_tfield_set' =>
array(
'ids' => $ids_tablefield_settings ),
618 $set = $this->db->query(
'SELECT * FROM il_dcl_field_prop WHERE field_id = ' . $this->db->quote($a_rec[
'id'],
'integer'));
619 $ids = $this->
buildCache(
'il_dcl_field_prop', $set);
622 'il_dcl_field_prop' =>
array(
'ids' => $ids ),
624 case 'il_dcl_record':
625 $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)' 626 .
' INNER JOIN il_dcl_datatype AS d ON (f.datatype_id = d.id) ' .
' WHERE rf.record_id = ' 627 . $this->db->quote($a_rec[
'id'],
'integer');
628 $set = $this->db->query($sql);
629 $ids = $this->
buildCache(
'il_dcl_record_field', $set);
631 $set = $this->db->query($sql);
632 while ($rec = $this->db->fetchObject($set)) {
637 '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 ' 638 .
'LEFT JOIN il_dcl_stloc1_value AS st1 ON (st1.record_field_id = rf.id) ' 639 .
'LEFT JOIN il_dcl_stloc2_value AS st2 ON (st2.record_field_id = rf.id) ' 640 .
'LEFT JOIN il_dcl_stloc3_value AS st3 ON (st3.record_field_id = rf.id) ' .
'WHERE rf.record_id = ' 641 . $this->db->quote($a_rec[
'id'],
'integer');
642 $set = $this->db->query($sql);
644 while ($rec = $this->db->fetchObject($set)) {
645 $stloc = $this->record_field_ids_2_storage[$rec->record_field_id];
646 $value =
"value{$stloc}";
648 $this->caches[
"il_dcl_stloc{$stloc}_value"][$rec->record_field_id] =
array(
649 'record_field_id' => $rec->record_field_id,
650 'value' => $rec->{$value}
655 'il_dcl_record_field' =>
array(
'ids' => $ids )
657 case 'il_dcl_tableview':
658 $set = $this->db->query(
'SELECT * FROM il_dcl_tview_set WHERE tableview_id = ' . $this->db->quote($a_rec[
'id'],
'integer'));
659 $ids = $this->
buildCache(
'il_dcl_tview_set', $set);
662 'il_dcl_tview_set' =>
array(
'ids' => $ids )
664 case 'il_dcl_record_field':
665 $record_field_id = $a_rec[
'id'];
666 $storage_loc = $this->record_field_ids_2_storage[$record_field_id];
669 "il_dcl_stloc{$storage_loc}_value" =>
array(
'ids' =>
array( $record_field_id ) )
684 public function readData($a_entity, $a_version, $a_ids) {
686 if (!is_array($a_ids)) {
687 $a_ids =
array( $a_ids );
702 foreach ($a_ids as $dcl_id) {
707 'title' => $obj->getTitle(),
708 'description' => $obj->getDescription(),
709 'is_online' => $obj->getOnline(),
710 'rating' => $obj->getRating(),
711 'public_notes' => $obj->getPublicNotes(),
712 'approval' => $obj->getApproval(),
713 'notification' => $obj->getNotification(),
715 $this->caches[
'dcl'][$dcl_id] =
$data;
722 foreach ($a_ids as $id) {
739 $fields = array_keys($this->
getTypes($a_entity,
''));
741 while ($rec = $this->db->fetchObject($set)) {
743 foreach ($fields as $field) {
744 $data[$field] = $rec->{$field};
747 $this->caches[$a_entity][$id] =
$data;
$record_field_ids_2_storage
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)
Class ilDclBaseFieldModel.
readData($a_entity, $a_version, $a_ids)
Read data from Cache for a given entity and ID(s)
Base class for ILIAS Exception handling.
static getFieldCache($field_id=0)
Class ilDclFieldProperty.
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) ...
const INPUTFORMAT_REFERENCELIST
getCache($a_entity)
Get cached data from a given entity.
static getTableCache($table_id=0)
Class ilDclBaseFieldModel.
Class ilDclTableViewFieldSetting.
static getInstance($tableview_id, $field_id)
buildCache($a_entity, $set)
Helper method to build cache for data of all entities.
DataCollection dataset class.
static getRecordCache($record_id=0)
getTargetId()
get target id
const INPUTFORMAT_ILIAS_REF
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)
const INPUTFORMAT_REFERENCE
Class ilDclBaseRecordModel.
$import_record_field_cache
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...)
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getXmlNamespace($a_entity, $a_schema_version)
Class ilObjDataCollection.