ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $objDataCollection = new ilObjDataCollection($_GET['ref_id']);
126 $objDataCollection->sendNotification("update_record", $this->getTableId(), $this->id);
127 }
128 }
129
130
134 public function doRead()
135 {
136 global $DIC;
137 $ilDB = $DIC['ilDB'];
138 //build query
139 $query = "Select * From il_dcl_record WHERE id = " . $ilDB->quote($this->getId(), "integer") . " ORDER BY id";
140
141 $set = $ilDB->query($query);
142 $rec = $ilDB->fetchAssoc($set);
143
144 $this->setTableId($rec["table_id"]);
145 $this->setCreateDate($rec["create_date"]);
146 $this->setLastUpdate($rec["last_update"]);
147 $this->setOwner($rec["owner"]);
148 $this->setLastEditBy($rec["last_edit_by"]);
149 }
150
151
155 public function doCreate()
156 {
157 global $DIC;
158 $ilDB = $DIC['ilDB'];
159
160 if (!ilDclTable::_tableExists($this->getTableId())) {
161 throw new ilException("The field does not have a related table!");
162 }
163
164 $id = $ilDB->nextId("il_dcl_record");
165 $this->setId($id);
166 $query
167 = "INSERT INTO il_dcl_record (
168 id,
169 table_id,
170 create_date,
171 Last_update,
172 owner,
173 last_edit_by
174 ) VALUES (" . $ilDB->quote($this->getId(), "integer") . "," . $ilDB->quote($this->getTableId(), "integer") . ","
175 . $ilDB->quote($this->getCreateDate(), "timestamp") . "," . $ilDB->quote($this->getLastUpdate(), "timestamp") . ","
176 . $ilDB->quote($this->getOwner(), "integer") . "," . $ilDB->quote($this->getLastEditBy(), "integer") . "
177 )";
178 $ilDB->manipulate($query);
179
180 $this->loadRecordFields();
181 foreach ($this->getRecordFields() as $recordField) {
182 $recordField->doCreate();
183 }
184
185 $this->getTable()->loadRecords();
186 }
187
188
192 public function deleteField($field_id)
193 {
194 $this->loadRecordFields();
195 $this->recordfields[$field_id]->delete();
196 if (count($this->recordfields) == 1) {
197 $this->doDelete();
198 }
199 }
200
201
207 public function setId($a_id)
208 {
209 $this->id = $a_id;
210 }
211
212
218 public function getId()
219 {
220 return $this->id;
221 }
222
223
229 public function setTableId($a_id)
230 {
231 $this->table_id = $a_id;
232 }
233
234
240 public function getTableId()
241 {
242 return $this->table_id;
243 }
244
245
251 public function setCreateDate($a_datetime)
252 {
253 $this->create_date = $a_datetime;
254 }
255
256
262 public function getCreateDate()
263 {
264 return $this->create_date;
265 }
266
267
273 public function setLastUpdate($a_datetime)
274 {
275 $this->last_update = $a_datetime;
276 }
277
278
284 public function getLastUpdate()
285 {
286 return $this->last_update;
287 }
288
289
295 public function setOwner($a_id)
296 {
297 $this->owner = $a_id;
298 }
299
300
306 public function getOwner()
307 {
308 return $this->owner;
309 }
310
311
312 /*
313 * getLastEditBy
314 */
315 public function getLastEditBy()
316 {
317 return $this->last_edit_by;
318 }
319
320
321 /*
322 * setLastEditBy
323 */
325 {
326 $this->last_edit_by = $last_edit_by;
327 }
328
329
336 public function setRecordFieldValue($field_id, $value)
337 {
338 $this->loadRecordFields();
340 $this->setStandardField($field_id, $value);
341 } else {
342 $this->loadTable();
343 $record_field = $this->recordfields[$field_id];
344
345 $this->recordfields[$field_id]->setValue($value);
346 }
347 }
348
349
356 public function setRecordFieldValueFromForm($field_id, &$form)
357 {
358 $this->loadRecordFields();
360 $this->setStandardFieldFromForm($field_id, $form);
361 } else {
362 $this->loadTable();
363 $this->recordfields[$field_id]->setValueFromForm($form);
364 }
365 }
366
367
376 public function getRecordFieldValueFromExcel($excel, $row, $col, $field)
377 {
378 $this->loadRecordFields();
379
380 return $this->recordfields[$field->getId()]->getValueFromExcel($excel, $row, $col);
381 }
382
383
390 public function setStandardFieldValueFromExcel($excel, $row, $col, $field)
391 {
392 $value = $field->getValueFromExcel($excel, $row, $col);
393 if ($value) {
394 $this->{$field->getId()} = $value;
395 }
396 }
397
398
403 public function getRecordFieldValues()
404 {
405 $this->loadRecordFields();
406 $return = array();
407 foreach ($this->recordfields as $id => $record_field) {
408 $return[$id] = $record_field->getValue();
409 }
410
411 return $return;
412 }
413
414
422 public function getRecordFieldValue($field_id)
423 {
424 if ($field_id === null) {
425 return null;
426 }
427 $this->loadRecordFields();
429 return $this->getStandardField($field_id);
430 } else {
431 return $this->recordfields[$field_id]->getValue();
432 }
433 }
434
435
443 public function getRecordFieldRepresentationValue($field_id)
444 {
445 if ($field_id === null) {
446 return null;
447 }
448 $this->loadRecordFields();
450 return $this->getStandardField($field_id);
451 } else {
452 return $this->recordfields[$field_id]->getValueForRepresentation();
453 }
454 }
455
456
464 public function getRecordFieldExportValue($field_id)
465 {
466 $this->loadRecordFields();
468 return $this->getStandardFieldHTML($field_id);
469 } else {
470 return $this->recordfields[$field_id]->getExportValue();
471 }
472 }
473
474
482 public function getRecordFieldPlainText($field_id)
483 {
484 $this->loadRecordFields();
486 return $this->getStandardFieldHTML($field_id);
487 } else {
488 return $this->recordfields[$field_id]->getPlainText();
489 }
490 }
491
492
499 public function fillRecordFieldExcelExport(ilExcel $worksheet, &$row, &$col, $field_id)
500 {
501 $this->loadRecordFields();
503 if ($field_id == 'owner') {
504 $worksheet->setCell($row, $col, ilObjUser::_lookupLogin($this->getOwner()));
505 $col++;
506 $name_array = ilObjUser::_lookupName($this->getOwner());
507 $worksheet->setCell($row, $col, $name_array['lastname'] . ', ' . $name_array['firstname']);
508 $col++;
509 } else {
510 $worksheet->setCell($row, $col, $this->getStandardFieldHTML($field_id));
511 $col++;
512 }
513 } else {
514 $this->recordfields[$field_id]->fillExcelExport($worksheet, $row, $col);
515 }
516 }
517
518
524 public function getRecordFieldFormulaValue($field_id)
525 {
526 $this->loadRecordFields();
528 $value = $this->getStandardFieldFormulaValue($field_id);
529 } else {
530 if (is_object($this->recordfields[$field_id])) {
531 $value = $this->recordfields[$field_id]->getFormulaValue();
532 } else {
533 $value = '';
534 }
535 }
536
537 return $value;
538 }
539
546 public function getRecordFieldHTML($field_id, array $options = array())
547 {
548 $this->loadRecordFields();
550 $html = $this->getStandardFieldHTML($field_id, $options);
551 } else {
552 if (is_object($this->recordfields[$field_id])) {
553 $html = $this->recordfields[$field_id]->getRecordRepresentation()->getHTML();
554 } else {
555 $html = '';
556 }
557 }
558
559 // 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
560 // SW 16.07.2014 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
561 // $html = str_ireplace("{", "&#123;", $html);
562 // $html = str_ireplace("}", "&#125;", $html);
563
564 return $html;
565 }
566
567
574 public function getRecordFieldSortingValue($field_id, array $options = array())
575 {
576 $this->loadRecordFields();
578 $html = $this->getStandardFieldHTML($field_id, $options);
579 } else {
580 if (is_object($this->recordfields[$field_id])) {
581 $html = $this->recordfields[$field_id]->getSortingValue();
582 } else {
583 $html = '';
584 }
585 }
586
587 // 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
588 // SW 16.07.2014 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
589 // $html = str_ireplace("{", "&#123;", $html);
590 // $html = str_ireplace("}", "&#125;", $html);
591
592 return $html;
593 }
594
595
602 public function getRecordFieldSingleHTML($field_id, array $options = array())
603 {
604 $this->loadRecordFields();
605
607 $html = $this->getStandardFieldHTML($field_id);
608 } else {
609 $field = $this->recordfields[$field_id];
614 $html = $field->getRecordRepresentation()->getSingleHTML($options, false);
615 }
616 // 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
617 // SW 14.10.2015 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
618 // $html = str_ireplace("{", "&#123;", $html);
619 // $html = str_ireplace("}", "&#125;", $html);
620
621 return $html;
622 }
623
624
629 public function fillRecordFieldFormInput($field_id, &$form)
630 {
631 $this->loadRecordFields();
633 $this->fillStandardFieldFormInput($field_id, $form);
634 } else {
635 $this->recordfields[$field_id]->getRecordRepresentation()->fillFormInput($form);
636 }
637 }
638
639
644 protected function setStandardFieldFromForm($field_id, &$form)
645 {
646 if ($item = $form->getItemByPostVar("field_" . $field_id)) {
647 $this->setStandardField($item->getValue());
648 }
649 }
650
651
656 protected function setStandardField($field_id, $value)
657 {
658 switch ($field_id) {
659 case "last_edit_by":
660 $this->setLastEditBy($value);
661
662 return;
663 }
664 $this->$field_id = $value;
665 }
666
667
672 protected function fillStandardFieldFormInput($field_id, &$form)
673 {
674 if ($item = $form->getItemByPostVar('field_' . $field_id)) {
675 $item->setValue($this->getStandardField($field_id));
676 }
677 }
678
679
685 protected function getStandardField($field_id)
686 {
687 switch ($field_id) {
688 case "last_edit_by":
689 return $this->getLastEditBy();
690 break;
691 case 'owner':
692 $usr_data = ilObjUser::_lookupName($this->getOwner());
693
694 return $usr_data['login'];
695 break;
696 }
697
698 return $this->$field_id;
699 }
700
701
707 public function getStandardFieldFormulaValue($field_id)
708 {
709 return $this->getStandardFieldHTML($field_id);
710 }
711
718 public function getStandardFieldHTML($field_id, array $options = array())
719 {
720 switch ($field_id) {
721 case 'id':
722 return $this->getId();
723 case 'owner':
725 case 'last_edit_by':
727 case 'last_update':
729 case 'create_date':
731 case 'comments':
732 $nComments = count($this->getComments());
734 1,
735 $_GET['ref_id'],
736 'dcl',
737 $this->table->getCollectionObject()
738 ->getId(),
739 'dcl',
740 $this->getId()
741 );
742 $ajax_link = ilNoteGUI::getListCommentsJSCall($ajax_hash, '');
743
744 return "<a class='dcl_comment' href='#' onclick=\"return " . $ajax_link . "\">
745 <img src='" . ilUtil::getImagePath("comment_unlabeled.svg")
746 . "' alt='{$nComments} Comments'><span class='ilHActProp'>{$nComments}</span></a>";
747 }
748 }
749
750
756 public function getStandardFieldPlainText($field_id)
757 {
758 switch ($field_id) {
759 case 'comments':
760 return count(ilNote::_getNotesOfObject(
761 $this->table->getCollectionObject()->getId(),
762 $this->getId(),
763 "dcl",
764 2,
765 false,
766 "",
767 "y",
768 true,
769 true
770 ));
771 default:
772 return strip_tags($this->getStandardFieldHTML($field_id));
773 }
774 }
775
776
780 private function loadRecordFields()
781 {
782 if ($this->recordfields == null) {
783 $this->loadTable();
784 $recordfields = array();
785 foreach ($this->table->getRecordFields() as $field) {
786 if ($recordfields[$field->getId()] == null) {
787 $recordfields[$field->getId()] = ilDclCache::getRecordFieldCache($this, $field);
788 }
789 }
790
791 $this->recordfields = $recordfields;
792 }
793 }
794
795
799 private function loadTable()
800 {
801 if ($this->table == null) {
802 $this->table = ilDclCache::getTableCache($this->getTableId());
803 }
804 }
805
806
812 public function getRecordField($field_id)
813 {
814 $this->loadRecordFields();
815
816 return $this->recordfields[$field_id];
817 }
818
819
825 public function doDelete($omit_notification = false)
826 {
827 global $DIC;
828 $ilDB = $DIC['ilDB'];
829 $ilAppEventHandler = $DIC['ilAppEventHandler'];
830
831 $this->loadRecordFields();
832 foreach ($this->recordfields as $recordfield) {
833 if ($recordfield->getField()->getDatatypeId() == ilDclDatatype::INPUTFORMAT_FILE) {
834 $this->deleteFile($recordfield->getValue());
835 }
836
837 if ($recordfield->getField()->getDatatypeId() == ilDclDatatype::INPUTFORMAT_MOB) {
838 $this->deleteMob($recordfield->getValue());
839 }
840
841 $recordfield->delete();
842 }
843
844 $query = "DELETE FROM il_dcl_record WHERE id = " . $ilDB->quote($this->getId(), "integer");
845 $ilDB->manipulate($query);
846
847 $this->table->loadRecords();
848
849 if (!$omit_notification) {
850 $objDataCollection = new ilObjDataCollection($_GET['ref_id']);
851 $objDataCollection->sendNotification("delete_record", $this->getTableId(), $this->getId());
852
853 $ilAppEventHandler->raise(
854 'Modules/DataCollection',
855 'deleteRecord',
856 array(
857 'dcl' => ilDclCache::getTableCache($this->getTableId())->getCollectionObject(),
858 'table_id' => $this->table_id,
859 'record_id' => $this->getId(),
860 'record' => $this,
861 )
862 );
863 }
864 }
865
866
867 // TODO: Find better way to copy data (including all references)
868
869
874 public function cloneStructure($original_id, $new_fields)
875 {
876 $original = ilDclCache::getRecordCache($original_id);
877 $this->setCreateDate($original->getCreateDate());
878 $this->setLastEditBy($original->getLastEditBy());
879 $this->setLastUpdate($original->getLastUpdate());
880 $this->setOwner($original->getOwner());
881 $this->doCreate();
882 foreach ($new_fields as $old => $new) {
883 $old_rec_field = $original->getRecordField($old);
884 $new_rec_field = ilDclCache::getRecordFieldCache($this, $new);
885 $new_rec_field->cloneStructure($old_rec_field);
886 $this->recordfields[] = $new_rec_field;
887 }
888
889 // mandatory for all cloning functions
891 }
892
893
899 public function deleteFile($obj_id)
900 {
901 if (ilObject2::_exists($obj_id, false)) {
902 $file = new ilObjFile($obj_id, false);
903 $file->delete();
904 }
905 }
906
907
913 public function deleteMob($obj_id)
914 {
915 if (ilObject2::_lookupObjId($obj_id)) {
916 $mob = new ilObjMediaObject($obj_id);
917 $mob->delete();
918 }
919 }
920
921
927 public function passThroughFilter(array $filter)
928 {
929 $this->loadTable();
930 // If one field returns false, the whole record does not pass the filter #performance-improvements
931 foreach ($this->table->getFilterableFields() as $field) {
932 if (!isset($filter["filter_" . $field->getId()]) || !$filter["filter_" . $field->getId()]) {
933 continue;
934 }
935 if (!ilDclCache::getFieldRepresentation($field)->passThroughFilter($this, $filter["filter_" . $field->getId()])) {
936 return false;
937 }
938 }
939
940 return true;
941 }
942
943
949 public function hasPermissionToEdit($ref_id)
950 {
951 return $this->getTable()->hasPermissionToEditRecord($ref_id, $this);
952 }
953
954
960 public function hasPermissionToDelete($ref_id)
961 {
962 return $this->getTable()->hasPermissionToDeleteRecord($ref_id, $this);
963 }
964
965
971 public function hasPermissionToView($ref_id)
972 {
973 return $this->getTable()->hasPermissionToViewRecord($ref_id, $this);
974 }
975
976
980 public function getRecordFields()
981 {
982 $this->loadRecordFields();
983
984 return $this->recordfields;
985 }
986
987
991 public function getTable()
992 {
993 $this->loadTable();
994
995 return $this->table;
996 }
997
998
1004 public function getComments()
1005 {
1006 if ($this->comments === null) {
1007 $this->comments = ilNote::_getNotesOfObject($this->table->getCollectionObject()->getId(), $this->getId(), 'dcl', IL_NOTE_PUBLIC);
1008 }
1009
1010 return $this->comments;
1011 }
1012}
$_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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 ilObjDataCollection.
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)
global $DIC
Definition: goto.php:24
$query
global $ilDB