ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
4require_once './Modules/DataCollection/exceptions/class.ilDclInputException.php';
5
19{
20
24 protected $id;
28 protected $field;
32 protected $record;
33
38
46 protected $value;
50 protected $user;
54 protected $ctrl;
58 protected $db;
59
63 protected $lng;
64
70 {
71 global $DIC;
72 $ilCtrl = $DIC['ilCtrl'];
73 $ilUser = $DIC['ilUser'];
74 $ilDB = $DIC['ilDB'];
75 $lng = $DIC['lng'];
76 $this->record = $record;
77 $this->field = $field;
78 $this->ctrl = $ilCtrl;
79 $this->user = $ilUser;
80 $this->db = $ilDB;
81 $this->lng = $lng;
82 $this->doRead();
83 }
84
85
89 protected function doRead()
90 {
91 if (!$this->getRecord()->getId()) {
92 return;
93 }
94
95 $query = "SELECT * FROM il_dcl_record_field WHERE field_id = " . $this->db->quote($this->getField()->getId(), "integer") . " AND record_id = "
96 . $this->db->quote($this->getRecord()->getId(), "integer");
97 $set = $this->db->query($query);
98 $rec = $this->db->fetchAssoc($set);
99 $this->id = $rec['id'];
100
101 $this->loadValue();
102 }
103
104
108 public function doCreate()
109 {
110 $id = $this->db->nextId("il_dcl_record_field");
111 $query = "INSERT INTO il_dcl_record_field (id, record_id, field_id) VALUES (" . $this->db->quote($id, "integer") . ", "
112 . $this->db->quote($this->getRecord()->getId(), "integer") . ", " . $this->db->quote($this->getField()->getId(), "text") . ")";
113 $this->db->manipulate($query);
114 $this->id = $id;
115 }
116
117
121 public function doUpdate()
122 {
123 //$this->loadValue(); //Removed Mantis #0011799
124 $datatype = $this->getField()->getDatatype();
125 $storage_location = ($this->getField()->getStorageLocationOverride() !== null)? $this->getField()->getStorageLocationOverride() : $datatype->getStorageLocation();
126
127 if ($storage_location != 0) {
128 $query = "DELETE FROM il_dcl_stloc" . $storage_location . "_value WHERE record_field_id = "
129 . $this->db->quote($this->id, "integer");
130 $this->db->manipulate($query);
131
132 $next_id = $this->db->nextId("il_dcl_stloc" . $storage_location . "_value");
133
134 // This is a workaround to ensure that date values in stloc3 are never stored as NULL, which is not allowed
135 if ($storage_location == 3 && (is_null($this->value) || empty($this->value))) {
136 $this->value = '0000-00-00 00:00:00';
137 }
138
139 $value = $this->serializeData($this->value);
140
141 if ($this->getId() == 0) {
142 $this->doCreate();
143 }
144
145 $insert_params = array(
146 "value" => array( $datatype->getDbType(), $value),
147 "record_field_id" => array( "integer", $this->getId()),
148 "id" => array( "integer", $next_id )
149 );
150
151 $this->db->insert("il_dcl_stloc" . $storage_location . "_value", $insert_params);
152 }
153 }
154
155
159 public function delete()
160 {
161 $datatype = $this->getField()->getDatatype();
162 $storage_location = ($this->getField()->getStorageLocationOverride() !== null)? $this->getField()->getStorageLocationOverride() : $datatype->getStorageLocation();
163
164 if ($storage_location != 0) {
165 $query = "DELETE FROM il_dcl_stloc" . $storage_location . "_value WHERE record_field_id = "
166 . $this->db->quote($this->id, "integer");
167 $this->db->manipulate($query);
168 }
169
170 $query2 = "DELETE FROM il_dcl_record_field WHERE id = " . $this->db->quote($this->id, "integer");
171 $this->db->manipulate($query2);
172 }
173
174
178 public function getValue()
179 {
180 $this->loadValue();
181
182 return $this->value;
183 }
184
185
190 {
191 return $this->getValue();
192 }
193
200 public function serializeData($value)
201 {
202 if (is_array($value)) {
203 $value = json_encode($value);
204 }
205 return $value;
206 }
207
208
215 public function deserializeData($value)
216 {
217 $deserialize = json_decode($value, true);
218 if (is_array($deserialize)) {
219 return $deserialize;
220 }
221 return $value;
222 }
223
230 public function setValue($value, $omit_parsing = false)
231 {
232 $this->loadValue();
233 if (!$omit_parsing) {
234 $tmp = $this->parseValue($value, $this);
236 //if parse value fails keep the old value
237 if ($tmp !== false) {
238 $this->value = $tmp;
239 }
240 } else {
241 $this->value = $value;
242 }
243 }
244
248 public function setValueFromForm($form)
249 {
250 $value = $form->getInput("field_" . $this->getField()->getId());
251
252 $this->setValue($value);
253 }
254
262 public function parseExportValue($value)
263 {
264 return $value;
265 }
266
273 public function getValueFromExcel($excel, $row, $col)
274 {
275 $value = $excel->getCell($row, $col);
276
277 return $value;
278 }
279
287 public function parseValue($value)
288 {
289 return $value;
290 }
291
292
296 public function getExportValue()
297 {
298 return $this->parseExportValue($this->getValue());
299 }
300
306 public function fillExcelExport(ilExcel $worksheet, &$row, &$col)
307 {
308 $worksheet->setCell($row, $col, $this->getExportValue());
309 $col++;
310 }
311
315 public function getPlainText()
316 {
317 return $this->getExportValue();
318 }
319
320 public function getSortingValue($link = true)
321 {
322 return $this->parseSortingValue($this->getValue(), $this, $link);
323 }
324
325
329 public function addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
330 {
331 ;
332 if (!is_array($this->getValue())) {
333 $confirmation->addHiddenItem('field_' . $this->field->getId(), $this->getValue());
334 } else {
335 foreach ($this->getValue() as $key => $value) {
336 $confirmation->addHiddenItem('field_' . $this->field->getId() . "[$key]", $value);
337 }
338 }
339 }
340
350 public function parseSortingValue($value, $link = true)
351 {
352 return $value;
353 }
354
358 protected function loadValue()
359 {
360 if ($this->value === null) {
361 $datatype = $this->getField()->getDatatype();
362
363 $storage_location = ($this->getField()->getStorageLocationOverride() !== null)? $this->getField()->getStorageLocationOverride() : $datatype->getStorageLocation();
364 if ($storage_location != 0) {
365 $query = "SELECT * FROM il_dcl_stloc" . $storage_location . "_value WHERE record_field_id = "
366 . $this->db->quote($this->id, "integer");
367
368 $set = $this->db->query($query);
369 $rec = $this->db->fetchAssoc($set);
370 $value = $this->deserializeData($rec['value']);
371 $this->value = $value;
372 }
373 }
374 }
375
376
380 public function cloneStructure(ilDclBaseRecordFieldModel $old_record_field)
381 {
382 $this->setValue($old_record_field->getValue());
383 $this->doUpdate();
384 }
385
386
390 public function afterClone()
391 {
392 }
393
394
398 public function getField()
399 {
400 return $this->field;
401 }
402
403
407 public function getId()
408 {
409 return $this->id;
410 }
411
412
416 public function getRecord()
417 {
418 return $this->record;
419 }
420
424 public function getRecordRepresentation()
425 {
427 }
428
429
434 {
435 $this->record_representation = $record_representation;
436 }
437
438
442 public function getFieldRepresentation()
443 {
445 }
446
447
452 {
453 $this->field_representation = $field_representation;
454 }
455}
$worksheet
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.
$key
Definition: croninfo.php:18
global $ilCtrl
Definition: ilias.php:18
$query
if(isset($_POST['submit'])) $form
$old
global $DIC
Definition: saml.php:7
global $ilDB
$ilUser
Definition: imgupload.php:18