ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
23  protected $id;
27  protected $field;
31  protected $record;
32 
37 
45  protected $value;
49  protected $user;
53  protected $ctrl;
57  protected $db;
58 
62  protected $lng;
63 
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  if(!$this->getRecord()->getId())
89  return;
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  $id = $this->db->nextId("il_dcl_record_field");
106  $query = "INSERT INTO il_dcl_record_field (id, record_id, field_id) VALUES (" . $this->db->quote($id, "integer") . ", "
107  . $this->db->quote($this->getRecord()->getId(), "integer") . ", " . $this->db->quote($this->getField()->getId(), "text") . ")";
108  $this->db->manipulate($query);
109  $this->id = $id;
110  }
111 
112 
116  public function doUpdate() {
117  //$this->loadValue(); //Removed Mantis #0011799
118  $datatype = $this->getField()->getDatatype();
119  $storage_location = ($this->getField()->getStorageLocationOverride() !== null)? $this->getField()->getStorageLocationOverride() : $datatype->getStorageLocation();
120 
121  if($storage_location != 0) {
122  $query = "DELETE FROM il_dcl_stloc" . $storage_location . "_value WHERE record_field_id = "
123  . $this->db->quote($this->id, "integer");
124  $this->db->manipulate($query);
125 
126  $next_id = $this->db->nextId("il_dcl_stloc" . $storage_location . "_value");
127 
128  // This is a workaround to ensure that date values in stloc3 are never stored as NULL, which is not allowed
129  if ($storage_location == 3 && (is_null($this->value) || empty($this->value))) {
130  $this->value = '0000-00-00 00:00:00';
131  }
132 
133  $value = $this->serializeData($this->value);
134 
135  if($this->getId() == 0) {
136  $this->doCreate();
137  }
138 
139  $insert_params = array(
140  "value" => array( $datatype->getDbType(), $value),
141  "record_field_id" => array( "integer", $this->getId()),
142  "id" => array( "integer", $next_id )
143  );
144 
145  $this->db->insert("il_dcl_stloc" . $storage_location . "_value", $insert_params);
146  }
147  }
148 
149 
153  public function delete() {
154  $datatype = $this->getField()->getDatatype();
155  $storage_location = ($this->getField()->getStorageLocationOverride() !== null)? $this->getField()->getStorageLocationOverride() : $datatype->getStorageLocation();
156 
157  if($storage_location != 0) {
158  $query = "DELETE FROM il_dcl_stloc" . $storage_location . "_value WHERE record_field_id = "
159  . $this->db->quote($this->id, "integer");
160  $this->db->manipulate($query);
161  }
162 
163  $query2 = "DELETE FROM il_dcl_record_field WHERE id = " . $this->db->quote($this->id, "integer");
164  $this->db->manipulate($query2);
165  }
166 
167 
171  public function getValue() {
172  $this->loadValue();
173 
174  return $this->value;
175  }
176 
177 
181  public function getValueForRepresentation() {
182  return $this->getValue();
183  }
184 
191  public function serializeData($value) {
192  if(is_array($value)) {
193  $value = json_encode($value);
194  }
195  return $value;
196  }
197 
198 
205  public function deserializeData($value) {
206  $deserialize = json_decode($value, true);
207  if(is_array($deserialize)) {
208  return $deserialize;
209  }
210  return $value;
211  }
212 
219  public function setValue($value, $omit_parsing = false) {
220  $this->loadValue();
221  if (! $omit_parsing) {
222  $tmp = $this->parseValue($value, $this);
223  $old = $this->value;
224  //if parse value fails keep the old value
225  if ($tmp !== false) {
226  $this->value = $tmp;
227  }
228  } else {
229  $this->value = $value;
230  }
231  }
232 
236  public function setValueFromForm($form) {
237  $value = $form->getInput("field_" . $this->getField()->getId());
238 
239  $this->setValue($value);
240  }
241 
249  public function parseExportValue($value) {
250  return $value;
251  }
252 
259  public function getValueFromExcel($excel, $row, $col) {
260  $value = $excel->getCell($row, $col);
261 
262  return $value;
263  }
264 
272  public function parseValue($value) {
273  return $value;
274  }
275 
276 
280  public function getExportValue() {
281  return $this->parseExportValue($this->getValue());
282  }
283 
289  public function fillExcelExport(ilExcel $worksheet, &$row, &$col) {
290  $worksheet->setCell($row, $col, $this->getExportValue());
291  $col ++;
292  }
293 
297  public function getPlainText() {
298  return $this->getExportValue();
299  }
300 
301  public function getSortingValue($link = true) {
302  return $this->parseSortingValue($this->getValue(), $this, $link);
303  }
304 
305 
309  public function addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation) {;
310  if (!is_array($this->getValue())) {
311  $confirmation->addHiddenItem('field_'.$this->field->getId(), $this->getValue());
312  } else {
313  foreach ($this->getValue() as $key => $value) {
314  $confirmation->addHiddenItem('field_'.$this->field->getId() . "[$key]", $value);
315  }
316  }
317  }
318 
328  public function parseSortingValue($value, $link = true) {
329  return $value;
330  }
331 
335  protected function loadValue() {
336  if ($this->value === NULL) {
337  $datatype = $this->getField()->getDatatype();
338 
339  $storage_location = ($this->getField()->getStorageLocationOverride() !== null)? $this->getField()->getStorageLocationOverride() : $datatype->getStorageLocation();
340  if($storage_location != 0) {
341  $query = "SELECT * FROM il_dcl_stloc" . $storage_location . "_value WHERE record_field_id = "
342  . $this->db->quote($this->id, "integer");
343 
344  $set = $this->db->query($query);
345  $rec = $this->db->fetchAssoc($set);
346  $value = $this->deserializeData($rec['value']);
347  $this->value = $value;
348  }
349  }
350  }
351 
352 
356  public function cloneStructure(ilDclBaseRecordFieldModel $old_record_field) {
357  $this->setValue($old_record_field->getValue());
358  $this->doUpdate();
359  }
360 
361 
365  public function afterClone(){
366 
367  }
368 
369 
373  public function getField() {
374  return $this->field;
375  }
376 
377 
381  public function getId() {
382  return $this->id;
383  }
384 
385 
389  public function getRecord() {
390  return $this->record;
391  }
392 
396  public function getRecordRepresentation() {
398  }
399 
400 
405  $this->record_representation = $record_representation;
406  }
407 
408 
412  public function getFieldRepresentation() {
414  }
415 
416 
421  $this->field_representation = $field_representation;
422  }
423 
424 }
425 
parseValue($value)
Function to parse incoming data from form input value $value.
Class ilDclBaseFieldModel.
$worksheet
addHiddenItem($a_post_var, $a_value)
Add hidden item.
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.
doUpdate()
Update object in database.
fillExcelExport(ilExcel $worksheet, &$row, &$col)
addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
$ilUser
Definition: imgupload.php:18
serializeData($value)
Serialize data before storing to db.
$old
Create styles array
The data for the language used.
setCell($a_row, $a_col, $a_value)
Set cell value.
Class ilDclBaseRecordModel.
setRecordRepresentation($record_representation)
global $ilDB
global $DIC
Confirmation screen class.