ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDclBaseRecordFieldModel.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
17{
18
22 protected $id;
26 protected $field;
30 protected $record;
42 protected $value;
46 protected $user;
50 protected $ctrl;
54 protected $db;
58 protected $lng;
59
60
66 {
67 global $DIC;
68 $ilCtrl = $DIC['ilCtrl'];
69 $ilUser = $DIC['ilUser'];
70 $ilDB = $DIC['ilDB'];
71 $lng = $DIC['lng'];
72 $this->record = $record;
73 $this->field = $field;
74 $this->ctrl = $ilCtrl;
75 $this->user = $ilUser;
76 $this->db = $ilDB;
77 $this->lng = $lng;
78 $this->doRead();
79 }
80
81
85 protected function doRead()
86 {
87 if (!$this->getRecord()->getId()) {
88 return;
89 }
90
91 $query = "SELECT * FROM il_dcl_record_field WHERE field_id = " . $this->db->quote($this->getField()->getId(), "integer") . " AND record_id = "
92 . $this->db->quote($this->getRecord()->getId(), "integer");
93 $set = $this->db->query($query);
94 $rec = $this->db->fetchAssoc($set);
95 $this->id = $rec['id'];
96
97 $this->loadValue();
98 }
99
100
104 public function doCreate()
105 {
106 $id = $this->db->nextId("il_dcl_record_field");
107 $query = "INSERT INTO il_dcl_record_field (id, record_id, field_id) VALUES (" . $this->db->quote($id, "integer") . ", "
108 . $this->db->quote($this->getRecord()->getId(), "integer") . ", " . $this->db->quote($this->getField()->getId(), "text") . ")";
109 $this->db->manipulate($query);
110 $this->id = $id;
111 }
112
113
117 public function doUpdate()
118 {
119 //$this->loadValue(); //Removed Mantis #0011799
120 $datatype = $this->getField()->getDatatype();
121 $storage_location = ($this->getField()->getStorageLocationOverride() !== null) ? $this->getField()->getStorageLocationOverride() : $datatype->getStorageLocation();
122
123 if ($storage_location != 0) {
124 $query = "DELETE FROM il_dcl_stloc" . $storage_location . "_value WHERE record_field_id = "
125 . $this->db->quote($this->id, "integer");
126 $this->db->manipulate($query);
127
128 $next_id = $this->db->nextId("il_dcl_stloc" . $storage_location . "_value");
129
130 // This is a workaround to ensure that date values in stloc3 are never stored as NULL, which is not allowed
131 if ($storage_location == 3 && (is_null($this->value) || empty($this->value))) {
132 $this->value = '0000-00-00 00:00:00';
133 }
134
135 $value = $this->serializeData($this->value);
136
137 if ($this->getId() == 0) {
138 $this->doCreate();
139 }
140
141 $insert_params = array(
142 "value" => array($datatype->getDbType(), $value),
143 "record_field_id" => array("integer", $this->getId()),
144 "id" => array("integer", $next_id),
145 );
146
147 $this->db->insert("il_dcl_stloc" . $storage_location . "_value", $insert_params);
148 }
149 }
150
151
155 public function delete()
156 {
157 $datatype = $this->getField()->getDatatype();
158 $storage_location = ($this->getField()->getStorageLocationOverride() !== null) ? $this->getField()->getStorageLocationOverride() : $datatype->getStorageLocation();
159
160 if ($storage_location != 0) {
161 $query = "DELETE FROM il_dcl_stloc" . $storage_location . "_value WHERE record_field_id = "
162 . $this->db->quote($this->id, "integer");
163 $this->db->manipulate($query);
164 }
165
166 $query2 = "DELETE FROM il_dcl_record_field WHERE id = " . $this->db->quote($this->id, "integer");
167 $this->db->manipulate($query2);
168 }
169
170
174 public function getValue()
175 {
176 $this->loadValue();
177
178 return $this->value;
179 }
180
181
186 {
187 return $this->getValue();
188 }
189
190
198 public function serializeData($value)
199 {
200 if (is_array($value)) {
201 $value = json_encode($value);
202 }
203
204 return $value;
205 }
206
207
215 public function deserializeData($value)
216 {
217 $deserialize = json_decode($value, true);
218 if (is_array($deserialize)) {
219 return $deserialize;
220 }
221
222 return $value;
223 }
224
225
232 public function setValue($value, $omit_parsing = false)
233 {
234 $this->loadValue();
235 if (!$omit_parsing) {
236 $tmp = $this->parseValue($value, $this);
237 $old = $this->value;
238 //if parse value fails keep the old value
239 if ($tmp !== false) {
240 $this->value = $tmp;
241 }
242 } else {
243 $this->value = $value;
244 }
245 }
246
247
251 public function setValueFromForm($form)
252 {
253 $value = $form->getInput("field_" . $this->getField()->getId());
254
255 $this->setValue($value);
256 }
257
258
262 public function getFormulaValue()
263 {
264 return $this->getExportValue();
265 }
266
267
275 public function parseExportValue($value)
276 {
277 return $value;
278 }
279
280
288 public function getValueFromExcel($excel, $row, $col)
289 {
290 $value = $excel->getCell($row, $col);
291
292 return $value;
293 }
294
295
303 public function parseValue($value)
304 {
305 return $value;
306 }
307
308
312 public function getExportValue()
313 {
314 return $this->parseExportValue($this->getValue());
315 }
316
317
323 public function fillExcelExport(ilExcel $worksheet, &$row, &$col)
324 {
325 $worksheet->setCell($row, $col, $this->getExportValue());
326 $col++;
327 }
328
329
333 public function getPlainText()
334 {
335 return $this->getExportValue();
336 }
337
338
339 public function getSortingValue($link = true)
340 {
341 return $this->parseSortingValue($this->getValue(), $this, $link);
342 }
343
344
348 public function addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
349 {
350 ;
351 if (!is_array($this->getValue())) {
352 $confirmation->addHiddenItem('field_' . $this->field->getId(), $this->getValue());
353 } else {
354 foreach ($this->getValue() as $key => $value) {
355 $confirmation->addHiddenItem('field_' . $this->field->getId() . "[$key]", $value);
356 }
357 }
358 }
359
360
370 public function parseSortingValue($value, $link = true)
371 {
372 return $value;
373 }
374
375
379 protected function loadValue()
380 {
381 if ($this->value === null) {
382 $datatype = $this->getField()->getDatatype();
383
384 $storage_location = ($this->getField()->getStorageLocationOverride() !== null) ? $this->getField()->getStorageLocationOverride() : $datatype->getStorageLocation();
385 if ($storage_location != 0) {
386 $query = "SELECT * FROM il_dcl_stloc" . $storage_location . "_value WHERE record_field_id = "
387 . $this->db->quote($this->id, "integer");
388
389 $set = $this->db->query($query);
390 $rec = $this->db->fetchAssoc($set);
391 $value = $this->deserializeData($rec['value']);
392 $this->value = $value;
393 }
394 }
395 }
396
397
401 public function cloneStructure(ilDclBaseRecordFieldModel $old_record_field)
402 {
403 $this->setValue($old_record_field->getValue());
404 $this->doUpdate();
405 }
406
407
411 public function afterClone()
412 {
413 }
414
415
419 public function getField()
420 {
421 return $this->field;
422 }
423
424
428 public function getId()
429 {
430 return $this->id;
431 }
432
433
437 public function getRecord()
438 {
439 return $this->record;
440 }
441
442
446 public function getRecordRepresentation()
447 {
449 }
450
451
456 {
457 $this->record_representation = $record_representation;
458 }
459
460
464 public function getFieldRepresentation()
465 {
467 }
468
469
474 {
475 $this->field_representation = $field_representation;
476 }
477}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
addHiddenItem($a_post_var, $a_value)
Add hidden item.
Class ilDclBaseFieldModel.
addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
setRecordRepresentation($record_representation)
deserializeData($value)
Deserialize data before applying to field.
parseValue($value)
Function to parse incoming data from form input value $value.
parseExportValue($value)
Function to parse incoming data from form input value $value.
fillExcelExport(ilExcel $worksheet, &$row, &$col)
parseSortingValue($value, $link=true)
Returns sortable value for the specific field-types.
doCreate()
Creates an Id and a database entry.
serializeData($value)
Serialize data before storing to db.
setValue($value, $omit_parsing=false)
Set value for record field.
doRead()
Read object data from database.
__construct(ilDclBaseRecordModel $record, ilDclBaseFieldModel $field)
cloneStructure(ilDclBaseRecordFieldModel $old_record_field)
Class ilDclBaseRecordModel.
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
$query
global $ilDB