ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 20 of file class.ilDclNReferenceFieldGUI.php.

References $field.

21  {
22  $this->field = $field;
23  }

Member Function Documentation

◆ buildTemplate()

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

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

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

Referenced by getSingleHTML().

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  }
$tpl
Definition: ilias.php:10
setValue($value, $omit_parsing=false)
Set value for record field.
special template class to simplify handling of ITX/PEAR
static getRecordCache($record_id=0)
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
+ 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 82 of file class.ilDclNReferenceFieldGUI.php.

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

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  }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
Class ilDclBaseFieldModel.
$tpl
Definition: ilias.php:10
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 32 of file class.ilDclNReferenceFieldGUI.php.

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

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  }
buildTemplate(ilDclNReferenceRecordFieldModel $record_field, $values, $options)
$tpl
Definition: ilias.php:10
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
+ Here is the call graph for this function:

Field Documentation

◆ $field

ilDclNReferenceFieldGUI::$field
protected

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

Referenced by __construct(), and getHTML().


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