ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
36
37 public function doUpdate()
38 {
39 global $DIC;
40 $ilDB = $DIC['ilDB'];
41
42 $values = $this->getValue();
43 if (!is_array($values)) {
44 $values = array( $values );
45 }
46 $datatype = $this->getField()->getDatatype();
47
48 $query = "DELETE FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
49 . $ilDB->quote($this->id, "integer");
50 $ilDB->manipulate($query);
51
52 if (!count($values) || $values[0] == 0) {
53 return;
54 }
55
56 $query = "INSERT INTO il_dcl_stloc" . $datatype->getStorageLocation() . "_value (value, record_field_id, id) VALUES";
57 foreach ($values as $value) {
58 $next_id = $ilDB->nextId("il_dcl_stloc" . $datatype->getStorageLocation() . "_value");
59 $query .= " (" . $ilDB->quote($value, $datatype->getDbType()) . ", " . $ilDB->quote($this->getId(), "integer") . ", "
60 . $ilDB->quote($next_id, "integer") . "),";
61 }
62 $query = substr($query, 0, -1);
63 $ilDB->manipulate($query);
64 }
65
66
70 public function getValue()
71 {
72 $this->loadValue();
73
74 return $this->value;
75 }
76
77
78 protected function loadValueSorted()
79 {
80 if ($this->value === null) {
81 global $DIC;
82 $ilDB = $DIC['ilDB'];
83 $datatype = $this->getField()->getDatatype();
84 $refField = ilDclCache::getFieldCache($this->getField()->getFieldRef());
85
86 $supported_internal_types = array(
90 );
91
92 $supported_types = array_merge(array(
96 ), $supported_internal_types);
97 $datatypeId = $refField->getDatatypeId();
98 if (in_array($datatypeId, $supported_types)) {
99 if (in_array($datatypeId, $supported_internal_types)) {
100 $query = "SELECT stlocOrig.value AS value, ilias_object.title AS value_ref ";
101 } else {
102 $query = "SELECT stlocOrig.value AS value, stlocRef.value AS value_ref ";
103 }
104 $query .= "FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value AS stlocOrig ";
105
106 $query .= " INNER JOIN il_dcl_record_field AS refField ON stlocOrig.value = refField.record_id AND refField.field_id = "
107 . $ilDB->quote($refField->getId(), "integer");
108 $query .= " INNER JOIN il_dcl_stloc" . $refField->getStorageLocation()
109 . "_value AS stlocRef ON stlocRef.record_field_id = refField.id ";
110 } else {
111 $query = "SELECT stlocOrig.value AS value ";
112 $query .= "FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value AS stlocOrig ";
113 }
114
115 switch ($datatypeId) {
117 $query .= " INNER JOIN object_reference AS ilias_ref ON ilias_ref.ref_id = stlocRef.value ";
118 $query .= " INNER JOIN object_data AS ilias_object ON ilias_object.obj_id = ilias_ref.obj_id ";
119 break;
122 $query .= " INNER JOIN object_data AS ilias_object ON ilias_object.obj_id = stlocRef.value ";
123 break;
124 }
125 $query .= " WHERE stlocOrig.record_field_id = " . $ilDB->quote($this->id, "integer");
126 if (in_array($datatypeId, $supported_types)) {
127 $query .= " ORDER BY value_ref ASC";
128 }
129
130 $set = $ilDB->query($query);
131
132 $this->value = array();
133 while ($rec = $ilDB->fetchAssoc($set)) {
134 $this->value[] = $rec['value'];
135 }
136 }
137 }
138
139
140 protected function loadValue()
141 {
142 if ($this->value === null) {
143 global $DIC;
144 $ilDB = $DIC['ilDB'];
145 $datatype = $this->getField()->getDatatype();
146 $query = "SELECT * FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
147 . $ilDB->quote($this->id, "integer");
148 $set = $ilDB->query($query);
149 $this->value = array();
150 while ($rec = $ilDB->fetchAssoc($set)) {
151 $this->value[] = $rec['value'];
152 }
153 }
154 }
155
156
162 public function getSingleHTML($options = null)
163 {
164 $ilDataCollectionNReferenceFieldGUI = new ilDclNReferenceFieldGUI($this);
165 return $ilDataCollectionNReferenceFieldGUI->getSingleHTML($options);
166 }
167
168
169
176 public function getLinkHTML($link, $value)
177 {
178 if ($link == "[" . $this->getField()->getTitle() . "]") {
179 $link = null;
180 }
181
182 return parent::getLinkHTML($link, $value);
183 }
184
185
189 public function getHTML()
190 {
191 $ilDataCollectionNReferenceFieldGUI = new ilDclNReferenceFieldGUI($this);
192 return $ilDataCollectionNReferenceFieldGUI->getHTML();
193 }
194
195 public function getValueFromExcel($excel, $row, $col)
196 {
197 global $DIC;
198 $lng = $DIC['lng'];
199 $stringValue = parent::getValueFromExcel($excel, $row, $col);
200 $this->getReferencesFromString($stringValue);
201 $referenceIds = $this->getReferencesFromString($stringValue);
202 if (!count($referenceIds) && $stringValue) {
203 $warning = "(" . $row . ", " . ilDataCollectionImporter::getExcelCharForInteger($col+1) . ") " . $lng->txt("dcl_no_such_reference") . " "
204 . $stringValue;
205 return array('warning' => $warning);
206 }
207
208 return $referenceIds;
209 }
210
214 public function getExportValue()
215 {
216 $values = $this->getValue();
217 $names = array();
218 foreach ($values as $value) {
219 if ($value) {
221 $names[] = $ref_rec->getRecordField($this->getField()->getFieldRef())->getValue();
222 }
223 }
224 $string = "";
225 foreach ($names as $name) {
226 $string .= $name . ", ";
227 }
228 if (!count($names)) {
229 return "";
230 }
231 $string = substr($string, 0, -2);
232
233 return $string;
234 }
235
243 protected function getReferencesFromString($stringValues)
244 {
245 $slicedStrings = explode(", ", $stringValues);
246 $slicedReferences = array();
247 $resolved = 0;
248 for ($i = 0; $i < count($slicedStrings); $i++) {
249 //try to find a reference since the last resolved value separated by a comma.
250 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "hello, world".
251 $searchString = implode(array_slice($slicedStrings, $resolved, $i - $resolved + 1));
252 if ($ref = $this->getReferenceFromValue($searchString)) {
253 $slicedReferences[] = $ref;
254 $resolved = $i;
255 continue;
256 }
257
258 //try to find a reference with the current index.
259 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "world".
260 $searchString = $slicedStrings[$i];
261 if ($ref = $this->getReferenceFromValue($searchString)) {
262 $slicedReferences[] = $ref;
263 $resolved = $i;
264 continue;
265 }
266 }
267 return $slicedReferences;
268 }
269}
$warning
Definition: X509warning.php:13
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
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.
$i
Definition: disco.tpl.php:19
if($format !==null) $name
Definition: metadata.php:146
$query
global $DIC
Definition: saml.php:7
global $ilDB