ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
ilDataCollectionNReferenceField Class Reference

Class ilDataCollectionNReferenceField. More...

+ Inheritance diagram for ilDataCollectionNReferenceField:
+ Collaboration diagram for ilDataCollectionNReferenceField:

Public Member Functions

 doUpdate ()
 
 getSingleHTML ($options=NULL)
 this funciton is used to in the viewdefinition of a single record. More...
 
 buildTemplate ($record_field, $values, $options)
 
 getHTML ()
 
 getExportValue ()
 
- Public Member Functions inherited from ilDataCollectionReferenceField
 __construct (ilDataCollectionRecord $record, ilDataCollectionField $field)
 
 getExportValue ()
 
- Public Member Functions inherited from ilDataCollectionRecordField
 __construct (ilDataCollectionRecord $record, ilDataCollectionField $field)
 
 doUpdate ()
 Update object in database. More...
 
 delete ()
 Delete record field in database. More...
 
 getValue ()
 
 setValue ($value, $omit_parsing=false)
 Set value for record field. More...
 
 getFormInput ()
 
 getExportValue ()
 
 getPlainText ()
 
 getHTML ($link=true)
 
 getSortingValue ($link=true)
 
 getSingleHTML ()
 
 getField ()
 
 getId ()
 
 getRecord ()
 

Protected Member Functions

 loadValue ()
 
 getLinkHTML ($link, $value)
 
- Protected Member Functions inherited from ilDataCollectionReferenceField
 getLinkHTML ($link_name=NULL, $value)
 
- Protected Member Functions inherited from ilDataCollectionRecordField
 doRead ()
 Read object data from database. More...
 
 doCreate ()
 Create object in database. More...
 
 loadValue ()
 Load the value. More...
 

Protected Attributes

 $max_reference_length = 20
 
- Protected Attributes inherited from ilDataCollectionReferenceField
 $dcl_obj_id
 
 $properties = array()
 
- Protected Attributes inherited from ilDataCollectionRecordField
 $id
 
 $field
 
 $record
 
 $value
 
 $lng
 
 $user
 
 $ctrl
 
 $db
 

Detailed Description

Member Function Documentation

◆ buildTemplate()

ilDataCollectionNReferenceField::buildTemplate (   $record_field,
  $values,
  $options 
)
Parameters
$record_field
$values
$options
Returns
ilTemplate

Definition at line 88 of file class.ilDataCollectionNReferenceField.php.

References $options, $tpl, ilDataCollectionRecordField\$value, getLinkHTML(), and ilDataCollectionCache\getRecordCache().

Referenced by getSingleHTML().

88  {
89  $tpl = new ilTemplate("tpl.reference_list.html", true, true, "Modules/DataCollection");
90  $tpl->setCurrentBlock("reference_list");
91  foreach ($values as $value) {
92  $ref_record = ilDataCollectionCache::getRecordCache($value);
93  if (!$ref_record->getTableId() || !$record_field->getField() || !$record_field->getField()->getTableId()) {
94  //the referenced record_field does not seem to exist.
95  $record_field->setValue(0);
96  $record_field->doUpdate();
97  } else {
98  $tpl->setCurrentBlock("reference");
99  if (!$options) {
100  $tpl->setVariable("CONTENT", $ref_record->getRecordFieldHTML($this->getField()->getFieldRef()));
101  } else {
102  $tpl->setVariable("CONTENT", $this->getLinkHTML($options['link']['name'], $value));
103  }
104  $tpl->parseCurrentBlock();
105  }
106  }
107  $tpl->parseCurrentBlock();
108 
109  return $tpl;
110  }
static getRecordCache($record_id=0)
global $tpl
Definition: ilias.php:8
if(!is_array($argv)) $options
special template class to simplify handling of ITX/PEAR
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doUpdate()

ilDataCollectionNReferenceField::doUpdate ( )

Definition at line 17 of file class.ilDataCollectionNReferenceField.php.

References $ilDB, $query, ilDataCollectionRecordField\$value, and ilDataCollectionRecordField\getValue().

17  {
18  global $ilDB;
19 
20  $values = $this->getValue();
21  if (!is_array($values)) {
22  $values = array( $values );
23  }
24  $datatype = $this->field->getDatatype();
25 
26  $query = "DELETE FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
27  . $ilDB->quote($this->id, "integer");
28  $ilDB->manipulate($query);
29 
30  if (!count($values) || $values[0] == 0) {
31  return;
32  }
33 
34  $query = "INSERT INTO il_dcl_stloc" . $datatype->getStorageLocation() . "_value (value, record_field_id, id) VALUES";
35  foreach ($values as $value) {
36  $next_id = $ilDB->nextId("il_dcl_stloc" . $datatype->getStorageLocation() . "_value");
37  $query .= " (" . $ilDB->quote($value, $datatype->getDbType()) . ", " . $ilDB->quote($this->getId(), "integer") . ", "
38  . $ilDB->quote($next_id, "integer") . "),";
39  }
40  $query = substr($query, 0, - 1);
41  $ilDB->manipulate($query);
42  }
global $ilDB
+ Here is the call graph for this function:

◆ getExportValue()

ilDataCollectionNReferenceField::getExportValue ( )
Returns
int|string

Definition at line 194 of file class.ilDataCollectionNReferenceField.php.

References ilDataCollectionRecordField\$value, ilDataCollectionRecordField\getField(), ilDataCollectionCache\getRecordCache(), and ilDataCollectionRecordField\getValue().

