ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilDataCollectionRecord.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/class.ilDataCollectionRecordField.php';
5require_once './Modules/DataCollection/classes/class.ilDataCollectionDatatype.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('class.ilDataCollectionTable.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
82 public function doUpdate() {
83 global $ilDB;
84
85 $ilDB->update("il_dcl_record", array(
86 "table_id" => array(
87 "integer",
88 $this->getTableId()
89 ),
90 "last_update" => array(
91 "date",
92 $this->getLastUpdate()
93 ),
94 "owner" => array(
95 "text",
96 $this->getOwner()
97 ),
98 "last_edit_by" => array(
99 "text",
100 $this->getLastEditBy()
101 )
102 ), array(
103 "id" => array(
104 "integer",
105 $this->id
106 )
107 ));
108
109 foreach ($this->getRecordFields() as $recordfield) {
110 $recordfield->doUpdate();
111 }
112
113 ilObjDataCollection::sendNotification("update_record", $this->getTableId(), $this->id);
114 }
115
116
120 public function doRead() {
121 global $ilDB;
122 //build query
123 $query = "Select * From il_dcl_record WHERE id = " . $ilDB->quote($this->getId(), "integer") . " ORDER BY id";
124
125 $set = $ilDB->query($query);
126 $rec = $ilDB->fetchAssoc($set);
127
128 $this->setTableId($rec["table_id"]);
129 $this->setCreateDate($rec["create_date"]);
130 $this->setLastUpdate($rec["last_update"]);
131 $this->setOwner($rec["owner"]);
132 $this->setLastEditBy($rec["last_edit_by"]);
133 }
134
135
139 public function doCreate() {
140 global $ilDB;
141
143 throw new ilException("The field does not have a related table!");
144 }
145
146 $id = $ilDB->nextId("il_dcl_record");
147 $this->setId($id);
148 $query = "INSERT INTO il_dcl_record (
149 id,
150 table_id,
151 create_date,
152 Last_update,
153 owner,
154 last_edit_by
155 ) VALUES (" . $ilDB->quote($this->getId(), "integer") . "," . $ilDB->quote($this->getTableId(), "integer") . ","
156 . $ilDB->quote($this->getCreateDate(), "timestamp") . "," . $ilDB->quote($this->getLastUpdate(), "timestamp") . ","
157 . $ilDB->quote($this->getOwner(), "integer") . "," . $ilDB->quote($this->getLastEditBy(), "integer") . "
158 )";
159 $ilDB->manipulate($query);
160 }
161
162
166 public function deleteField($field_id) {
167 $this->loadRecordFields();
168 $this->recordfields[$field_id]->delete();
169 if (count($this->recordfields) == 1) {
170 $this->doDelete();
171 }
172 }
173
174
180 public function setId($a_id) {
181 $this->id = $a_id;
182 }
183
184
190 public function getId() {
191 return $this->id;
192 }
193
194
200 public function setTableId($a_id) {
201 $this->table_id = $a_id;
202 }
203
204
210 public function getTableId() {
211 return $this->table_id;
212 }
213
214
220 public function setCreateDate($a_datetime) {
221 $this->create_date = $a_datetime;
222 }
223
224
230 public function getCreateDate() {
231 return $this->create_date;
232 }
233
234
240 public function setLastUpdate($a_datetime) {
241 $this->last_update = $a_datetime;
242 }
243
244
250 public function getLastUpdate() {
251 return $this->last_update;
252 }
253
254
260 public function setOwner($a_id) {
261 $this->owner = $a_id;
262 }
263
264
270 public function getOwner() {
271 return $this->owner;
272 }
273
274
275 /*
276 * getLastEditBy
277 */
278 public function getLastEditBy() {
279 return $this->last_edit_by;
280 }
281
282
283 /*
284 * setLastEditBy
285 */
286 public function setLastEditBy($last_edit_by) {
287 $this->last_edit_by = $last_edit_by;
288 }
289
290
297 public function setRecordFieldValue($field_id, $value) {
298 $this->loadRecordFields();
300 $this->setStandardField($field_id, $value);
301 } else {
302 $this->loadTable();
303 $this->recordfields[$field_id]->setValue($value);
304 }
305 }
306
313 public function setRecordFieldValueFromForm($field_id, &$form) {
314 $this->loadRecordFields();
316 $this->setStandardFieldFromForm($field_id, $form);
317 } else {
318 $this->loadTable();
319 $this->recordfields[$field_id]->setValueFromForm($form);
320 }
321 }
322
330 public function getRecordFieldValueFromExcel($excel, $row, $col, $field) {
331 $this->loadRecordFields();
332 return $this->recordfields[$field->getId()]->getValueFromExcel($excel, $row, $col);
333 }
334
335
340 public function getRecordFieldValues() {
341 $this->loadRecordFields();
342 $return = array();
343 foreach ($this->recordfields as $id => $record_field) {
344 $return[$id] = $record_field->getValue();
345 }
346
347 return $return;
348 }
349
350
358 public function getRecordFieldValue($field_id) {
359 if ($field_id === NULL) {
360 return NULL;
361 }
362 $this->loadRecordFields();
364 return $this->getStandardField($field_id);
365 } else {
366 return $this->recordfields[$field_id]->getValue();
367 }
368 }
369
370
378 public function getRecordFieldExportValue($field_id) {
379 $this->loadRecordFields();
381 return $this->getStandardFieldHTML($field_id);
382 } else {
383 return $this->recordfields[$field_id]->getExportValue();
384 }
385 }
386
393 public function fillRecordFieldExcelExport($worksheet, &$row, &$col, $field_id) {
394 $this->loadRecordFields();
396 $worksheet->writeString($row, $col, $this->getStandardFieldHTML($field_id));
397 $col++;
398 } else {
399 $this->recordfields[$field_id]->fillExcelExport($worksheet, $row, $col);
400 }
401 }
402
409 public function getRecordFieldHTML($field_id, array $options = array()) {
410 $this->loadRecordFields();
412 $html = $this->getStandardFieldHTML($field_id, $options);
413 } else {
414 if (is_object($this->recordfields[$field_id])) {
415 $html = $this->recordfields[$field_id]->getHTML();
416 } else {
417 $html = '';
418 }
419 }
420
421 // 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
422 // SW 16.07.2014 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
423 // $html = str_ireplace("{", "&#123;", $html);
424 // $html = str_ireplace("}", "&#125;", $html);
425
426 return $html;
427 }
428
429
436 public function getRecordFieldSortingValue($field_id, array $options = array()) {
437 $this->loadRecordFields();
439 $html = $this->getStandardFieldHTML($field_id, $options);
440 } else {
441 if (is_object($this->recordfields[$field_id])) {
442 $html = $this->recordfields[$field_id]->getSortingValue();
443 } else {
444 $html = '';
445 }
446 }
447
448 // 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
449 // SW 16.07.2014 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
450 // $html = str_ireplace("{", "&#123;", $html);
451 // $html = str_ireplace("}", "&#125;", $html);
452
453 return $html;
454 }
455
462 public function getRecordFieldSingleHTML($field_id, array $options = array()) {
463 $this->loadRecordFields();
464
466 $html = $this->getStandardFieldHTML($field_id);
467 } else {
468 $field = $this->recordfields[$field_id];
472 $html = $field->getSingleHTML($options, false);
473 }
474 // 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
475 // SW 14.10.2015 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
476// $html = str_ireplace("{", "&#123;", $html);
477// $html = str_ireplace("}", "&#125;", $html);
478
479 return $html;
480 }
481
486 public function fillRecordFieldFormInput($field_id, &$form) {
487 $this->loadRecordFields();
489 $this->fillStandardFieldFormInput($field_id, $form);
490 } else {
491 $this->recordfields[$field_id]->fillFormInput($form);
492 }
493 }
494
495
500 protected function setStandardFieldFromForm($field_id, &$form) {
501 if ($item = $form->getItemByPostVar("field_".$field_id)) {
502 $this->setStandardField($item->getValue());
503 }
504 }
505
510 protected function setStandardField($field_id, $value) {
511 switch ($field_id) {
512 case "last_edit_by":
513 $this->setLastEditBy($value);
514
515 return;
516 }
517 $this->$field_id = $value;
518 }
519
524 protected function fillStandardFieldFormInput($field_id, &$form) {
525 if ($item = $form->getItemByPostVar('field_' . $field_id)) {
526 $item->setValue($this->getStandardField($field_id));
527 }
528 }
529
530
536 protected function getStandardField($field_id) {
537 switch ($field_id) {
538 case "last_edit_by":
539 return $this->getLastEditBy();
540 break;
541 case 'owner':
542 $usr_data = ilObjUser::_lookupName($this->getOwner());
543
544 return $usr_data['login'];
545 break;
546 }
547
548 return $this->$field_id;
549 }
550
551
558 private function getStandardFieldHTML($field_id, array $options = array()) {
559 switch ($field_id) {
560 case 'id':
561 return $this->getId();
562 case 'owner':
564 case 'last_edit_by':
566 case 'last_update':
568 case 'create_date':
570 case 'comments':
571 $nComments = count($this->getComments());
572 $ajax_hash = ilCommonActionDispatcherGUI::buildAjaxHash(1, $_GET['ref_id'], 'dcl', $this->table->getCollectionObject()
573 ->getId(), 'dcl', $this->getId());
574 $ajax_link = ilNoteGUI::getListCommentsJSCall($ajax_hash, '');
575
576 return "<a class='dcl_comment' href='#' onclick=\"return " . $ajax_link . "\">
577 <img src='" . ilUtil::getImagePath("comment_unlabeled.svg")
578 . "' alt='{$nComments} Comments'><span class='ilHActProp'>{$nComments}</span></a>";
579 }
580 }
581
582
586 private function loadRecordFields() {
587 if ($this->recordfields == NULL) {
588 $this->loadTable();
589 $recordfields = array();
590 foreach ($this->table->getRecordFields() as $field) {
591 if ($recordfields[$field->getId()] == NULL) {
592 $recordfields[$field->getId()] = ilDataCollectionCache::getRecordFieldCache($this, $field);
593 }
594 }
595
596 $this->recordfields = $recordfields;
597 }
598 }
599
600
604 private function loadTable() {
605 if ($this->table == NULL) {
606 $this->table = ilDataCollectionCache::getTableCache($this->getTableId());
607 }
608 }
609
610
616 public function getRecordField($field_id) {
617 $this->loadRecordFields();
618
619 return $this->recordfields[$field_id];
620 }
621
622
626 public function doDelete() {
627 global $ilDB;
628
629 $this->loadRecordFields();
630 foreach ($this->recordfields as $recordfield) {
631 if ($recordfield->getField()->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE) {
632 $this->deleteFile($recordfield->getValue());
633 }
634
635 if ($recordfield->getField()->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB) {
636 $this->deleteMob($recordfield->getValue());
637 }
638
639 $recordfield->delete();
640 }
641
642 $query = "DELETE FROM il_dcl_record WHERE id = " . $ilDB->quote($this->getId(), "integer");
643 $ilDB->manipulate($query);
644
645 ilObjDataCollection::sendNotification("delete_record", $this->getTableId(), $this->getId());
646 }
647
648
649 // TODO: Find better way to copy data (including all references)
654 /*public function cloneStructure($original_id, $new_fields){
655 $original = ilDataCollectionCache::getRecordCache($original_id);
656 $this->setCreateDate($original->getCreateDate());
657 $this->setLastEditBy($original->getLastEditBy());
658 $this->setLastUpdate($original->getLastUpdate());
659 $this->setOwner($original->getOwner());
660 $this->doCreate();
661 foreach($new_fields as $old => $new){
662 $old_rec_field = $original->getRecordField($old);
663 $new_rec_field = new ilDataCollectionRecordField($this, $new);
664 $new_rec_field->setValue($old_rec_field->getValue());
665 $new_rec_field->doUpdate();
666 $this->recordfields[] = $new_rec_field;
667 }
668 }*/
669
675 public function deleteFile($obj_id) {
676 if (ilObject2::_exists($obj_id, false)) {
677 $file = new ilObjFile($obj_id, false);
678 $file->delete();
679 }
680 }
681
682
688 public function deleteMob($obj_id) {
689 if (ilObject2::_exists($obj_id)) {
690 $mob = new ilObjMediaObject($obj_id);
691 $mob->delete();
692 }
693 }
694
695
701 public function passThroughFilter(array $filter) {
702 $this->loadTable();
703 // If one field returns false, the whole record does not pass the filter #performance-improvements
704 foreach ($this->table->getFilterableFields() as $field) {
705 if (! isset($filter["filter_" . $field->getId()]) || ! $filter["filter_" . $field->getId()]) {
706 continue;
707 }
708 if (! ilDataCollectionDatatype::passThroughFilter($this, $field, $filter["filter_" . $field->getId()])) {
709 return false;
710 }
711 }
712
713 return true;
714 }
715
716
722 public function hasPermissionToEdit($ref_id) {
723 return $this->getTable()->hasPermissionToEditRecord($ref_id, $this);
724 }
725
726
733 return $this->getTable()->hasPermissionToDeleteRecord($ref_id, $this);
734 }
735
736
742 public function hasPermissionToView($ref_id) {
743 return $this->getTable()->hasPermissionToViewRecord($ref_id, $this);
744 }
745
746
750 public function getRecordFields() {
751 $this->loadRecordFields();
752
753 return $this->recordfields;
754 }
755
756
760 public function getTable() {
761 $this->loadTable();
762
763 return $this->table;
764 }
765
766
772 public function getComments() {
773 if ($this->comments === NULL) {
774 $this->comments = ilNote::_getNotesOfObject($this->table->getCollectionObject()->getId(), $this->getId(), 'dcl', IL_NOTE_PUBLIC);
775 }
776
777 return $this->comments;
778 }
779}
780
781?>
print $file
$_GET["client_id"]
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 getRecordFieldCache($record, $field)
static passThroughFilter(ilDataCollectionRecord $record, ilDataCollectionField $field, $filter)
Class ilDataCollectionRecord.
getComments()
Get all comments of this record.
getRecordFieldValueFromExcel($excel, $row, $col, $field)
getRecordFieldSortingValue($field_id, array $options=array())
getRecordFieldHTML($field_id, array $options=array())
getRecordFieldExportValue($field_id)
Get Field Export Value.
getStandardFieldHTML($field_id, array $options=array())
setRecordFieldValue($field_id, $value)
Set a field value.
getRecordFieldValue($field_id)
Get Field Value.
fillStandardFieldFormInput($field_id, &$form)
fillRecordFieldExcelExport($worksheet, &$row, &$col, $field_id)
setLastUpdate($a_datetime)
Set Last Update Date.
getLastUpdate()
Get Last Update Date.
setRecordFieldValueFromForm($field_id, &$form)
Set a field value.
setCreateDate($a_datetime)
Set Creation Date.
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
Base class for ILIAS Exception handling.
getListCommentsJSCall($a_hash, $a_update_code=null)
Get list comments js call.
_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
static sendNotification($a_action, $a_table_id, $a_record_id=NULL)
Class ilObjFile.
Class ilObjMediaObject.
static _lookupName($a_user_id)
lookup user name
static _exists($a_id, $a_reference=false)
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
$ref_id
Definition: sahs_server.php:39
global $ilDB
if(!is_array($argv)) $options