ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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(
104  'value' => $ref_record->getRecordFieldHTML($this->field->getField()->getFieldRef()),
105  'sort' => $ref_record->getRecordFieldSortingValue($this->field->getField()->getFieldRef()),
106  );
107  }
108  }
109  //sort fetched elements
110  $is_numeric = false;
111  $ref_field = new ilDclBaseFieldModel($this->field->getField()->getFieldRef());
112  switch ($ref_field->getDatatypeId()) {
115  $is_numeric = true;
116  break;
117  }
118  $elements = ilUtil::sortArray($elements, 'sort', 'asc', $is_numeric);
119 
120  //concat
121  foreach ($elements as $element) {
122  if ((strlen($html) < $record_field->getMaxReferenceLength())) {
123  $html .= $element['value'] . ", ";
124  } else {
125  $cut = true;
126  }
127  $tpl->setCurrentBlock("reference");
128  $tpl->setVariable("CONTENT", $element['value']);
129  $tpl->parseCurrentBlock();
130  }
131 
132  $html = substr($html, 0, -2);
133  if ($cut) {
134  $html .= "...";
135  }
136  $tpl->setVariable("RECORD_ID", $record_field->getRecord()->getId());
137  $tpl->setVariable("ALL", $html);
138  $tpl->parseCurrentBlock();
139 
140  return $tpl->get();
141  }
142 }
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)
setValue($value, $omit_parsing=false)
Set value for record field.
Class ilDclNReferenceFieldGUI.
__construct(ilDclNReferenceRecordFieldModel $field)
static getRecordCache($record_id=0)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41