ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilDclNReferenceFieldGUI Class Reference

Class ilDclNReferenceFieldGUI. More...

+ Collaboration diagram for ilDclNReferenceFieldGUI:

Public Member Functions

 __construct (ilDclNReferenceRecordFieldModel $field)
 
 getSingleHTML ($options=NULL)
 
 getHTML ()
 

Protected Member Functions

 buildTemplate (ilDclNReferenceRecordFieldModel $record_field, $values, $options)
 

Protected Attributes

 $field
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilDclNReferenceFieldGUI::__construct ( ilDclNReferenceRecordFieldModel  $field)
Parameters
ilDclNReferenceRecordFieldModel$field

Definition at line 19 of file class.ilDclNReferenceFieldGUI.php.

References $field.

19  {
20  $this->field = $field;
21  }

Member Function Documentation

◆ buildTemplate()

ilDclNReferenceFieldGUI::buildTemplate ( ilDclNReferenceRecordFieldModel  $record_field,
  $values,
  $options 
)
protected
Parameters
$record_field
$values
$options
Returns
ilTemplate

Definition at line 50 of file class.ilDclNReferenceFieldGUI.php.

References $options, $tpl, ilDclNReferenceRecordFieldModel\doUpdate(), ilDclBaseRecordFieldModel\getField(), ilDclNReferenceRecordFieldModel\getLinkHTML(), ilDclCache\getRecordCache(), and ilDclBaseRecordFieldModel\setValue().

Referenced by getSingleHTML().

50  {
51  $tpl = new ilTemplate("tpl.reference_list.html", true, true, "Modules/DataCollection");
52  $tpl->setCurrentBlock("reference_list");
53  foreach ($values as $value) {
54  $ref_record = ilDclCache::getRecordCache($value);
55  if (! $ref_record->getTableId() || ! $record_field->getField() || ! $record_field->getField()->getTableId()) {
56  //the referenced record_field does not seem to exist.
57  $record_field->setValue(0);
58  $record_field->doUpdate();
59  } else {
60  $tpl->setCurrentBlock("reference");
61  if (! $options) {
62  $tpl->setVariable("CONTENT", $ref_record->getRecordFieldHTML($record_field->getField()->getFieldRef()));
63  } else {
64  $tpl->setVariable("CONTENT", $record_field->getLinkHTML($options['link']['name'], $value));
65  }
66  $tpl->parseCurrentBlock();
67  }
68  }
69  $tpl->parseCurrentBlock();
70 
71  return $tpl;
72  }
setValue($value, $omit_parsing=false)
Set value for record field.
global $tpl
Definition: ilias.php:8
if(!is_array($argv)) $options
special template class to simplify handling of ITX/PEAR
static getRecordCache($record_id=0)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHTML()

ilDclNReferenceFieldGUI::getHTML ( )
Returns
array|mixed|string

Definition at line 78 of file class.ilDclNReferenceFieldGUI.php.

References $field, $html, $tpl, array, ilDclCache\getRecordCache(), ilDclDatatype\INPUTFORMAT_DATETIME, ilDclDatatype\INPUTFORMAT_NUMBER, and ilUtil\sortArray().

78  {
79  $values = $this->field->getValue();
80  $record_field = $this->field;
81 
82  if (!$values OR !count($values)) {
83  return "";
84  }
85 
86  $html = "";
87  $cut = false;
88  $tpl = new ilTemplate("tpl.reference_hover.html", true, true, "Modules/DataCollection");
89  $tpl->setCurrentBlock("reference_list");
90  $elements = array();
91  foreach ($values as $value) {
92  $ref_record = ilDclCache::getRecordCache($value);
93  if (!$ref_record->getTableId() OR !$record_field->getField() OR !$record_field->getField()->getTableId()) {
94  //the referenced record_field does not seem to exist.
95  $record_field->setValue(NULL);
96  $record_field->doUpdate();
97  } else {
98  $elements[] = array('value' => $ref_record->getRecordFieldHTML($this->field->getField()->getFieldRef()),
99  'sort' => $ref_record->getRecordFieldSortingValue($this->field->getField()->getFieldRef()));
100 
101  }
102  }
103  //sort fetched elements
104  $is_numeric = false;
105  $ref_field = new ilDclBaseFieldModel($this->field->getField()->getFieldRef());
106  switch ($ref_field->getDatatypeId()) {
109  $is_numeric = true;
110  break;
111  }
112  $elements = ilUtil::sortArray($elements, 'sort', 'asc', $is_numeric);
113 
114  //concat
115  foreach($elements as $element) {
116  if ((strlen($html) < $record_field->getMaxReferenceLength())) {
117  $html .= $element['value'] . ", ";
118  } else {
119  $cut = true;
120  }
121  $tpl->setCurrentBlock("reference");
122  $tpl->setVariable("CONTENT", $element['value']);
123  $tpl->parseCurrentBlock();
124  }
125 
126  $html = substr($html, 0, - 2);
127  if ($cut) {
128  $html .= "...";
129  }
130  $tpl->setVariable("RECORD_ID", $record_field->getRecord()->getId());
131  $tpl->setVariable("ALL", $html);
132  $tpl->parseCurrentBlock();
133 
134  return $tpl->get();
135  }
Class ilDclBaseFieldModel.
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
global $tpl
Definition: ilias.php:8
special template class to simplify handling of ITX/PEAR
static getRecordCache($record_id=0)
Create styles array
The data for the language used.
$html
Definition: example_001.php:87
+ Here is the call graph for this function:

◆ getSingleHTML()

ilDclNReferenceFieldGUI::getSingleHTML (   $options = NULL)
Parameters
ilDclNReferenceRecordFieldModel$field
null$options
Returns
string

Definition at line 30 of file class.ilDclNReferenceFieldGUI.php.

References $options, $tpl, and buildTemplate().

30  {
31  $values = $this->field->getValue();
32 
33  if (! $values || ! count($values)) {
34  return "";
35  }
36 
37  $tpl = $this->buildTemplate($this->field, $values, $options);
38 
39  return $tpl->get();
40  }
buildTemplate(ilDclNReferenceRecordFieldModel $record_field, $values, $options)
global $tpl
Definition: ilias.php:8
if(!is_array($argv)) $options
+ Here is the call graph for this function:

Field Documentation

◆ $field

ilDclNReferenceFieldGUI::$field
protected

Definition at line 13 of file class.ilDclNReferenceFieldGUI.php.

Referenced by __construct(), and getHTML().


The documentation for this class was generated from the following file: