ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
307
312 public function getRecordFieldValues() {
313 $this->loadRecordFields();
314 $return = array();
315 foreach ($this->recordfields as $id => $record_field) {
316 $return[$id] = $record_field->getValue();
317 }
318
319 return $return;
320 }
321
322
330 public function getRecordFieldValue($field_id) {
331 if ($field_id === NULL) {
332 return NULL;
333 }
334 $this->loadRecordFields();
336 return $this->getStandardField($field_id);
337 } else {
338 return $this->recordfields[$field_id]->getValue();
339 }
340 }
341
342
350 public function getRecordFieldExportValue($field_id) {
351 $this->loadRecordFields();
353 return $this->getStandardFieldHTML($field_id);
354 } else {
355 return $this->recordfields[$field_id]->getExportValue();
356 }
357 }
358
359
366 public function getRecordFieldHTML($field_id, array $options = array()) {
367 $this->loadRecordFields();
369 $html = $this->getStandardFieldHTML($field_id, $options);
370 } else {
371 if (is_object($this->recordfields[$field_id])) {
372 $html = $this->recordfields[$field_id]->getHTML();
373 } else {
374 $html = '';
375 }
376 }
377
378 // 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
379 // SW 16.07.2014 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
380 // $html = str_ireplace("{", "&#123;", $html);
381 // $html = str_ireplace("}", "&#125;", $html);
382
383 return $html;
384 }
385
386
393 public function getRecordFieldSortingValue($field_id, array $options = array()) {
394 $this->loadRecordFields();
396 $sort = $this->getStandardFieldHTML($field_id, $options);
397 } else {
398 if (is_object($this->recordfields[$field_id])) {
399 $sort = $this->recordfields[$field_id]->getSortingValue();
400 } else {
401 $sort = '';
402 }
403 }
404
405 return $sort;
406 }
407
408
415 public function getRecordFieldSingleHTML($field_id, array $options = array()) {
416 $this->loadRecordFields();
417
419 $html = $this->getStandardFieldHTML($field_id);
420 } else {
421 $field = $this->recordfields[$field_id];
425 $html = $field->getSingleHTML($options, false);
426 }
427 // 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
428 // SW 14.10.2015 Uncommented again, as some fields are outputting javascript that was broken due to entity encode the curly brackets
429// $html = str_ireplace("{", "&#123;", $html);
430// $html = str_ireplace("}", "&#125;", $html);
431
432 return $html;
433 }
434
435
441 public function getRecordFieldFormInput($field_id) {
442 $this->loadRecordFields();
444 return $this->getStandardField($field_id);
445 } else {
446 return $this->recordfields[$field_id]->getFormInput();
447 }
448 }
449
450
455 protected function setStandardField($field_id, $value) {
456 switch ($field_id) {
457 case "last_edit_by":
458 $this->setLastEditBy($value);
459
460 return;
461 }
462 $this->$field_id = $value;
463 }
464
465
471 protected function getStandardField($field_id) {
472 switch ($field_id) {
473 case "last_edit_by":
474 return $this->getLastEditBy();
475 break;
476 case 'owner':
477 $usr_data = ilObjUser::_lookupName($this->getOwner());
478
479 return $usr_data['login'];
480 break;
481 }
482
483 return $this->$field_id;
484 }
485
486
493 private function getStandardFieldHTML($field_id, array $options = array()) {
494 switch ($field_id) {
495 case 'id':
496 return $this->getId();
497 case 'owner':
499 case 'last_edit_by':
501 case 'last_update':
503 case 'create_date':
505 case 'comments':
506 $nComments = count($this->getComments());
507 $ajax_hash = ilCommonActionDispatcherGUI::buildAjaxHash(1, $_GET['ref_id'], 'dcl', $this->table->getCollectionObject()
508 ->getId(), 'dcl', $this->getId());
509 $ajax_link = ilNoteGUI::getListCommentsJSCall($ajax_hash, '');
510
511 return "<a class='dcl_comment' href='#' onclick=\"return " . $ajax_link . "\">
512 <img src='" . ilUtil::getImagePath("comment_unlabeled.svg")
513 . "' alt='{$nComments} Comments'><span class='ilHActProp'>{$nComments}</span></a>";
514 }
515 }
516
517
521 private function loadRecordFields() {
522 if ($this->recordfields == NULL) {
523 $this->loadTable();
524 $recordfields = array();
525 foreach ($this->table->getRecordFields() as $field) {
526 if ($recordfields[$field->getId()] == NULL) {
527 $recordfields[$field->getId()] = ilDataCollectionCache::getRecordFieldCache($this, $field);
528 }
529 }
530
531 $this->recordfields = $recordfields;
532 }
533 }
534
535
539 private function loadTable() {
540 if ($this->table == NULL) {
541 $this->table = ilDataCollectionCache::getTableCache($this->getTableId());
542 }
543 }
544
545
551 public function getRecordField($field_id) {
552 $this->loadRecordFields();
553
554 return $this->recordfields[$field_id];
555 }
556
557
561 public function doDelete() {
562 global $ilDB;
563
564 $this->loadRecordFields();
565 foreach ($this->recordfields as $recordfield) {
566 if ($recordfield->getField()->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE) {
567 $this->deleteFile($recordfield->getValue());
568 }
569
570 if ($recordfield->getField()->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB) {
571 $this->deleteMob($recordfield->getValue());
572 }
573
574 $recordfield->delete();
575 }
576
577 $query = "DELETE FROM il_dcl_record WHERE id = " . $ilDB->quote($this->getId(), "integer");
578 $ilDB->manipulate($query);
579
580 ilObjDataCollection::sendNotification("delete_record", $this->getTableId(), $this->getId());
581 }
582
583
584 // TODO: Find better way to copy data (including all references)
589 /*public function cloneStructure($original_id, $new_fields){
590 $original = ilDataCollectionCache::getRecordCache($original_id);
591 $this->setCreateDate($original->getCreateDate());
592 $this->setLastEditBy($original->getLastEditBy());
593 $this->setLastUpdate($original->getLastUpdate());
594 $this->setOwner($original->getOwner());
595 $this->doCreate();
596 foreach($new_fields as $old => $new){
597 $old_rec_field = $original->getRecordField($old);
598 $new_rec_field = new ilDataCollectionRecordField($this, $new);
599 $new_rec_field->setValue($old_rec_field->getValue());
600 $new_rec_field->doUpdate();
601 $this->recordfields[] = $new_rec_field;
602 }
603 }*/
604
610 public function deleteFile($obj_id) {
611 if (ilObject2::_exists($obj_id, false)) {
612 $file = new ilObjFile($obj_id, false);
613 $file->delete();
614 }
615 }
616
617
623 public function deleteMob($obj_id) {
624 if (ilObject2::_exists($obj_id)) {
625 $mob = new ilObjMediaObject($obj_id);
626 $mob->delete();
627 }
628 }
629
630
636 public function passThroughFilter(array $filter) {
637 $this->loadTable();
638 // If one field returns false, the whole record does not pass the filter #performance-improvements
639 foreach ($this->table->getFilterableFields() as $field) {
640 if (! isset($filter["filter_" . $field->getId()]) || ! $filter["filter_" . $field->getId()]) {
641 continue;
642 }
643 if (! ilDataCollectionDatatype::passThroughFilter($this, $field, $filter["filter_" . $field->getId()])) {
644 return false;
645 }
646 }
647
648 return true;
649 }
650
651
657 public function hasPermissionToEdit($ref_id) {
658 return $this->getTable()->hasPermissionToEditRecord($ref_id, $this);
659 }
660
661
668 return $this->getTable()->hasPermissionToDeleteRecord($ref_id, $this);
669 }
670
671
677 public function hasPermissionToView($ref_id) {
678 return $this->getTable()->hasPermissionToViewRecord($ref_id, $this);
679 }
680
681
685 public function getRecordFields() {
686 $this->loadRecordFields();
687
688 return $this->recordfields;
689 }
690
691
695 public function getTable() {
696 $this->loadTable();
697
698 return $this->table;
699 }
700
701
707 public function getComments() {
708 if ($this->comments === NULL) {
709 $this->comments = ilNote::_getNotesOfObject($this->table->getCollectionObject()->getId(), $this->getId(), 'dcl', IL_NOTE_PUBLIC);
710 }
711
712 return $this->comments;
713 }
714}
715
716?>
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.
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.
setLastUpdate($a_datetime)
Set Last Update Date.
getLastUpdate()
Get Last Update Date.
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)
Default behaviour is:
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$ref_id
Definition: sahs_server.php:39
global $ilDB
if(!is_array($argv)) $options