ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilDclNReferenceRecordFieldModel.php
Go to the documentation of this file.
1<?php
2
9{
10
14 protected $max_reference_length = 20;
15
16
20 public function getMaxReferenceLength()
21 {
23 }
24
25
30 {
31 $this->max_reference_length = $max_reference_length;
32 }
33
34
35 public function doUpdate()
36 {
37 global $DIC;
38 $ilDB = $DIC['ilDB'];
39
40 $values = $this->getValue();
41 if (!is_array($values)) {
42 $values = array($values);
43 }
44 $datatype = $this->getField()->getDatatype();
45
46 $query = "DELETE FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
47 . $ilDB->quote($this->id, "integer");
48 $ilDB->manipulate($query);
49
50 if (!count($values) || $values[0] == 0) {
51 return;
52 }
53
54 $query = "INSERT INTO il_dcl_stloc" . $datatype->getStorageLocation() . "_value (value, record_field_id, id) VALUES";
55 foreach ($values as $value) {
56 $next_id = $ilDB->nextId("il_dcl_stloc" . $datatype->getStorageLocation() . "_value");
57 $query .= " (" . $ilDB->quote($value, $datatype->getDbType()) . ", " . $ilDB->quote($this->getId(), "integer") . ", "
58 . $ilDB->quote($next_id, "integer") . "),";
59 }
60 $query = substr($query, 0, -1);
61 $ilDB->manipulate($query);
62 }
63
64
68 public function getValue()
69 {
70 $this->loadValue();
71
72 return $this->value;
73 }
74
75
76 protected function loadValueSorted()
77 {
78 if ($this->value === null) {
79 global $DIC;
80 $ilDB = $DIC['ilDB'];
81 $datatype = $this->getField()->getDatatype();
82 $refField = ilDclCache::getFieldCache($this->getField()->getFieldRef());
83
84 $supported_internal_types = array(
88 );
89
90 $supported_types = array_merge(
91 array(
95 ),
96 $supported_internal_types
97 );
98 $datatypeId = $refField->getDatatypeId();
99 if (in_array($datatypeId, $supported_types)) {
100 if (in_array($datatypeId, $supported_internal_types)) {
101 $query = "SELECT stlocOrig.value AS value, ilias_object.title AS value_ref ";
102 } else {
103 $query = "SELECT stlocOrig.value AS value, stlocRef.value AS value_ref ";
104 }
105 $query .= "FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value AS stlocOrig ";
106
107 $query .= " INNER JOIN il_dcl_record_field AS refField ON stlocOrig.value = refField.record_id AND refField.field_id = "
108 . $ilDB->quote($refField->getId(), "integer");
109 $query .= " INNER JOIN il_dcl_stloc" . $refField->getStorageLocation()
110 . "_value AS stlocRef ON stlocRef.record_field_id = refField.id ";
111 } else {
112 $query = "SELECT stlocOrig.value AS value ";
113 $query .= "FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value AS stlocOrig ";
114 }
115
116 switch ($datatypeId) {
118 $query .= " INNER JOIN object_reference AS ilias_ref ON ilias_ref.ref_id = stlocRef.value ";
119 $query .= " INNER JOIN object_data AS ilias_object ON ilias_object.obj_id = ilias_ref.obj_id ";
120 break;
123 $query .= " INNER JOIN object_data AS ilias_object ON ilias_object.obj_id = stlocRef.value ";
124 break;
125 }
126 $query .= " WHERE stlocOrig.record_field_id = " . $ilDB->quote($this->id, "integer");
127 if (in_array($datatypeId, $supported_types)) {
128 $query .= " ORDER BY value_ref ASC";
129 }
130
131 $set = $ilDB->query($query);
132
133 $this->value = array();
134 while ($rec = $ilDB->fetchAssoc($set)) {
135 $this->value[] = $rec['value'];
136 }
137 }
138 }
139
140
141 protected function loadValue()
142 {
143 if ($this->value === null) {
144 global $DIC;
145 $ilDB = $DIC['ilDB'];
146 $datatype = $this->getField()->getDatatype();
147 $query = "SELECT * FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
148 . $ilDB->quote($this->id, "integer");
149 $set = $ilDB->query($query);
150 $this->value = array();
151 while ($rec = $ilDB->fetchAssoc($set)) {
152 $this->value[] = $rec['value'];
153 }
154 }
155 }
156
157
163 public function getSingleHTML($options = null)
164 {
165 $ilDataCollectionNReferenceFieldGUI = new ilDclNReferenceFieldGUI($this);
166
167 return $ilDataCollectionNReferenceFieldGUI->getSingleHTML($options);
168 }
169
170
177 public function getLinkHTML($link, $value)
178 {
179 if ($link == "[" . $this->getField()->getTitle() . "]") {
180 $link = null;
181 }
182
183 return parent::getLinkHTML($link, $value);
184 }
185
186
190 public function getHTML()
191 {
192 $ilDataCollectionNReferenceFieldGUI = new ilDclNReferenceFieldGUI($this);
193
194 return $ilDataCollectionNReferenceFieldGUI->getHTML();
195 }
196
197
198 public function getValueFromExcel($excel, $row, $col)
199 {
200 global $DIC;
201 $lng = $DIC['lng'];
202 $stringValue = parent::getValueFromExcel($excel, $row, $col);
203 $this->getReferencesFromString($stringValue);
204 $referenceIds = $this->getReferencesFromString($stringValue);
205 if (!count($referenceIds) && $stringValue) {
206 $warning = "(" . $row . ", " . ilDataCollectionImporter::getExcelCharForInteger($col + 1) . ") " . $lng->txt("dcl_no_such_reference") . " "
207 . $stringValue;
208
209 return array('warning' => $warning);
210 }
211
212 return $referenceIds;
213 }
214
215
219 public function getExportValue()
220 {
221 $values = $this->getValue();
222 $names = array();
223 foreach ($values as $value) {
224 if ($value) {
226 $names[] = $ref_rec->getRecordField($this->getField()->getFieldRef())->getValue();
227 }
228 }
229 $string = "";
230 foreach ($names as $name) {
231 $string .= $name . ", ";
232 }
233 if (!count($names)) {
234 return "";
235 }
236 $string = substr($string, 0, -2);
237
238 return $string;
239 }
240
241
251 protected function getReferencesFromString($stringValues)
252 {
253 $slicedStrings = explode(", ", $stringValues);
254 $slicedReferences = array();
255 $resolved = 0;
256 for ($i = 0; $i < count($slicedStrings); $i++) {
257 //try to find a reference since the last resolved value separated by a comma.
258 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "hello, world".
259 $searchString = implode(array_slice($slicedStrings, $resolved, $i - $resolved + 1));
260 if ($ref = $this->getReferenceFromValue($searchString)) {
261 $slicedReferences[] = $ref;
262 $resolved = $i;
263 continue;
264 }
265
266 //try to find a reference with the current index.
267 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "world".
268 $searchString = $slicedStrings[$i];
269 if ($ref = $this->getReferenceFromValue($searchString)) {
270 $slicedReferences[] = $ref;
271 $resolved = $i;
272 continue;
273 }
274 }
275
276 return $slicedReferences;
277 }
278}
An exception for terminatinating execution or to throw for unit testing.
static getRecordCache($record_id=0)
static getFieldCache($field_id=0)
Class ilDclNReferenceFieldGUI.
getSingleHTML($options=null)
@description this funciton is used to in the viewdefinition of a single record.
getReferencesFromString($stringValues)
This method tries to get as many valid references out of a string separated by commata.
if($format !==null) $name
Definition: metadata.php:230
$i
Definition: metadata.php:24
$query
global $ilDB
$DIC
Definition: xapitoken.php:46