ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilDclBaseRecordModel.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once './Modules/DataCollection/classes/Fields/Base/class.ilDclBaseRecordFieldModel.php';
5require_once './Modules/DataCollection/classes/Fields/Base/class.ilDclDatatype.php';
6require_once './Services/Exceptions/classes/class.ilException.php';
7require_once './Services/User/classes/class.ilUserUtil.php';
8require_once('./Services/Object/classes/class.ilCommonActionDispatcherGUI.php');
9require_once('./Modules/DataCollection/classes/class.ilObjDataCollection.php');
10require_once('./Modules/DataCollection/classes/Table/class.ilDclTable.php');
11require_once('./Services/Notes/classes/class.ilNote.php');
12require_once('./Services/Notes/classes/class.ilNoteGUI.php');
13
27
31 protected $recordfields;
35 protected $id;
39 protected $table_id;
43 protected $table;
49 protected $last_edit_by;
53 protected $owner;
57 protected $last_update;
61 protected $create_date;
65 protected $comments;
66
67
71 public function __construct($a_id = 0) {
72 if ($a_id != 0) {
73 $this->id = $a_id;
74 $this->doRead();
75 }
76 }
77
78
83 private function fixDate($value) {
84 global $DIC;
85 if ($DIC['ilDB']->getDBType() != ilDBConstants::TYPE_ORACLE) {
86 return $value;
87 }
88
89 $date = explode(' ', $value);
90
91 return $date[0];
92 }
93
94
98 public function doUpdate($omit_notification = false) {
99 global $DIC;
100 $ilDB = $DIC['ilDB'];
101
102 $values = array(
103 "table_id" => array(
104 "integer",
105 $this->getTableId()
106 ),
107 "last_update" => array(
108 "date",
109 $this->fixDate($this->getLastUpdate())
110 ),
111 "owner" => array(
112 "text",
113 $this->getOwner()
114 ),
115 "last_edit_by" => array(
116 "text",
117 $this->getLastEditBy()
118 )
119 );
120 $ilDB->update("il_dcl_record", $values, array(
121 "id" => array(
122 "integer",
123 $this->id
124 )
125 ));
126
127 foreach ($this->getRecordFields() as $recordfield) {
128 $recordfield->doUpdate();
129 }
130
131 //TODO: add event raise
132 if (!$omit_notification) {
133 ilObjDataCollection::sendNotification("update_record", $this->getTableId(), $this->id);
134 }
135 }
136
137
141 public function doRead() {
142 global $DIC;
143 $ilDB = $DIC['ilDB'];
144 //build query
145 $query = "Select * From il_dcl_record WHERE id = " . $ilDB->quote($this->getId(), "integer") . " ORDER BY id";
146
147 $set = $ilDB->query($query);
148 $rec = $ilDB->fetchAssoc($set);
149
150 $this->setTableId($rec["table_id"]);
151 $this->setCreateDate($rec["create_date"]);
152 $this->setLastUpdate($rec["last_update"]);
153 $this->setOwner($rec["owner"]);
154 $this->setLastEditBy($rec["last_edit_by"]);
155 }
156
157
161 public function doCreate() {
162 global $DIC;
163 $ilDB = $DIC['ilDB'];
164
165 if (! ilDclTable::_tableExists($this->getTableId())) {
166 throw new ilException("The field does not have a related table!");
167 }
168
169 $id = $ilDB->nextId("il_dcl_record");
170 $this->setId($id);
171 $query = "INSERT INTO il_dcl_record (
172 id,
173 table_id,
174 create_date,
175 Last_update,
176 owner,
177 last_edit_by
178 ) VALUES (" . $ilDB->quote($this->getId(), "integer") . "," . $ilDB->quote($this->getTableId(), "integer") . ","
179 . $ilDB->quote($this->getCreateDate(), "timestamp") . "," . $ilDB->quote($this->getLastUpdate(), "timestamp") . ","
180 . $ilDB->quote($this->getOwner(), "integer") . "," . $ilDB->quote($this->getLastEditBy(), "integer") . "
181 )";
182 $ilDB->manipulate($query);
183
184 $this->loadRecordFields();
185 foreach ($this->getRecordFields() as $recordField) {
186 $recordField->doCreate();
187 }
188
189 $this->getTable()->loadRecords();
190 }
191
192
196 public function deleteField($field_id) {
197 $this->loadRecordFields();
198 $this->recordfields[$field_id]->delete();
199 if (count($this->recordfields) == 1) {
200 $this->doDelete();
201 }
202 }
203
204
210 public function setId($a_id) {
211 $this->id = $a_id;
212 }
213
214
220 public function getId() {
221 return $this->id;
222 }
223
224
230 public function setTableId($a_id) {
231 $this->table_id = $a_id;
232 }
233
234
240 public function getTableId() {
241 return $this->table_id;
242 }
243
244
250 public function setCreateDate($a_datetime) {
251 $this->create_date = $a_datetime;
252 }
253
254
260 public function getCreateDate() {
261 return $this->create_date;
262 }
263
264
270 public function setLastUpdate($a_datetime) {
271 $this->last_update = $a_datetime;
272 }
273
274
280 public function getLastUpdate() {
281 return $this->last_update;
282 }
283
284
290 public function setOwner($a_id) {
291 $this->owner = $a_id;
292 }
293
294
300 public function getOwner() {
301 return $this->owner;
302 }
303
304
305 /*
306 * getLastEditBy
307 */
308 public function getLastEditBy() {
309 return $this->last_edit_by;
310 }
311
312
313 /*
314 * setLastEditBy
315 */
316 public function setLastEditBy($last_edit_by) {
317 $this->last_edit_by = $last_edit_by;
318 }
319
320
327 public function setRecordFieldValue($field_id, $value) {
328 $this->loadRecordFields();
330 $this->setStandardField($field_id, $value);
331 } else {
332 $this->loadTable();
333 $record_field = $this->recordfields[$field_id];
334
335
336 $this->recordfields[$field_id]->setValue($value);
337 }
338 }
339
346 public function setRecordFieldValueFromForm($field_id, &$form) {
347 $this->loadRecordFields();
349 $this->setStandardFieldFromForm($field_id, $form);
350 } else {
351 $this->loadTable();
352 $this->recordfields[$field_id]->setValueFromForm($form);
353 }
354 }
355
363 public function getRecordFieldValueFromExcel($excel, $row, $col, $field) {
364 $this->loadRecordFields();
365 return $this->recordfields[$field->getId()]->getValueFromExcel($excel, $row, $col);
366 }
367
368
373 public function getRecordFieldValues() {
374 $this->loadRecordFields();
375 $return = array();
376 foreach ($this->recordfields as $id => $record_field) {
377 $return[$id] = $record_field->getValue();
378 }
379
380 return $return;
381 }
382
390 public function getRecordFieldValue($field_id) {
391 if ($field_id === NULL) {
392 return NULL;
393 }
394 $this->loadRecordFields();
396 return $this->getStandardField($field_id);
397 } else {
398 return $this->recordfields[$field_id]->getValue();
399 }
400 }
401
402
410 public function getRecordFieldRepresentationValue($field_id) {
411 if ($field_id === NULL) {
412 return NULL;
413 }
414 $this->loadRecordFields();
416 return $this->getStandardField($field_id);
417 } else {
418 return $this->recordfields[$field_id]->getValueForRepresentation();
419 }
420 }
421
422
430 public function getRecordFieldExportValue($field_id) {
431 $this->loadRecordFields();
433 return $this->getStandardFieldHTML($field_id);
434 } else {
435 return $this->recordfields[$field_id]->getExportValue();
436 }
437 }
438
446 public function getRecordFieldPlainText($field_id) {
447 $this->loadRecordFields();
449 return $this->getStandardFieldHTML($field_id);
450 } else {
451 return $this->recordfields[$field_id]->getPlainText();
452 }
453 }
454
461 public function fillRecordFieldExcelExport(ilExcel $worksheet, &$row, &$col, $field_id) {
462 $this->loadRecordFields();
464 $worksheet->setCell($row, $col, $this->getStandardFieldHTML($field_id));
465 $col++;
466 } else {
467 $this->recordfields[$field_id]->fillExcelExport($worksheet, $row, $col);
468 }
469 }
470
477 public function getRecordFieldHTML($field_id, array $options = array()) {
478 $this->loadRecordFields();
480 $html = $this->getStandardFieldHTML($field_id, $options);
481 } else {
482 if (is_object($this->recordfields[$field_id])) {
483 $html = $this->recordfields[$field_id]->getRecordRepresentation()->getHTML();
484 } else {
485 $html = '';
486 }
487 }
488
489 // This is a workaround as templating in ILIAS currently has some issues with curly brackets.see: http://www.ilias.de/mantis/view.php?id=12681#bugnotes
490 // SW 16.07.2014 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
491 // $html = str_ireplace("{", "&#123;", $html);
492 // $html = str_ireplace("}", "&#125;", $html);
493
494 return $html;
495 }
496
497
504 public function getRecordFieldSortingValue($field_id, array $options = array()) {
505 $this->loadRecordFields();
507 $html = $this->getStandardFieldHTML($field_id, $options);
508 } else {
509 if (is_object($this->recordfields[$field_id])) {
510 $html = $this->recordfields[$field_id]->getSortingValue();
511 } else {
512 $html = '';
513 }
514 }
515
516 // This is a workaround as templating in ILIAS currently has some issues with curly brackets.see: http://www.ilias.de/mantis/view.php?id=12681#bugnotes
517 // SW 16.07.2014 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
518 // $html = str_ireplace("{", "&#123;", $html);
519 // $html = str_ireplace("}", "&#125;", $html);
520
521 return $html;
522 }
523
530 public function getRecordFieldSingleHTML($field_id, array $options = array()) {
531 $this->loadRecordFields();
532
534 $html = $this->getStandardFieldHTML($field_id);
535 } else {
536 $field = $this->recordfields[$field_id];
541 $html = $field->getRecordRepresentation()->getSingleHTML($options, false);
542 }
543 // This is a workaround as templating in ILIAS currently has some issues with curly brackets.see: http://www.ilias.de/mantis/view.php?id=12681#bugnotes
544 // SW 14.10.2015 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
545// $html = str_ireplace("{", "&#123;", $html);
546// $html = str_ireplace("}", "&#125;", $html);
547
548 return $html;
549 }
550
555 public function fillRecordFieldFormInput($field_id, &$form) {
556 $this->loadRecordFields();
558 $this->fillStandardFieldFormInput($field_id, $form);
559 } else {
560 $this->recordfields[$field_id]->getRecordRepresentation()->fillFormInput($form);
561 }
562 }
563
564
569 protected function setStandardFieldFromForm($field_id, &$form) {
570 if ($item = $form->getItemByPostVar("field_".$field_id)) {
571 $this->setStandardField($item->getValue());
572 }
573 }
574
579 protected function setStandardField($field_id, $value) {
580 switch ($field_id) {
581 case "last_edit_by":
582 $this->setLastEditBy($value);
583
584 return;
585 }
586 $this->$field_id = $value;
587 }
588
593 protected function fillStandardFieldFormInput($field_id, &$form) {
594 if ($item = $form->getItemByPostVar('field_' . $field_id)) {
595 $item->setValue($this->getStandardField($field_id));
596 }
597 }
598
599
605 protected function getStandardField($field_id) {
606 switch ($field_id) {
607 case "last_edit_by":
608 return $this->getLastEditBy();
609 break;
610 case 'owner':
611 $usr_data = ilObjUser::_lookupName($this->getOwner());
612
613 return $usr_data['login'];
614 break;
615 }
616
617 return $this->$field_id;
618 }
619
620
627 public function getStandardFieldHTML($field_id, array $options = array()) {
628 switch ($field_id) {
629 case 'id':
630 return $this->getId();
631 case 'owner':
633 case 'last_edit_by':
635 case 'last_update':
637 case 'create_date':
639 case 'comments':
640 $nComments = count($this->getComments());
641 $ajax_hash = ilCommonActionDispatcherGUI::buildAjaxHash(1, $_GET['ref_id'], 'dcl', $this->table->getCollectionObject()
642 ->getId(), 'dcl', $this->getId());
643 $ajax_link = ilNoteGUI::getListCommentsJSCall($ajax_hash, '');
644
645 return "<a class='dcl_comment' href='#' onclick=\"return " . $ajax_link . "\">
646 <img src='" . ilUtil::getImagePath("comment_unlabeled.svg")
647 . "' alt='{$nComments} Comments'><span class='ilHActProp'>{$nComments}</span></a>";
648 }
649 }
650
656 public function getStandardFieldPlainText($field_id) {
657 switch ($field_id) {
658 case 'comments':
659 return count(ilNote::_getNotesOfObject($this->table->getCollectionObject()->getId(), $this->getId(),"dcl", 2,
660 false, "", "y", true, true));
661 default:
662 return strip_tags($this->getStandardFieldHTML($field_id));
663 }
664 }
665
666
670 private function loadRecordFields() {
671 if ($this->recordfields == NULL) {
672 $this->loadTable();
673 $recordfields = array();
674 foreach ($this->table->getRecordFields() as $field) {
675 if ($recordfields[$field->getId()] == NULL) {
676 $recordfields[$field->getId()] = ilDclCache::getRecordFieldCache($this, $field);
677 }
678 }
679
680 $this->recordfields = $recordfields;
681 }
682 }
683
684
688 private function loadTable() {
689 if ($this->table == NULL) {
690 $this->table = ilDclCache::getTableCache($this->getTableId());
691 }
692 }
693
694
700 public function getRecordField($field_id) {
701 $this->loadRecordFields();
702
703 return $this->recordfields[$field_id];
704 }
705
706
712 public function doDelete($omit_notification = false) {
713 global $DIC;
714 $ilDB = $DIC['ilDB'];
715 $ilAppEventHandler = $DIC['ilAppEventHandler'];
716
717 $this->loadRecordFields();
718 foreach ($this->recordfields as $recordfield) {
719
720 if ($recordfield->getField()->getDatatypeId() == ilDclDatatype::INPUTFORMAT_FILE) {
721 $this->deleteFile($recordfield->getValue());
722 }
723
724 if ($recordfield->getField()->getDatatypeId() == ilDclDatatype::INPUTFORMAT_MOB) {
725 $this->deleteMob($recordfield->getValue());
726 }
727
728 $recordfield->delete();
729 }
730
731 $query = "DELETE FROM il_dcl_record WHERE id = " . $ilDB->quote($this->getId(), "integer");
732 $ilDB->manipulate($query);
733
734 $this->table->loadRecords();
735
736 if (!$omit_notification) {
737 ilObjDataCollection::sendNotification("delete_record", $this->getTableId(), $this->getId());
738
739 $ilAppEventHandler->raise('Modules/DataCollection',
740 'deleteRecord',
741 array(
742 'dcl' => ilDclCache::getTableCache($this->getTableId())->getCollectionObject(),
743 'table_id' => $this->table_id,
744 'record_id' => $this->getId(),
745 'record' => $this,
746 ));
747 }
748
749 }
750
751
752 // TODO: Find better way to copy data (including all references)
757 public function cloneStructure($original_id, $new_fields){
758 $original = ilDclCache::getRecordCache($original_id);
759 $this->setCreateDate($original->getCreateDate());
760 $this->setLastEditBy($original->getLastEditBy());
761 $this->setLastUpdate($original->getLastUpdate());
762 $this->setOwner($original->getOwner());
763 $this->doCreate();
764 foreach($new_fields as $old => $new){
765 $old_rec_field = $original->getRecordField($old);
766 $new_rec_field = ilDclCache::getRecordFieldCache($this, $new);
767 $new_rec_field->cloneStructure($old_rec_field);
768 $this->recordfields[] = $new_rec_field;
769 }
770
771 // mandatory for all cloning functions
773 }
774
780 public function deleteFile($obj_id) {
781 if (ilObject2::_exists($obj_id, false)) {
782 $file = new ilObjFile($obj_id, false);
783 $file->delete();
784 }
785 }
786
787
793 public function deleteMob($obj_id) {
794 if (ilObject2::_lookupObjId($obj_id)) {
795 $mob = new ilObjMediaObject($obj_id);
796 $mob->delete();
797 }
798 }
799
800
806 public function passThroughFilter(array $filter) {
807 $this->loadTable();
808 // If one field returns false, the whole record does not pass the filter #performance-improvements
809 foreach ($this->table->getFilterableFields() as $field) {
810 if (! isset($filter["filter_" . $field->getId()]) || ! $filter["filter_" . $field->getId()]) {
811 continue;
812 }
813 if (! ilDclCache::getFieldRepresentation($field)->passThroughFilter($this, $filter["filter_" . $field->getId()])) {
814 return false;
815 }
816 }
817
818 return true;
819 }
820
821
827 public function hasPermissionToEdit($ref_id) {
828 return $this->getTable()->hasPermissionToEditRecord($ref_id, $this);
829 }
830
831
838 return $this->getTable()->hasPermissionToDeleteRecord($ref_id, $this);
839 }
840
841
847 public function hasPermissionToView($ref_id) {
848 return $this->getTable()->hasPermissionToViewRecord($ref_id, $this);
849 }
850
851
855 public function getRecordFields() {
856 $this->loadRecordFields();
857
858 return $this->recordfields;
859 }
860
861
865 public function getTable() {
866 $this->loadTable();
867
868 return $this->table;
869 }
870
871
877 public function getComments() {
878 if ($this->comments === NULL) {
879 $this->comments = ilNote::_getNotesOfObject($this->table->getCollectionObject()->getId(), $this->getId(), 'dcl', IL_NOTE_PUBLIC);
880 }
881
882 return $this->comments;
883 }
884}
$worksheet
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
const IL_NOTE_PUBLIC
Definition: class.ilNote.php:5
static buildAjaxHash($a_node_type, $a_node_id, $a_obj_type, $a_obj_id, $a_sub_type=null, $a_sub_id=null)
Build ajax hash.
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
Class ilDclBaseRecordModel.
setStandardFieldFromForm($field_id, &$form)
fillRecordFieldFormInput($field_id, &$form)
getComments()
Get all comments of this record.
loadRecordFields()
Load record fields.
fillStandardFieldFormInput($field_id, &$form)
setLastUpdate($a_datetime)
Set Last Update Date.
deleteFile($obj_id)
Delete a file.
getRecordFieldExportValue($field_id)
Get Field Export Value.
setRecordFieldValueFromForm($field_id, &$form)
Set a field value.
cloneStructure($original_id, $new_fields)
getRecordFieldPlainText($field_id)
Get Field Export Value.
setCreateDate($a_datetime)
Set Creation Date.
doDelete($omit_notification=false)
Delete.
doUpdate($omit_notification=false)
doUpdate
getRecordFieldSortingValue($field_id, array $options=array())
getRecordFieldValueFromExcel($excel, $row, $col, $field)
getRecordFieldValue($field_id)
Get Field Value.
getLastUpdate()
Get Last Update Date.
getStandardFieldHTML($field_id, array $options=array())
getRecordFieldHTML($field_id, array $options=array())
getRecordFieldRepresentationValue($field_id)
Get Field Value for Representation in a Form.
fillRecordFieldExcelExport(ilExcel $worksheet, &$row, &$col, $field_id)
setRecordFieldValue($field_id, $value)
Set a field value.
static getRecordFieldCache($record, $field)
static getTableCache($table_id=0)
static getRecordCache($record_id=0)
static setCloneOf($old, $new, $type)
static getFieldRepresentation(ilDclBaseFieldModel $field)
static _isStandardField($field_id)
static _tableExists($table_id)
Base class for ILIAS Exception handling.
static getListCommentsJSCall($a_hash, $a_update_code=null)
Get list comments js call.
static _getNotesOfObject($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_type=IL_NOTE_PRIVATE, $a_incl_sub=false, $a_filter="", $a_all_public="y", $a_repository_mode=true, $a_sort_ascending=false)
get all notes related to a specific object
Class ilObjFile.
Class ilObjMediaObject.
static _lookupName($a_user_id)
lookup user name
static _lookupObjId($a_id)
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static getNamePresentation($a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false)
Default behaviour is:
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$html
Definition: example_001.php:87
$old
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
$ref_id
Definition: sahs_server.php:39
global $ilDB
if(!is_array($argv)) $options
global $DIC