4 require_once(
"./Services/DataSet/classes/class.ilDataSet.php");
5 require_once(
'class.ilDataCollectionCache.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_view' => array(),
60 'il_dcl_viewdefinition' => array(),
106 return array(
'4.5.0' );
119 if (!in_array($a_entity, array_keys($this->caches))) {
120 throw new ilException(
"Entity '$a_entity' does not exist in Cache");
123 return $this->caches[$a_entity];
134 return 'http://www.ilias.de/xml/Modules/DataCollection/' . $a_entity;
145 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version) {
148 if($new_id = $a_mapping->getMapping(
'Services/Container',
'objs',$a_rec[
'id']))
155 $newObj->create(
true);
158 $newObj->setTitle($a_rec[
'title']);
159 $newObj->setDescription($a_rec[
'description']);
160 $newObj->setApproval($a_rec[
'approval']);
161 $newObj->setPublicNotes($a_rec[
'public_notes']);
162 $newObj->setNotification($a_rec[
'notification']);
163 $newObj->setPublicNotes($a_rec[
'public_notes']);
164 $newObj->setOnline(
false);
165 $newObj->setRating($a_rec[
'rating']);
168 $this->import_dc_object = $newObj;
169 $a_mapping->addMapping(
'Modules/DataCollection',
'dcl', $a_rec[
'id'], $newObj->getId());
173 $table = ($this->count_imported_tables
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->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 if ($this->count_imported_tables > 0) {
192 $table->doCreate(
false);
195 $this->count_imported_tables ++;
197 $set = $this->db->query(
'SELECT * FROM il_dcl_view WHERE table_id = ' . $this->db->quote($table->getId(),
'integer'));
199 while (
$row = $this->db->fetchObject($set)) {
200 $view_ids[] =
$row->id;
202 if (count($view_ids)) {
203 $this->db->manipulate(
"DELETE FROM il_dcl_viewdefinition WHERE view_id IN (" . implode(
',', $view_ids) .
")");
205 $this->db->manipulate(
"DELETE FROM il_dcl_view WHERE table_id = " . $this->db->quote($table->getId(),
'integer'));
207 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_table', $a_rec[
'id'], $table->getId());
210 $new_table_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_table', $a_rec[
'table_id']);
213 $field->setTableId($new_table_id);
214 $field->setDatatypeId($a_rec[
'datatype_id']);
215 $field->setTitle($a_rec[
'title']);
216 $field->setDescription($a_rec[
'description']);
217 $field->setRequired($a_rec[
'required']);
218 $field->setUnique($a_rec[
'is_unique']);
219 $field->setLocked($a_rec[
'is_locked']);
221 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_field', $a_rec[
'id'], $field->getId());
224 if ($table && $table->getDefaultSortField() == $a_rec[
'id']) {
225 $table->setDefaultSortField($field->getId());
230 case 'il_dcl_record':
231 $new_table_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_table', $a_rec[
'table_id']);
234 $record->setTableId($new_table_id);
236 $record->setCreateDate($datetime);
237 $record->setLastUpdate($datetime);
238 $record->setOwner($this->user->getId());
239 $record->setLastEditBy($this->user->getId());
241 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_record', $a_rec[
'id'], $record->getId());
245 $new_table_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_table', $a_rec[
'table_id']);
247 if ($a_rec[
'type'] == 0 && $a_rec[
'formtype'] == 0) {
251 $definition->setTableId($new_table_id);
252 $definition->create(
true);
254 $a_mapping->addMapping(
'Services/COPage',
'pg',
'dclf:' . $a_rec[
'id'],
'dclf:' . $definition->getId());
255 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_view', $a_rec[
'id'], $definition->getId());
258 $view_id = $this->db->nextId(
"il_dcl_view");
259 $sql =
"INSERT INTO il_dcl_view (id, table_id, type, formtype) VALUES (" . $this->db->quote($view_id,
"integer") .
", "
260 . $this->db->quote($new_table_id,
"integer") .
", " . $this->db->quote($a_rec[
'type'],
"integer") .
", "
261 . $this->db->quote($a_rec[
'formtype'],
"integer") .
")";
262 $this->db->manipulate($sql);
263 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_view', $a_rec[
'id'], $view_id);
267 case 'il_dcl_viewdefinition':
268 $new_view_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_view', $a_rec[
'view_id']);
269 $new_field_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_field', $a_rec[
'field']);
270 $field = ($new_field_id) ? $new_field_id : $a_rec[
'field'];
273 'INSERT INTO il_dcl_viewdefinition (view_id, field, field_order, is_set) VALUES (' . $this->db->quote($new_view_id,
'integer')
274 .
', ' . $this->db->quote($field,
'text') .
', ' . $this->db->quote($a_rec[
'field_order'],
'integer') .
', '
275 . $this->db->quote($a_rec[
'is_set'],
'integer') .
')';
276 $this->db->manipulate($sql);
279 case 'il_dcl_field_prop':
280 $new_field_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_field', $a_rec[
'field_id']);
283 $prop->setFieldId($new_field_id);
284 $prop->setDatatypePropertyId($a_rec[
'datatype_prop_id']);
287 $value = $a_rec[
'value'];
290 if (in_array($prop->getDatatypePropertyId(), $refs)) {
291 $new_field_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_field', $a_rec[
'value']);
292 if ($new_field_id ===
false) {
297 $prop->setValue($value);
299 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_field_prop', $a_rec[
'id'], $prop->getId());
301 $this->import_temp_refs_props[$prop->getId()] = $a_rec[
'value'];
305 case 'il_dcl_record_field':
306 $record_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_record', $a_rec[
'record_id']);
307 $field_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_field', $a_rec[
'field_id']);
308 if ($record_id && $field_id) {
312 $a_mapping->addMapping(
'Modules/DataCollection',
'il_dcl_record_field', $a_rec[
'id'], $record_field->getId());
313 $this->import_record_field_cache[$record_field->getId()] = $record_field;
316 case 'il_dcl_stloc1_value':
317 case 'il_dcl_stloc2_value':
318 case 'il_dcl_stloc3_value':
319 $new_record_field_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_record_field', $a_rec[
'record_field_id']);
320 if ($new_record_field_id) {
322 $record_field = $this->import_record_field_cache[$new_record_field_id];
323 if (is_object($record_field)) {
326 switch ($record_field->getField()->getDatatypeId()) {
329 $new_mob_id = $a_mapping->getMapping(
'Services/MediaObjects',
'mob', $a_rec[
'value']);
330 $value = ($new_mob_id) ? (
int)$new_mob_id : NULL;
331 $this->import_temp_new_mob_ids[] = $new_mob_id;
334 $new_file_id = $a_mapping->getMapping(
'Modules/File',
'file', $a_rec[
'value']);
335 $value = ($new_file_id) ? (
int)$new_file_id : NULL;
338 case ilDataCollectioNDatatype::INPUTFORMAT_REFERENCELIST:
341 $new_record_id = $a_mapping->getMapping(
'Modules/DataCollection',
'il_dcl_record', $a_rec[
'value']);
342 if ($new_record_id ===
false) {
343 $this->import_temp_refs[$new_record_field_id] = $a_rec[
'value'];
345 $value = ($new_record_id) ? (
int)$new_record_id : NULL;
351 $value = $a_rec[
'value'];
352 if ($a_entity ==
'il_dcl_stloc3_value' && (is_null($value) || empty($value))) {
353 $value =
'0000-00-00 00:00:00';
356 $record_field->setValue($value,
true);
357 $record_field->doUpdate();
371 foreach ($this->import_temp_new_mob_ids as $new_mob_id) {
374 foreach ($this->import_temp_refs as $record_field_id => $old_record_id) {
375 $new_record_id = $a_mapping->
getMapping(
'Modules/DataCollection',
'il_dcl_record', $old_record_id);
376 $value = ($new_record_id) ? (
int)$new_record_id : NULL;
378 $record_field = $this->import_record_field_cache[$record_field_id];
379 $record_field->setValue($value,
true);
380 $record_field->doUpdate();
382 foreach ($this->import_temp_refs_props as $field_prop_id => $old_field_id) {
383 $new_field_id = $a_mapping->
getMapping(
'Modules/DataCollection',
'il_dcl_field', $old_field_id);
384 $value = ($new_field_id) ? (
int)$new_field_id : NULL;
386 $field_prop->setValue($value);
387 $field_prop->doUpdate();
400 protected function getTypes($a_entity, $a_version) {
406 "description" =>
"text",
407 'main_table_id' =>
'integer',
408 'is_online' =>
'integer',
409 'rating' =>
'integer',
410 'public_notes' =>
'integer',
411 'approval' =>
'integer',
412 'notification' =>
'integer',
417 'obj_id' =>
'integer',
419 'add_perm' =>
'integer',
420 'edit_perm' =>
'integer',
421 'delete_perm' =>
'integer',
422 'edit_by_owner' =>
'integer',
423 'limited' =>
'integer',
424 'limit_start' =>
'text',
425 'limit_end' =>
'text',
426 'is_visible' =>
'integer',
427 'export_enabled' =>
'integer',
428 'default_sort_field_id' =>
'text',
429 'default_sort_field_order' =>
'text',
430 'description' =>
'text',
431 'public_comments' =>
'integer',
432 'view_own_records_perm' =>
'integer',
437 'table_id' =>
'integer',
439 'description' =>
'text',
440 'datatype_id' =>
'integer',
441 'required' =>
'integer',
442 'is_unique' =>
'integer',
443 'is_locked' =>
'integer',
445 case 'il_dcl_field_prop':
448 'field_id' =>
'integer',
449 'datatype_prop_id' =>
'integer',
450 'value' =>
'integer',
452 case 'il_dcl_record':
455 'table_id' =>
'integer',
457 case 'il_dcl_record_field':
460 'record_id' =>
'integer',
461 'field_id' =>
'integer',
463 case 'il_dcl_stloc1_value':
466 'record_field_id' =>
'integer',
469 case 'il_dcl_stloc2_value':
472 'record_field_id' =>
'integer',
475 case 'il_dcl_stloc3_value':
478 'record_field_id' =>
'integer',
484 'table_id' =>
'integer',
486 'formtype' =>
'integer',
488 case 'il_dcl_viewdefinition':
490 'view_id' =>
'integer',
492 'field_order' =>
'integer',
493 'is_set' =>
'integer',
512 if (!$a_rec && !$a_ids) {
517 $set = $this->db->query(
'SELECT * FROM il_dcl_table WHERE obj_id = ' . $this->db->quote($a_rec[
'id'],
'integer') .
' ORDER BY id');
518 $ids = $this->
buildCache(
'il_dcl_table', $set);
521 'il_dcl_table' => array(
'ids' => $ids ),
525 $set = $this->db->query(
'SELECT * FROM il_dcl_record WHERE table_id = ' . $this->db->quote($a_rec[
'id'],
'integer'));
526 $ids_records = $this->
buildCache(
'il_dcl_record', $set);
527 $set = $this->db->query(
'SELECT * FROM il_dcl_field WHERE table_id = ' . $this->db->quote($a_rec[
'id'],
'integer'));
528 $ids_fields = $this->
buildCache(
'il_dcl_field', $set);
529 $set = $this->db->query(
'SELECT * FROM il_dcl_view WHERE table_id = ' . $this->db->quote($a_rec[
'id'],
'integer'));
530 $ids_views = $this->
buildCache(
'il_dcl_view', $set);
533 'il_dcl_field' => array(
'ids' => $ids_fields ),
534 'il_dcl_record' => array(
'ids' => $ids_records ),
535 'il_dcl_view' => array(
'ids' => $ids_views ),
538 $set = $this->db->query(
'SELECT * FROM il_dcl_field_prop WHERE field_id = ' . $this->db->quote($a_rec[
'id'],
'integer'));
539 $ids = $this->
buildCache(
'il_dcl_field_prop', $set);
542 'il_dcl_field_prop' => array(
'ids' => $ids ),
544 case 'il_dcl_record':
545 $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)'
546 .
' INNER JOIN il_dcl_datatype AS d ON (f.datatype_id = d.id) ' .
' WHERE rf.record_id = '
547 . $this->db->quote($a_rec[
'id'],
'integer');
548 $set = $this->db->query($sql);
549 $ids = $this->
buildCache(
'il_dcl_record_field', $set);
551 $set = $this->db->query($sql);
552 while ($rec = $this->db->fetchObject($set)) {
553 $this->record_field_ids_2_storage[$rec->id] = $rec->storage_location;
557 '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 '
558 .
'LEFT JOIN il_dcl_stloc1_value AS st1 ON (st1.record_field_id = rf.id) '
559 .
'LEFT JOIN il_dcl_stloc2_value AS st2 ON (st2.record_field_id = rf.id) '
560 .
'LEFT JOIN il_dcl_stloc3_value AS st3 ON (st3.record_field_id = rf.id) ' .
'WHERE rf.record_id = '
561 . $this->db->quote($a_rec[
'id'],
'integer');
562 $set = $this->db->query($sql);
564 while ($rec = $this->db->fetchObject($set)) {
565 $stloc = $this->record_field_ids_2_storage[$rec->record_field_id];
566 $value =
"value{$stloc}";
568 $this->caches[
"il_dcl_stloc{$stloc}_value"][$rec->record_field_id] = array(
569 'record_field_id' => $rec->record_field_id,
570 'value' => $rec->{$value}
575 'il_dcl_record_field' => array(
'ids' => $ids )
578 $set = $this->db->query(
'SELECT * FROM il_dcl_viewdefinition WHERE view_id = ' . $this->db->quote($a_rec[
'id'],
'integer'));
579 $ids = $this->
buildCache(
'il_dcl_viewdefinition', $set);
582 'il_dcl_viewdefinition' => array(
'ids' => $ids )
584 case 'il_dcl_record_field':
585 $record_field_id = $a_rec[
'id'];
586 $storage_loc = $this->record_field_ids_2_storage[$record_field_id];
589 "il_dcl_stloc{$storage_loc}_value" => array(
'ids' => array( $record_field_id ) )
604 public function readData($a_entity, $a_version, $a_ids) {
605 $this->data = array();
606 if (!is_array($a_ids)) {
607 $a_ids = array( $a_ids );
609 $this->_readData($a_entity, $a_ids);
622 foreach ($a_ids as $dcl_id) {
627 'title' => $obj->getTitle(),
628 'description' => $obj->getDescription(),
629 'main_table_id' => $obj->getMainTableId(),
630 'is_online' => $obj->getOnline(),
631 'rating' => $obj->getRating(),
632 'public_notes' => $obj->getPublicNotes(),
633 'approval' => $obj->getApproval(),
634 'notification' => $obj->getNotification(),
636 $this->caches[
'dcl'][$dcl_id] = $data;
637 $this->data[] = $data;
642 $data = $this->getCache($a_entity);
643 foreach ($a_ids as $id) {
644 $this->data[] = $data[$id];
660 $fields = array_keys($this->getTypes($a_entity,
''));
662 while ($rec = $this->db->fetchObject($set)) {
664 foreach ($fields as $field) {
665 $data[$field] = $rec->{$field};
668 $id = ($a_entity ==
'il_dcl_viewdefinition') ? $rec->view_id .
'_' . $rec->field : $rec->id;
669 $this->caches[$a_entity][$id] = $data;