ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilDclNReferenceRecordFieldModel.php
Go to the documentation of this file.
1<?php
2require_once("./Modules/DataCollection/classes/Fields/NReference/class.ilDclNReferenceFieldGUI.php");
3
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 $DIC;
37 $ilDB = $DIC['ilDB'];
38
39 $values = $this->getValue();
40 if (!is_array($values)) {
41 $values = array( $values );
42 }
43 $datatype = $this->getField()->getDatatype();
44
45 $query = "DELETE FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
46 . $ilDB->quote($this->id, "integer");
47 $ilDB->manipulate($query);
48
49 if (!count($values) || $values[0] == 0) {
50 return;
51 }
52
53 $query = "INSERT INTO il_dcl_stloc" . $datatype->getStorageLocation() . "_value (value, record_field_id, id) VALUES";
54 foreach ($values as $value) {
55 $next_id = $ilDB->nextId("il_dcl_stloc" . $datatype->getStorageLocation() . "_value");
56 $query .= " (" . $ilDB->quote($value, $datatype->getDbType()) . ", " . $ilDB->quote($this->getId(), "integer") . ", "
57 . $ilDB->quote($next_id, "integer") . "),";
58 }
59 $query = substr($query, 0, - 1);
60 $ilDB->manipulate($query);
61 }
62
63
67 public function getValue() {
68 $this->loadValue();
69
70 return $this->value;
71 }
72
73
74 protected function loadValueSorted() {
75 if ($this->value === NULL) {
76
77 global $DIC;
78 $ilDB = $DIC['ilDB'];
79 $datatype = $this->getField()->getDatatype();
80 $refField = ilDclCache::getFieldCache($this->getField()->getFieldRef());
81
82 $supported_internal_types = array(
86 );
87
88 $supported_types = array_merge(array(
92 ), $supported_internal_types);
93 $datatypeId = $refField->getDatatypeId();
94 if (in_array($datatypeId, $supported_types)) {
95 if (in_array($datatypeId, $supported_internal_types)) {
96 $query = "SELECT stlocOrig.value AS value, ilias_object.title AS value_ref ";
97 } else {
98 $query = "SELECT stlocOrig.value AS value, stlocRef.value AS value_ref ";
99 }
100 $query .= "FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value AS stlocOrig ";
101
102 $query .= " INNER JOIN il_dcl_record_field AS refField ON stlocOrig.value = refField.record_id AND refField.field_id = "
103 . $ilDB->quote($refField->getId(), "integer");
104 $query .= " INNER JOIN il_dcl_stloc" . $refField->getStorageLocation()
105 . "_value AS stlocRef ON stlocRef.record_field_id = refField.id ";
106 } else {
107 $query = "SELECT stlocOrig.value AS value ";
108 $query .= "FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value AS stlocOrig ";
109 }
110
111 switch ($datatypeId) {
113 $query .= " INNER JOIN object_reference AS ilias_ref ON ilias_ref.ref_id = stlocRef.value ";
114 $query .= " INNER JOIN object_data AS ilias_object ON ilias_object.obj_id = ilias_ref.obj_id ";
115 break;
118 $query .= " INNER JOIN object_data AS ilias_object ON ilias_object.obj_id = stlocRef.value ";
119 break;
120 }
121 $query .= " WHERE stlocOrig.record_field_id = " . $ilDB->quote($this->id, "integer");
122 if (in_array($datatypeId, $supported_types)) {
123 $query .= " ORDER BY value_ref ASC";
124 }
125
126 $set = $ilDB->query($query);
127
128 $this->value = array();
129 while ($rec = $ilDB->fetchAssoc($set)) {
130 $this->value[] = $rec['value'];
131 }
132 }
133 }
134
135
136 protected function loadValue() {
137 if ($this->value === NULL) {
138 global $DIC;
139 $ilDB = $DIC['ilDB'];
140 $datatype = $this->getField()->getDatatype();
141 $query = "SELECT * FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
142 . $ilDB->quote($this->id, "integer");
143 $set = $ilDB->query($query);
144 $this->value = array();
145 while ($rec = $ilDB->fetchAssoc($set)) {
146 $this->value[] = $rec['value'];
147 }
148 }
149 }
150
151
157 public function getSingleHTML($options = NULL) {
158 $ilDataCollectionNReferenceFieldGUI = new ilDclNReferenceFieldGUI($this);
159 return $ilDataCollectionNReferenceFieldGUI->getSingleHTML($options);
160 }
161
162
163
170 public function getLinkHTML($link, $value) {
171 if ($link == "[" . $this->getField()->getTitle() . "]") {
172 $link = NULL;
173 }
174
175 return parent::getLinkHTML($link, $value);
176 }
177
178
182 public function getHTML() {
183 $ilDataCollectionNReferenceFieldGUI = new ilDclNReferenceFieldGUI($this);
184 return $ilDataCollectionNReferenceFieldGUI->getHTML();
185 }
186
187 public function getValueFromExcel($excel, $row, $col){
188 global $DIC;
189 $lng = $DIC['lng'];
190 $stringValue = parent::getValueFromExcel($excel, $row, $col);
191 $this->getReferencesFromString($stringValue);
192 $referenceIds = $this->getReferencesFromString($stringValue);
193 if (!count($referenceIds) && $stringValue) {
194 $warning = "(" . $row . ", " . ilDataCollectionImporter::getExcelCharForInteger($col+1) . ") " . $lng->txt("dcl_no_such_reference") . " "
195 . $stringValue;
196 return array('warning' => $warning);
197 }
198
199 return $referenceIds;
200 }
201
205 public function getExportValue() {
206 $values = $this->getValue();
207 $names = array();
208 foreach ($values as $value) {
209 if ($value) {
211 $names[] = $ref_rec->getRecordField($this->getField()->getFieldRef())->getValue();
212 }
213 }
214 $string = "";
215 foreach ($names as $name) {
216 $string .= $name . ", ";
217 }
218 if (!count($names)) {
219 return "";
220 }
221 $string = substr($string, 0, - 2);
222
223 return $string;
224 }
225
233 protected function getReferencesFromString($stringValues) {
234 $slicedStrings = explode(", ", $stringValues);
235 $slicedReferences = array();
236 $resolved = 0;
237 for($i = 0; $i < count($slicedStrings); $i++) {
238 //try to find a reference since the last resolved value separated by a comma.
239 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "hello, world".
240 $searchString = implode(array_slice($slicedStrings, $resolved, $i - $resolved + 1));
241 if($ref = $this->getReferenceFromValue($searchString)){
242 $slicedReferences[] = $ref;
243 $resolved = $i;
244 continue;
245 }
246
247 //try to find a reference with the current index.
248 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "world".
249 $searchString = $slicedStrings[$i];
250 if($ref = $this->getReferenceFromValue($searchString)){
251 $slicedReferences[] = $ref;
252 $resolved = $i;
253 continue;
254 }
255 }
256 return $slicedReferences;
257 }
258}
259
260?>
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.
global $ilDB
if(!is_array($argv)) $options
global $DIC