ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
17{
18
22 protected $recordfields;
26 protected $id;
30 protected $table_id;
34 protected $table;
40 protected $last_edit_by;
44 protected $owner;
48 protected $last_update;
52 protected $create_date;
56 protected $comments;
57
58
62 public function __construct($a_id = 0)
63 {
64 if ($a_id != 0) {
65 $this->id = $a_id;
66 $this->doRead();
67 }
68 }
69
70
76 private function fixDate($value)
77 {
78 return $value;
79 }
80
81
85 public function doUpdate($omit_notification = false)
86 {
87 global $DIC;
88 $ilDB = $DIC['ilDB'];
89
90 $values = array(
91 "table_id" => array(
92 "integer",
93 $this->getTableId(),
94 ),
95 "last_update" => array(
96 "date",
97 $this->fixDate($this->getLastUpdate()),
98 ),
99 "owner" => array(
100 "text",
101 $this->getOwner(),
102 ),
103 "last_edit_by" => array(
104 "text",
105 $this->getLastEditBy(),
106 ),
107 );
108 $ilDB->update(
109 "il_dcl_record",
110 $values,
111 array(
112 "id" => array(
113 "integer",
114 $this->id,
115 ),
116 )
117 );
118
119 foreach ($this->getRecordFields() as $recordfield) {
120 $recordfield->doUpdate();
121 }
122
123 //TODO: add event raise
124 if (!$omit_notification) {
125 ilObjDataCollection::sendNotification("update_record", $this->getTableId(), $this->id);
126 }
127 }
128
129
133 public function doRead()
134 {
135 global $DIC;
136 $ilDB = $DIC['ilDB'];
137 //build query
138 $query = "Select * From il_dcl_record WHERE id = " . $ilDB->quote($this->getId(), "integer") . " ORDER BY id";
139
140 $set = $ilDB->query($query);
141 $rec = $ilDB->fetchAssoc($set);
142
143 $this->setTableId($rec["table_id"]);
144 $this->setCreateDate($rec["create_date"]);
145 $this->setLastUpdate($rec["last_update"]);
146 $this->setOwner($rec["owner"]);
147 $this->setLastEditBy($rec["last_edit_by"]);
148 }
149
150
154 public function doCreate()
155 {
156 global $DIC;
157 $ilDB = $DIC['ilDB'];
158
159 if (!ilDclTable::_tableExists($this->getTableId())) {
160 throw new ilException("The field does not have a related table!");
161 }
162
163 $id = $ilDB->nextId("il_dcl_record");
164 $this->setId($id);
165 $query
166 = "INSERT INTO il_dcl_record (
167 id,
168 table_id,
169 create_date,
170 Last_update,
171 owner,
172 last_edit_by
173 ) VALUES (" . $ilDB->quote($this->getId(), "integer") . "," . $ilDB->quote($this->getTableId(), "integer") . ","
174 . $ilDB->quote($this->getCreateDate(), "timestamp") . "," . $ilDB->quote($this->getLastUpdate(), "timestamp") . ","
175 . $ilDB->quote($this->getOwner(), "integer") . "," . $ilDB->quote($this->getLastEditBy(), "integer") . "
176 )";
177 $ilDB->manipulate($query);
178
179 $this->loadRecordFields();
180 foreach ($this->getRecordFields() as $recordField) {
181 $recordField->doCreate();
182 }
183
184 $this->getTable()->loadRecords();
185 }
186
187
191 public function deleteField($field_id)
192 {
193 $this->loadRecordFields();
194 $this->recordfields[$field_id]->delete();
195 if (count($this->recordfields) == 1) {
196 $this->doDelete();
197 }
198 }
199
200
206 public function setId($a_id)
207 {
208 $this->id = $a_id;
209 }
210
211
217 public function getId()
218 {
219 return $this->id;
220 }
221
222
228 public function setTableId($a_id)
229 {
230 $this->table_id = $a_id;
231 }
232
233
239 public function getTableId()
240 {
241 return $this->table_id;
242 }
243
244
250 public function setCreateDate($a_datetime)
251 {
252 $this->create_date = $a_datetime;
253 }
254
255
261 public function getCreateDate()
262 {
263 return $this->create_date;
264 }
265
266
272 public function setLastUpdate($a_datetime)
273 {
274 $this->last_update = $a_datetime;
275 }
276
277
283 public function getLastUpdate()
284 {
285 return $this->last_update;
286 }
287
288
294 public function setOwner($a_id)
295 {
296 $this->owner = $a_id;
297 }
298
299
305 public function getOwner()
306 {
307 return $this->owner;
308 }
309
310
311 /*
312 * getLastEditBy
313 */
314 public function getLastEditBy()
315 {
316 return $this->last_edit_by;
317 }
318
319
320 /*
321 * setLastEditBy
322 */
324 {
325 $this->last_edit_by = $last_edit_by;
326 }
327
328
335 public function setRecordFieldValue($field_id, $value)
336 {
337 $this->loadRecordFields();
339 $this->setStandardField($field_id, $value);
340 } else {
341 $this->loadTable();
342 $record_field = $this->recordfields[$field_id];
343
344 $this->recordfields[$field_id]->setValue($value);
345 }
346 }
347
348
355 public function setRecordFieldValueFromForm($field_id, &$form)
356 {
357 $this->loadRecordFields();
359 $this->setStandardFieldFromForm($field_id, $form);
360 } else {
361 $this->loadTable();
362 $this->recordfields[$field_id]->setValueFromForm($form);
363 }
364 }
365
366
375 public function getRecordFieldValueFromExcel($excel, $row, $col, $field)
376 {
377 $this->loadRecordFields();
378
379 return $this->recordfields[$field->getId()]->getValueFromExcel($excel, $row, $col);
380 }
381
382
389 public function setStandardFieldValueFromExcel($excel, $row, $col, $field)
390 {
391 $value = $field->getValueFromExcel($excel, $row, $col);
392 if ($value) {
393 $this->{$field->getId()} = $value;
394 }
395 }
396
397
402 public function getRecordFieldValues()
403 {
404 $this->loadRecordFields();
405 $return = array();
406 foreach ($this->recordfields as $id => $record_field) {
407 $return[$id] = $record_field->getValue();
408 }
409
410 return $return;
411 }
412
413
421 public function getRecordFieldValue($field_id)
422 {
423 if ($field_id === null) {
424 return null;
425 }
426 $this->loadRecordFields();
428 return $this->getStandardField($field_id);
429 } else {
430 return $this->recordfields[$field_id]->getValue();
431 }
432 }
433
434
442 public function getRecordFieldRepresentationValue($field_id)
443 {
444 if ($field_id === null) {
445 return null;
446 }
447 $this->loadRecordFields();
449 return $this->getStandardField($field_id);
450 } else {
451 return $this->recordfields[$field_id]->getValueForRepresentation();
452 }
453 }
454
455
463 public function getRecordFieldExportValue($field_id)
464 {
465 $this->loadRecordFields();
467 return $this->getStandardFieldHTML($field_id);
468 } else {
469 return $this->recordfields[$field_id]->getExportValue();
470 }
471 }
472
473
481 public function getRecordFieldPlainText($field_id)
482 {
483 $this->loadRecordFields();
485 return $this->getStandardFieldHTML($field_id);
486 } else {
487 return $this->recordfields[$field_id]->getPlainText();
488 }
489 }
490
491
498 public function fillRecordFieldExcelExport(ilExcel $worksheet, &$row, &$col, $field_id)
499 {
500 $this->loadRecordFields();
502 if ($field_id == 'owner') {
503 $worksheet->setCell($row, $col, ilObjUser::_lookupLogin($this->getOwner()));
504 $col++;
505 $name_array = ilObjUser::_lookupName($this->getOwner());
506 $worksheet->setCell($row, $col, $name_array['lastname'] . ', ' . $name_array['firstname']);
507 $col++;
508 } else {
509 $worksheet->setCell($row, $col, $this->getStandardFieldHTML($field_id));
510 $col++;
511 }
512 } else {
513 $this->recordfields[$field_id]->fillExcelExport($worksheet, $row, $col);
514 }
515 }
516
517
523 public function getRecordFieldFormulaValue($field_id)
524 {
525 $this->loadRecordFields();
527 $value = $this->getStandardFieldFormulaValue($field_id);
528 } else {
529 if (is_object($this->recordfields[$field_id])) {
530 $value = $this->recordfields[$field_id]->getFormulaValue();
531 } else {
532 $value = '';
533 }
534 }
535
536 return $value;
537 }
538
545 public function getRecordFieldHTML($field_id, array $options = array())
546 {
547 $this->loadRecordFields();
549 $html = $this->getStandardFieldHTML($field_id, $options);
550 } else {
551 if (is_object($this->recordfields[$field_id])) {
552 $html = $this->recordfields[$field_id]->getRecordRepresentation()->getHTML();
553 } else {
554 $html = '';
555 }
556 }
557
558 // 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
559 // SW 16.07.2014 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
560 // $html = str_ireplace("{", "&#123;", $html);
561 // $html = str_ireplace("}", "&#125;", $html);
562
563 return $html;
564 }
565
566
573 public function getRecordFieldSortingValue($field_id, array $options = array())
574 {
575 $this->loadRecordFields();
577 $html = $this->getStandardFieldHTML($field_id, $options);
578 } else {
579 if (is_object($this->recordfields[$field_id])) {
580 $html = $this->recordfields[$field_id]->getSortingValue();
581 } else {
582 $html = '';
583 }
584 }
585
586 // 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
587 // SW 16.07.2014 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
588 // $html = str_ireplace("{", "&#123;", $html);
589 // $html = str_ireplace("}", "&#125;", $html);
590
591 return $html;
592 }
593
594
601 public function getRecordFieldSingleHTML($field_id, array $options = array())
602 {
603 $this->loadRecordFields();
604
606 $html = $this->getStandardFieldHTML($field_id);
607 } else {
608 $field = $this->recordfields[$field_id];
613 $html = $field->getRecordRepresentation()->getSingleHTML($options, false);
614 }
615 // 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
616 // SW 14.10.2015 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
617 // $html = str_ireplace("{", "&#123;", $html);
618 // $html = str_ireplace("}", "&#125;", $html);
619
620 return $html;
621 }
622
623
628 public function fillRecordFieldFormInput($field_id, &$form)
629 {
630 $this->loadRecordFields();
632 $this->fillStandardFieldFormInput($field_id, $form);
633 } else {
634 $this->recordfields[$field_id]->getRecordRepresentation()->fillFormInput($form);
635 }
636 }
637
638
643 protected function setStandardFieldFromForm($field_id, &$form)
644 {
645 if ($item = $form->getItemByPostVar("field_" . $field_id)) {
646 $this->setStandardField($item->getValue());
647 }
648 }
649
650
655 protected function setStandardField($field_id, $value)
656 {
657 switch ($field_id) {
658 case "last_edit_by":
659 $this->setLastEditBy($value);
660
661 return;
662 }
663 $this->$field_id = $value;
664 }
665
666
671 protected function fillStandardFieldFormInput($field_id, &$form)
672 {
673 if ($item = $form->getItemByPostVar('field_' . $field_id)) {
674 $item->setValue($this->getStandardField($field_id));
675 }
676 }
677
678
684 protected function getStandardField($field_id)
685 {
686 switch ($field_id) {
687 case "last_edit_by":
688 return $this->getLastEditBy();
689 break;
690 case 'owner':
691 $usr_data = ilObjUser::_lookupName($this->getOwner());
692
693 return $usr_data['login'];
694 break;
695 }
696
697 return $this->$field_id;
698 }
699
700
706 public function getStandardFieldFormulaValue($field_id)
707 {
708 return $this->getStandardFieldHTML($field_id);
709 }
710
717 public function getStandardFieldHTML($field_id, array $options = array())
718 {
719 switch ($field_id) {
720 case 'id':
721 return $this->getId();
722 case 'owner':
724 case 'last_edit_by':
726 case 'last_update':
728 case 'create_date':
730 case 'comments':
731 $nComments = count($this->getComments());
733 1,
734 $_GET['ref_id'],
735 'dcl',
736 $this->table->getCollectionObject()
737 ->getId(),
738 'dcl',
739 $this->getId()
740 );
741 $ajax_link = ilNoteGUI::getListCommentsJSCall($ajax_hash, '');
742
743 return "<a class='dcl_comment' href='#' onclick=\"return " . $ajax_link . "\">
744 <img src='" . ilUtil::getImagePath("comment_unlabeled.svg")
745 . "' alt='{$nComments} Comments'><span class='ilHActProp'>{$nComments}</span></a>";
746 }
747 }
748
749
755 public function getStandardFieldPlainText($field_id)
756 {
757 switch ($field_id) {
758 case 'comments':
759 return count(ilNote::_getNotesOfObject(
760 $this->table->getCollectionObject()->getId(),
761 $this->getId(),
762 "dcl",
763 2,
764 false,
765 "",
766 "y",
767 true,
768 true
769 ));
770 default:
771 return strip_tags($this->getStandardFieldHTML($field_id));
772 }
773 }
774
775
779 private function loadRecordFields()
780 {
781 if ($this->recordfields == null) {
782 $this->loadTable();
783 $recordfields = array();
784 foreach ($this->table->getRecordFields() as $field) {
785 if ($recordfields[$field->getId()] == null) {
786 $recordfields[$field->getId()] = ilDclCache::getRecordFieldCache($this, $field);
787 }
788 }
789
790 $this->recordfields = $recordfields;
791 }
792 }
793
794
798 private function loadTable()
799 {
800 if ($this->table == null) {
801 $this->table = ilDclCache::getTableCache($this->getTableId());
802 }
803 }
804
805
811 public function getRecordField($field_id)
812 {
813 $this->loadRecordFields();
814
815 return $this->recordfields[$field_id];
816 }
817
818
824 public function doDelete($omit_notification = false)
825 {
826 global $DIC;
827 $ilDB = $DIC['ilDB'];
828 $ilAppEventHandler = $DIC['ilAppEventHandler'];
829
830 $this->loadRecordFields();
831 foreach ($this->recordfields as $recordfield) {
832 if ($recordfield->getField()->getDatatypeId() == ilDclDatatype::INPUTFORMAT_FILE) {
833 $this->deleteFile($recordfield->getValue());
834 }
835
836 if ($recordfield->getField()->getDatatypeId() == ilDclDatatype::INPUTFORMAT_MOB) {
837 $this->deleteMob($recordfield->getValue());
838 }
839
840 $recordfield->delete();
841 }
842
843 $query = "DELETE FROM il_dcl_record WHERE id = " . $ilDB->quote($this->getId(), "integer");
844 $ilDB->manipulate($query);
845
846 $this->table->loadRecords();
847
848 if (!$omit_notification) {
849 ilObjDataCollection::sendNotification("delete_record", $this->getTableId(), $this->getId());
850
851 $ilAppEventHandler->raise(
852 'Modules/DataCollection',
853 'deleteRecord',
854 array(
855 'dcl' => ilDclCache::getTableCache($this->getTableId())->getCollectionObject(),
856 'table_id' => $this->table_id,
857 'record_id' => $this->getId(),
858 'record' => $this,
859 )
860 );
861 }
862 }
863
864
865 // TODO: Find better way to copy data (including all references)
866
867
872 public function cloneStructure($original_id, $new_fields)
873 {
874 $original = ilDclCache::getRecordCache($original_id);
875 $this->setCreateDate($original->getCreateDate());
876 $this->setLastEditBy($original->getLastEditBy());
877 $this->setLastUpdate($original->getLastUpdate());
878 $this->setOwner($original->getOwner());
879 $this->doCreate();
880 foreach ($new_fields as $old => $new) {
881 $old_rec_field = $original->getRecordField($old);
882 $new_rec_field = ilDclCache::getRecordFieldCache($this, $new);
883 $new_rec_field->cloneStructure($old_rec_field);
884 $this->recordfields[] = $new_rec_field;
885 }
886
887 // mandatory for all cloning functions
889 }
890
891
897 public function deleteFile($obj_id)
898 {
899 if (ilObject2::_exists($obj_id, false)) {
900 $file = new ilObjFile($obj_id, false);
901 $file->delete();
902 }
903 }
904
905
911 public function deleteMob($obj_id)
912 {
913 if (ilObject2::_lookupObjId($obj_id)) {
914 $mob = new ilObjMediaObject($obj_id);
915 $mob->delete();
916 }
917 }
918
919
925 public function passThroughFilter(array $filter)
926 {
927 $this->loadTable();
928 // If one field returns false, the whole record does not pass the filter #performance-improvements
929 foreach ($this->table->getFilterableFields() as $field) {
930 if (!isset($filter["filter_" . $field->getId()]) || !$filter["filter_" . $field->getId()]) {
931 continue;
932 }
933 if (!ilDclCache::getFieldRepresentation($field)->passThroughFilter($this, $filter["filter_" . $field->getId()])) {
934 return false;
935 }
936 }
937
938 return true;
939 }
940
941
947 public function hasPermissionToEdit($ref_id)
948 {
949 return $this->getTable()->hasPermissionToEditRecord($ref_id, $this);
950 }
951
952
958 public function hasPermissionToDelete($ref_id)
959 {
960 return $this->getTable()->hasPermissionToDeleteRecord($ref_id, $this);
961 }
962
963
969 public function hasPermissionToView($ref_id)
970 {
971 return $this->getTable()->hasPermissionToViewRecord($ref_id, $this);
972 }
973
974
978 public function getRecordFields()
979 {
980 $this->loadRecordFields();
981
982 return $this->recordfields;
983 }
984
985
989 public function getTable()
990 {
991 $this->loadTable();
992
993 return $this->table;
994 }
995
996
1002 public function getComments()
1003 {
1004 if ($this->comments === null) {
1005 $this->comments = ilNote::_getNotesOfObject($this->table->getCollectionObject()->getId(), $this->getId(), 'dcl', IL_NOTE_PUBLIC);
1006 }
1007
1008 return $this->comments;
1009 }
1010}
$_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:6
static buildAjaxHash( $a_node_type, $a_node_id, $a_obj_type, $a_obj_id, $a_sub_type=null, $a_sub_id=null, $a_news_id=0)
Build ajax hash.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
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
setStandardFieldValueFromExcel($excel, $row, $col, $field)
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)
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
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, $a_news_id=0)
get all notes related to a specific object
Class ilObjFile.
Class ilObjMediaObject.
static _lookupLogin($a_user_id)
lookup login
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, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$query
global $ilDB
$DIC
Definition: xapitoken.php:46