ILIAS  Release_4_4_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;
28 
29 
30 
32  parent::__construct($record, $field);
33  $dclTable = ilDataCollectionCache::getTableCache($this->getField()->getTableId());
34  $this->dcl_obj_id = $dclTable->getCollectionObject()->getId();
35  }
36 
37  /*
38  * getHTML
39  *
40  * @param array $options
41  * @return array
42  */
43  public function getHTML(array $options = array()){
44  global $ilCtrl;
45 
46  $value = $this->getValue();
47  $record_field = $this;
48 
49  if(!$value || $value == "-"){
50  return "";
51  }
52 
53 
55  if(!$ref_record->getTableId() || !$record_field->getField() || !$record_field->getField()->getTableId()){
56  //the referenced record_field does not seem to exist.
57  $html = "";
58  $record_field->setValue(NULL);
59  $record_field->doUpdate();
60  }
61  else
62  {
63  $html = $ref_record->getRecordFieldHTML($record_field->getField()->getFieldRef());
64 
65  if($options['link']['display']) {
66  global $ilDB;
68  $ref_table = $ref_record->getTableId();
69 
70  $query = "SELECT table_id FROM il_dcl_view WHERE table_id = ".$ref_table." AND type = ".$ilDB->quote(0, "integer")." AND formtype = ".$ilDB->quote(0, "integer");
71  $set = $ilDB->query($query);
72  if($set->numRows())
73  $html = $this->getLinkHTML($options['link']['name'], $this->getValue());
74  }
75  }
76 
77 
78  return $html;
79  }
80 
81  /*
82  * get Link
83  *
84  * @param string $link_name
85  */
86  protected function getLinkHTML($link_name = NULL, $value) {
87  global $ilCtrl;
88 
89  if(!$value || $value == "-"){
90  return "";
91  }
92 
93  $record_field = $this;
95 
96  $objRefField = ilDataCollectionCache::getFieldCache($record_field->getField()->getFieldRef());
97  $objRefTable = ilDataCollectionCache::getTableCache($objRefField->getTableId());
98 
99  if(!$link_name) {
100  $link_name = $ref_record->getRecordFieldHTML($record_field->getField()->getFieldRef());
101  }
102 
103  $ilCtrl->setParameterByClass("ildatacollectionrecordviewgui", "record_id", $ref_record->getId());
104 
105  $html = "<a href='". $ilCtrl->getLinkTargetByClass("ilDataCollectionRecordViewGUI","renderRecord")."'>".$link_name."</a>";
106 
107 
108  return $html;
109  }
110 
111  /*
112  * getExportValue
113  */
114  public function getExportValue()
115  {
116  if($this->getValue()){
117  $ref_rec = ilDataCollectionCache::getRecordCache($this->getValue());
118  return $ref_rec->getRecordField($this->getField()->getFieldRef())->getExportValue();
119  }
120  else
121  return "";
122  }
123 
124 
125 }
126 ?>