ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDataCollectionReferenceField.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once 'class.ilDataCollectionRecordField.php';
6 require_once 'class.ilDataCollectionRecord.php';
7 require_once 'class.ilDataCollectionField.php';
8 require_once 'class.ilDataCollectionRecordViewGUI.php';
9 require_once("./Services/Link/classes/class.ilLink.php");
10 
23 
27  protected $dcl_obj_id;
31  protected $properties = array();
32 
33 
39  parent::__construct($record, $field);
40  $dclTable = ilDataCollectionCache::getTableCache($this->getField()->getTableId());
41  $this->dcl_obj_id = $dclTable->getCollectionObject()->getId();
42  $this->properties = $this->field->getProperties();
43  }
44 
45 
49  public function getHTML() {
50  $value = $this->getValue();
51  $record_field = $this;
52 
53  if (!$value || $value == "-") {
54  return "";
55  }
56 
58  $html = "";
59  if (!$ref_record->getTableId() || !$record_field->getField() || !$record_field->getField()->getTableId()) {
60  //the referenced record_field does not seem to exist.
61  $record_field->setValue(NULL);
62  $record_field->doUpdate();
63  } else {
64  if ($this->properties[ilDataCollectionField::PROPERTYID_REFERENCE_LINK]) {
65  global $ilDB;
68  $ref_table = $ref_record->getTableId();
69  // Checks if a view exists
70  $query = "SELECT table_id FROM il_dcl_view WHERE table_id = " . $ref_table . " AND type = " . $ilDB->quote(0, "integer")
71  . " AND formtype = " . $ilDB->quote(0, "integer");
72  $set = $ilDB->query($query);
73  if ($ilDB->numRows($set)) {
74  $html = $this->getLinkHTML(NULL, $this->getValue());
75  } else {
76  $html = $ref_record->getRecordFieldHTML($record_field->getField()->getFieldRef());
77  }
78  } else {
79  $html = $ref_record->getRecordFieldHTML($record_field->getField()->getFieldRef());
80  }
81  }
82 
83  return $html;
84  }
85 
86 
93  protected function getLinkHTML($link_name = NULL, $value) {
94  global $ilCtrl;
95 
96  if (!$value || $value == "-") {
97  return "";
98  }
99  $record_field = $this;
101  if (!$link_name) {
102  $link_name = $ref_record->getRecordFieldHTML($record_field->getField()->getFieldRef());
103  }
104  $ilCtrl->setParameterByClass("ildatacollectionrecordviewgui", "record_id", $ref_record->getId());
105  $html = "<a href='" . $ilCtrl->getLinkTargetByClass("ilDataCollectionRecordViewGUI", "renderRecord") . "&disable_paging=1'>" . $link_name
106  . "</a>";
107 
108  return $html;
109  }
110 
111 
115  public function getExportValue() {
116  if ($this->getValue()) {
117  $ref_rec = ilDataCollectionCache::getRecordCache($this->getValue());
118 
119  return $ref_rec->getRecordField($this->getField()->getFieldRef())->getExportValue();
120  } else {
121  return "";
122  }
123  }
124 }
125 
126 ?>