ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilDataCollectionNReferenceField.php
Go to the documentation of this file.
1<?php
2require_once('./Modules/DataCollection/classes/Field/NReference/class.ilDataCollectionNReferenceFieldGUI.php');
10
14 protected $max_reference_length = 20;
15
16
20 public function getMaxReferenceLength() {
22 }
23
24
29 $this->max_reference_length = $max_reference_length;
30 }
31
32
33
34
35 public function doUpdate() {
36 global $ilDB;
37
38 $values = $this->getValue();
39 if (!is_array($values)) {
40 $values = array( $values );
41 }
42 $datatype = $this->field->getDatatype();
43
44 $query = "DELETE FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
45 . $ilDB->quote($this->id, "integer");
46 $ilDB->manipulate($query);
47
48 if (!count($values) || $values[0] == 0) {
49 return;
50 }
51
52 $query = "INSERT INTO il_dcl_stloc" . $datatype->getStorageLocation() . "_value (value, record_field_id, id) VALUES";
53 foreach ($values as $value) {
54 $next_id = $ilDB->nextId("il_dcl_stloc" . $datatype->getStorageLocation() . "_value");
55 $query .= " (" . $ilDB->quote($value, $datatype->getDbType()) . ", " . $ilDB->quote($this->getId(), "integer") . ", "
56 . $ilDB->quote($next_id, "integer") . "),";
57 }
58 $query = substr($query, 0, - 1);
59 $ilDB->manipulate($query);
60 }
61
62
66 public function getValue() {
67 $this->loadValue();
68
69 return $this->value;
70 }
71
72
73 protected function loadValueSorted() {
74 if ($this->value === NULL) {
75
76 global $ilDB;
77 $datatype = $this->field->getDatatype();
78 $refField = ilDataCollectionCache::getFieldCache($this->getField()->getFieldRef());
79
80 $supported_internal_types = array(
84 );
85
86 $supported_types = array_merge(array(
90 ), $supported_internal_types);
91 $datatypeId = $refField->getDatatypeId();
92 if (in_array($datatypeId, $supported_types)) {
93 if (in_array($datatypeId, $supported_internal_types)) {
94 $query = "SELECT stlocOrig.value AS value, ilias_object.title AS value_ref ";
95 } else {
96 $query = "SELECT stlocOrig.value AS value, stlocRef.value AS value_ref ";
97 }
98 $query .= "FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value AS stlocOrig ";
99
100 $query .= " INNER JOIN il_dcl_record_field AS refField ON stlocOrig.value = refField.record_id AND refField.field_id = "
101 . $ilDB->quote($refField->getId(), "integer");
102 $query .= " INNER JOIN il_dcl_stloc" . $refField->getStorageLocation()
103 . "_value AS stlocRef ON stlocRef.record_field_id = refField.id ";
104 } else {
105 $query = "SELECT stlocOrig.value AS value ";
106 $query .= "FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value AS stlocOrig ";
107 }
108
109 switch ($datatypeId) {
111 $query .= " INNER JOIN object_reference AS ilias_ref ON ilias_ref.ref_id = stlocRef.value ";
112 $query .= " INNER JOIN object_data AS ilias_object ON ilias_object.obj_id = ilias_ref.obj_id ";
113 break;
116 $query .= " INNER JOIN object_data AS ilias_object ON ilias_object.obj_id = stlocRef.value ";
117 break;
118 }
119 $query .= " WHERE stlocOrig.record_field_id = " . $ilDB->quote($this->id, "integer");
120 if (in_array($datatypeId, $supported_types)) {
121 $query .= " ORDER BY value_ref ASC";
122 }
123
124 $set = $ilDB->query($query);
125
126 $this->value = array();
127 while ($rec = $ilDB->fetchAssoc($set)) {
128 $this->value[] = $rec['value'];
129 }
130 }
131 }
132
133
134 protected function loadValue() {
135 if ($this->value === NULL) {
136 global $ilDB;
137 $datatype = $this->field->getDatatype();
138 $query = "SELECT * FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
139 . $ilDB->quote($this->id, "integer");
140 $set = $ilDB->query($query);
141 $this->value = array();
142 while ($rec = $ilDB->fetchAssoc($set)) {
143 $this->value[] = $rec['value'];
144 }
145 }
146 }
147
148
154 public function getSingleHTML($options = NULL) {
155 $ilDataCollectionNReferenceFieldGUI = new ilDataCollectionNReferenceFieldGUI($this);
156 return $ilDataCollectionNReferenceFieldGUI->getSingleHTML($options);
157 }
158
159
160
167 public function getLinkHTML($link, $value) {
168 if ($link == "[" . $this->getField()->getTitle() . "]") {
169 $link = NULL;
170 }
171
172 return parent::getLinkHTML($link, $value);
173 }
174
175
179 public function getHTML() {
180 $ilDataCollectionNReferenceFieldGUI = new ilDataCollectionNReferenceFieldGUI($this);
181 return $ilDataCollectionNReferenceFieldGUI->getHTML();
182 }
183
184 public function getValueFromExcel($excel, $row, $col){
185 global $lng;
186 $stringValue = $excel->val($row, $col);
187 $this->getReferencesFromString($stringValue);
188 $referenceIds = $this->getReferencesFromString($stringValue);
189 if (!count($referenceIds)) {
190 $warning = "(" . $col . ", " . ilDataCollectionImporter::getExcelCharForInteger($col) . ") " . $lng->txt("dcl_no_such_reference") . " "
191 . $stringValue;
192 return array('warning' => $warning);
193 }
194
195 return $referenceIds;
196 }
197
201 public function getExportValue() {
202 $values = $this->getValue();
203 $names = array();
204 foreach ($values as $value) {
205 if ($value) {
207 $names[] = $ref_rec->getRecordField($this->getField()->getFieldRef())->getValue();
208 }
209 }
210 $string = "";
211 foreach ($names as $name) {
212 $string .= $name . ", ";
213 }
214 if (!count($names)) {
215 return "";
216 }
217 $string = substr($string, 0, - 2);
218
219 return $string;
220 }
221
229 protected function getReferencesFromString($stringValues) {
230 $slicedStrings = explode(", ", $stringValues);
231 $slicedReferences = array();
232 $resolved = 0;
233 for($i = 0; $i < count($slicedStrings); $i++) {
234 //try to find a reference since the last resolved value separated by a comma.
235 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "hello, world".
236 $searchString = implode(array_slice($slicedStrings, $resolved, $i - $resolved + 1));
237 if($ref = $this->getReferenceFromValue($searchString)){
238 $slicedReferences[] = $ref;
239 $resolved = $i;
240 continue;
241 }
242
243 //try to find a reference with the current index.
244 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "world".
245 $searchString = $slicedStrings[$i];
246 if($ref = $this->getReferenceFromValue($searchString)){
247 $slicedReferences[] = $ref;
248 $resolved = $i;
249 continue;
250 }
251 }
252 return $slicedReferences;
253 }
254}
255
256?>
static getRecordCache($record_id=0)
Class ilDataCollectionNReferenceField.
getReferencesFromString($stringValues)
This method tries to get as many valid references out of a string separated by commata.
getSingleHTML($options=NULL)
@description this funciton is used to in the viewdefinition of a single record.
global $ilDB
if(!is_array($argv)) $options