ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilDclNReferenceFieldGUI.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
14  protected $field;
15 
16 
21  {
22  $this->field = $field;
23  }
24 
25 
32  public function getSingleHTML($options = null)
33  {
34  $values = $this->field->getValue();
35 
36  if (!$values || !count($values)) {
37  return "";
38  }
39 
40  $tpl = $this->buildTemplate($this->field, $values, $options);
41 
42  return $tpl->get();
43  }
44 
45 
53  protected function buildTemplate(ilDclNReferenceRecordFieldModel $record_field, $values, $options)
54  {
55  $tpl = new ilTemplate("tpl.reference_list.html", true, true, "Modules/DataCollection");
56  $tpl->setCurrentBlock("reference_list");
57  foreach ($values as $value) {
58  $ref_record = ilDclCache::getRecordCache($value);
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(0);
62  $record_field->doUpdate();
63  } else {
64  $tpl->setCurrentBlock("reference");
65  if (!$options) {
66  $tpl->setVariable("CONTENT", $ref_record->getRecordFieldHTML($record_field->getField()->getFieldRef()));
67  } else {
68  $tpl->setVariable("CONTENT", $record_field->getLinkHTML($options['link']['name'], $value));
69  }
70  $tpl->parseCurrentBlock();
71  }
72  }
73  $tpl->parseCurrentBlock();
74 
75  return $tpl;
76  }
77 
78 
82  public function getHTML()
83  {
84  $values = $this->field->getValue();
85  $record_field = $this->field;
86 
87  if (!$values or !count($values)) {
88  return "";
89  }
90 
91  $html = "";
92  $cut = false;
93  $tpl = new ilTemplate("tpl.reference_hover.html", true, true, "Modules/DataCollection");
94  $tpl->setCurrentBlock("reference_list");
95  $elements = array();
96  foreach ($values as $value) {
97  $ref_record = ilDclCache::getRecordCache($value);
98  if (!$ref_record->getTableId() or !$record_field->getField() or !$record_field->getField()->getTableId()) {
99  //the referenced record_field does not seem to exist.
100  $record_field->setValue(null);
101  $record_field->doUpdate();
102  } else {
103  $elements[] = array('value' => $ref_record->getRecordFieldHTML($this->field->getField()->getFieldRef()),
104  'sort' => $ref_record->getRecordFieldSortingValue($this->field->getField()->getFieldRef()));
105  }
106  }
107  //sort fetched elements
108  $is_numeric = false;
109  $ref_field = new ilDclBaseFieldModel($this->field->getField()->getFieldRef());
110  switch ($ref_field->getDatatypeId()) {
113  $is_numeric = true;
114  break;
115  }
116  $elements = ilUtil::sortArray($elements, 'sort', 'asc', $is_numeric);
117 
118  //concat
119  foreach ($elements as $element) {
120  if ((strlen($html) < $record_field->getMaxReferenceLength())) {
121  $html .= $element['value'] . ", ";
122  } else {
123  $cut = true;
124  }
125  $tpl->setCurrentBlock("reference");
126  $tpl->setVariable("CONTENT", $element['value']);
127  $tpl->parseCurrentBlock();
128  }
129 
130  $html = substr($html, 0, -2);
131  if ($cut) {
132  $html .= "...";
133  }
134  $tpl->setVariable("RECORD_ID", $record_field->getRecord()->getId());
135  $tpl->setVariable("ALL", $html);
136  $tpl->parseCurrentBlock();
137 
138  return $tpl->get();
139  }
140 }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
Class ilDclBaseFieldModel.
buildTemplate(ilDclNReferenceRecordFieldModel $record_field, $values, $options)
$tpl
Definition: ilias.php:10
setValue($value, $omit_parsing=false)
Set value for record field.
Class ilDclNReferenceFieldGUI.
$values
__construct(ilDclNReferenceRecordFieldModel $field)
special template class to simplify handling of ITX/PEAR
static getRecordCache($record_id=0)
$html
Definition: example_001.php:87