ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 require_once './Modules/DataCollection/exceptions/class.ilDclInputException.php';
5 
19 {
20 
24  protected $id;
28  protected $field;
32  protected $record;
44  protected $value;
48  protected $user;
52  protected $ctrl;
56  protected $db;
60  protected $lng;
61 
62 
68  {
69  global $DIC;
70  $ilCtrl = $DIC['ilCtrl'];
71  $ilUser = $DIC['ilUser'];
72  $ilDB = $DIC['ilDB'];
73  $lng = $DIC['lng'];
74  $this->record = $record;
75  $this->field = $field;
76  $this->ctrl = $ilCtrl;
77  $this->user = $ilUser;
78  $this->db = $ilDB;
79  $this->lng = $lng;
80  $this->doRead();
81  }
82 
83 
87  protected function doRead()
88  {
89  if (!$this->getRecord()->getId()) {
90  return;
91  }
92 
93  $query = "SELECT * FROM il_dcl_record_field WHERE field_id = " . $this->db->quote($this->getField()->getId(), "integer") . " AND record_id = "
94  . $this->db->quote($this->getRecord()->getId(), "integer");
95  $set = $this->db->query($query);
96  $rec = $this->db->fetchAssoc($set);
97  $this->id = $rec['id'];
98 
99  $this->loadValue();
100  }
101 
102 
106  public function doCreate()
107  {
108  $id = $this->db->nextId("il_dcl_record_field");
109  $query = "INSERT INTO il_dcl_record_field (id, record_id, field_id) VALUES (" . $this->db->quote($id, "integer") . ", "
110  . $this->db->quote($this->getRecord()->getId(), "integer") . ", " . $this->db->quote($this->getField()->getId(), "text") . ")";
111  $this->db->manipulate($query);
112  $this->id = $id;
113  }
114 
115 
119  public function doUpdate()
120  {
121  //$this->loadValue(); //Removed Mantis #0011799
122  $datatype = $this->getField()->getDatatype();
123  $storage_location = ($this->getField()->getStorageLocationOverride() !== null) ? $this->getField()->getStorageLocationOverride() : $datatype->getStorageLocation();
124 
125  if ($storage_location != 0) {
126  $query = "DELETE FROM il_dcl_stloc" . $storage_location . "_value WHERE record_field_id = "
127  . $this->db->quote($this->id, "integer");
128  $this->db->manipulate($query);
129 
130  $next_id = $this->db->nextId("il_dcl_stloc" . $storage_location . "_value");
131 
132  // This is a workaround to ensure that date values in stloc3 are never stored as NULL, which is not allowed
133  if ($storage_location == 3 && (is_null($this->value) || empty($this->value))) {
134  $this->value = '0000-00-00 00:00:00';
135  }
136 
137  $value = $this->serializeData($this->value);
138 
139  if ($this->getId() == 0) {
140  $this->doCreate();
141  }
142 
143  $insert_params = array(
144  "value" => array($datatype->getDbType(), $value),
145  "record_field_id" => array("integer", $this->getId()),
146  "id" => array("integer", $next_id),
147  );
148 
149  $this->db->insert("il_dcl_stloc" . $storage_location . "_value", $insert_params);
150  }
151  }
152 
153 
157  public function delete()
158  {
159  $datatype = $this->getField()->getDatatype();
160  $storage_location = ($this->getField()->getStorageLocationOverride() !== null) ? $this->getField()->getStorageLocationOverride() : $datatype->getStorageLocation();
161 
162  if ($storage_location != 0) {
163  $query = "DELETE FROM il_dcl_stloc" . $storage_location . "_value WHERE record_field_id = "
164  . $this->db->quote($this->id, "integer");
165  $this->db->manipulate($query);
166  }
167 
168  $query2 = "DELETE FROM il_dcl_record_field WHERE id = " . $this->db->quote($this->id, "integer");
169  $this->db->manipulate($query2);
170  }
171 
172 
176  public function getValue()
177  {
178  $this->loadValue();
179 
180  return $this->value;
181  }
182 
183 
187  public function getValueForRepresentation()
188  {
189  return $this->getValue();
190  }
191 
192 
200  public function serializeData($value)
201  {
202  if (is_array($value)) {
203  $value = json_encode($value);
204  }
205 
206  return $value;
207  }
208 
209 
217  public function deserializeData($value)
218  {
219  $deserialize = json_decode($value, true);
220  if (is_array($deserialize)) {
221  return $deserialize;
222  }
223 
224  return $value;
225  }
226 
227 
234  public function setValue($value, $omit_parsing = false)
235  {
236  $this->loadValue();
237  if (!$omit_parsing) {
238  $tmp = $this->parseValue($value, $this);
239  $old = $this->value;
240  //if parse value fails keep the old value
241  if ($tmp !== false) {
242  $this->value = $tmp;
243  }
244  } else {
245  $this->value = $value;
246  }
247  }
248 
249 
253  public function setValueFromForm($form)
254  {
255  $value = $form->getInput("field_" . $this->getField()->getId());
256 
257  $this->setValue($value);
258  }
259 
260 
264  public function getFormulaValue()
265  {
266  return $this->getExportValue();
267  }
268 
269 
277  public function parseExportValue($value)
278  {
279  return $value;
280  }
281 
282 
290  public function getValueFromExcel($excel, $row, $col)
291  {
292  $value = $excel->getCell($row, $col);
293 
294  return $value;
295  }
296 
297 
305  public function parseValue($value)
306  {
307  return $value;
308  }
309 
310 
314  public function getExportValue()
315  {
316  return $this->parseExportValue($this->getValue());
317  }
318 
319 
325  public function fillExcelExport(ilExcel $worksheet, &$row, &$col)
326  {
327  $worksheet->setCell($row, $col, $this->getExportValue());
328  $col++;
329  }
330 
331 
335  public function getPlainText()
336  {
337  return $this->getExportValue();
338  }
339 
340 
341  public function getSortingValue($link = true)
342  {
343  return $this->parseSortingValue($this->getValue(), $this, $link);
344  }
345 
346 
350  public function addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
351  {
352  ;
353  if (!is_array($this->getValue())) {
354  $confirmation->addHiddenItem('field_' . $this->field->getId(), $this->getValue());
355  } else {
356  foreach ($this->getValue() as $key => $value) {
357  $confirmation->addHiddenItem('field_' . $this->field->getId() . "[$key]", $value);
358  }
359  }
360  }
361 
362 
372  public function parseSortingValue($value, $link = true)
373  {
374  return $value;
375  }
376 
377 
381  protected function loadValue()
382  {
383  if ($this->value === null) {
384  $datatype = $this->getField()->getDatatype();
385 
386  $storage_location = ($this->getField()->getStorageLocationOverride() !== null) ? $this->getField()->getStorageLocationOverride() : $datatype->getStorageLocation();
387  if ($storage_location != 0) {
388  $query = "SELECT * FROM il_dcl_stloc" . $storage_location . "_value WHERE record_field_id = "
389  . $this->db->quote($this->id, "integer");
390 
391  $set = $this->db->query($query);
392  $rec = $this->db->fetchAssoc($set);
393  $value = $this->deserializeData($rec['value']);
394  $this->value = $value;
395  }
396  }
397  }
398 
399 
403  public function cloneStructure(ilDclBaseRecordFieldModel $old_record_field)
404  {
405  $this->setValue($old_record_field->getValue());
406  $this->doUpdate();
407  }
408 
409 
413  public function afterClone()
414  {
415  }
416 
417 
421  public function getField()
422  {
423  return $this->field;
424  }
425 
426 
430  public function getId()
431  {
432  return $this->id;
433  }
434 
435 
439  public function getRecord()
440  {
441  return $this->record;
442  }
443 
444 
448  public function getRecordRepresentation()
449  {
451  }
452 
453 
458  {
459  $this->record_representation = $record_representation;
460  }
461 
462 
466  public function getFieldRepresentation()
467  {
469  }
470 
471 
476  {
477  $this->field_representation = $field_representation;
478  }
479 }
parseValue($value)
Function to parse incoming data from form input value $value.
Class ilDclBaseFieldModel.
addHiddenItem($a_post_var, $a_value)
Add hidden item.
global $DIC
Definition: saml.php:7
parseSortingValue($value, $link=true)
Returns sortable value for the specific field-types.
setValue($value, $omit_parsing=false)
Set value for record field.
__construct(ilDclBaseRecordModel $record, ilDclBaseFieldModel $field)
doRead()
Read object data from database.
doCreate()
Creates an Id and a database entry.
cloneStructure(ilDclBaseRecordFieldModel $old_record_field)
user()
Definition: user.php:4
deserializeData($value)
Deserialize data before applying to field.
global $ilCtrl
Definition: ilias.php:18
parseExportValue($value)
Function to parse incoming data from form input value $value.
if(isset($_POST['submit'])) $form
doUpdate()
Update object in database.
fillExcelExport(ilExcel $worksheet, &$row, &$col)
addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
$ilUser
Definition: imgupload.php:18
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
$query
serializeData($value)
Serialize data before storing to db.
$row
Class ilDclBaseRecordModel.
setRecordRepresentation($record_representation)
global $ilDB
$key
Definition: croninfo.php:18
Confirmation screen class.