194  {
195  $values = $this->getValue();
196  $names = array();
197  foreach ($values as $value) {
198  if ($value) {
199  $ref_rec = ilDataCollectionCache::getRecordCache($value);
200  $names[] = $ref_rec->getRecordField($this->getField()->getFieldRef())->getValue();
201  }
202  }
203  $string = "";
204  foreach ($names as $name) {
205  $string .= $name . ", ";
206  }
207  if (!count($names)) {
208  return "";
209  }
210  $string = substr($string, 0, - 2);
211 
212  return $string;
213  }
static getRecordCache($record_id=0)
+ Here is the call graph for this function:

◆ getHTML()

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

Definition at line 131 of file class.ilDataCollectionNReferenceField.php.

References $tpl, ilDataCollectionRecordField\$value, ilDataCollectionRecordField\getId(), ilDataCollectionRecordField\getRecord(), ilDataCollectionCache\getRecordCache(), ilDataCollectionRecordField\getValue(), ilDataCollectionDatatype\INPUTFORMAT_DATETIME, ilDataCollectionDatatype\INPUTFORMAT_NUMBER, and ilUtil\sortArray().

131  {
132  $values = $this->getValue();
133  $record_field = $this;
134 
135  if (!$values OR !count($values)) {
136  return "";
137  }
138 
139  $html = "";
140  $cut = false;
141  $tpl = new ilTemplate("tpl.reference_hover.html", true, true, "Modules/DataCollection");
142  $tpl->setCurrentBlock("reference_list");
143  $elements = array();
144  foreach ($values as $value) {
145  $ref_record = ilDataCollectionCache::getRecordCache($value);
146  if (!$ref_record->getTableId() OR !$record_field->getField() OR !$record_field->getField()->getTableId()) {
147  //the referenced record_field does not seem to exist.
148  $record_field->setValue(NULL);
149  $record_field->doUpdate();
150  } else {
151  $elements[] = array('value' => $ref_record->getRecordFieldHTML($this->getField()->getFieldRef()),
152  'sort' => $ref_record->getRecordFieldSortingValue($this->getField()->getFieldRef()));
153  }
154  }
155 
156  //sort fetched elements
157  $is_numeric = false;
158  $ref_field = new ilDataCollectionField($record_field->getField()->getFieldRef());
159  switch ($ref_field->getDatatypeId()) {
162  $is_numeric = true;
163  break;
164  }
165  $elements = ilUtil::sortArray($elements, 'sort', 'asc', $is_numeric);
166 
167  //concat
168  foreach($elements as $element) {
169  if ((strlen($html) < $this->max_reference_length)) {
170  $html .= $element['value'] . ", ";
171  } else {
172  $cut = true;
173  }
174  $tpl->setCurrentBlock("reference");
175  $tpl->setVariable("CONTENT", $element['value']);
176  $tpl->parseCurrentBlock();
177  }
178 
179  $html = substr($html, 0, - 2);
180  if ($cut) {
181  $html .= "...";
182  }
183  $tpl->setVariable("RECORD_ID", $this->getRecord()->getId());
184  $tpl->setVariable("ALL", $html);
185  $tpl->parseCurrentBlock();
186 
187  return $tpl->get();
188  }
static getRecordCache($record_id=0)
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
Class ilDataCollectionField.
+ Here is the call graph for this function:

◆ getLinkHTML()

ilDataCollectionNReferenceField::getLinkHTML (   $link,
  $value 
)
protected
Parameters
null$link
$value
Returns
string

Definition at line 119 of file class.ilDataCollectionNReferenceField.php.

References ilDataCollectionRecordField\$value, and ilDataCollectionRecordField\getField().

Referenced by buildTemplate().

119  {
120  if ($link == "[" . $this->getField()->getTitle() . "]") {
121  $link = NULL;
122  }
123 
124  return parent::getLinkHTML($link, $value);
125  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSingleHTML()

ilDataCollectionNReferenceField::getSingleHTML (   $options = NULL)

this funciton is used to in the viewdefinition of a single record.

Returns
mixed

Definition at line 65 of file class.ilDataCollectionNReferenceField.php.

References $options, $tpl, buildTemplate(), and ilDataCollectionRecordField\getValue().

65  {
66 
67  // if we are in a record view and the n-ref should be displayed as a link to it's reference
68  $values = $this->getValue();
69  $record_field = $this;
70 
71  if (!$values || !count($values)) {
72  return "";
73  }
74 
75  $tpl = $this->buildTemplate($record_field, $values, $options);
76 
77  return $tpl->get();
78  }
global $tpl
Definition: ilias.php:8
if(!is_array($argv)) $options
+ Here is the call graph for this function:

◆ loadValue()

ilDataCollectionNReferenceField::loadValue ( )
protected

Definition at line 45 of file class.ilDataCollectionNReferenceField.php.

References $ilDB, and $query.

45  {
46  if ($this->value === NULL) {
47  global $ilDB;
48  $datatype = $this->field->getDatatype();
49  $query = "SELECT * FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
50  . $ilDB->quote($this->id, "integer");
51  $set = $ilDB->query($query);
52  $this->value = array();
53  while ($rec = $ilDB->fetchAssoc($set)) {
54  $this->value[] = $rec['value'];
55  }
56  }
57  }
global $ilDB

Field Documentation

◆ $max_reference_length

ilDataCollectionNReferenceField::$max_reference_length = 20
protected

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


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