ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilDataCollectionRecordField.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.ilDataCollectionInputException.php';
5
19
23 protected $id;
27 protected $field;
31 protected $record;
35 protected $value;
39 protected $user;
43 protected $ctrl;
47 protected $db;
48
52 protected $lng;
53
59 global $ilCtrl, $ilUser, $ilDB, $lng;
60 $this->record = $record;
61 $this->field = $field;
62 $this->ctrl = $ilCtrl;
63 $this->user = $ilUser;
64 $this->db = $ilDB;
65 $this->lng = $lng;
66 $this->doRead();
67 }
68
69
73 protected function doRead() {
74 if(!$this->record->getId())
75 return;
76
77 $query = "SELECT * FROM il_dcl_record_field WHERE field_id = " . $this->db->quote($this->field->getId(), "integer") . " AND record_id = "
78 . $this->db->quote($this->record->getId(), "integer");
79 $set = $this->db->query($query);
80 $rec = $this->db->fetchAssoc($set);
81 $this->id = $rec['id'];
82
83 if ($this->id == null) {
84 $this->doCreate();
85 }
86
87 $this->loadValue();
88 }
89
90
94 protected function doCreate() {
95 $id = $this->db->nextId("il_dcl_record_field");
96 $query = "INSERT INTO il_dcl_record_field (id, record_id, field_id) VALUES (" . $this->db->quote($id, "integer") . ", "
97 . $this->db->quote($this->record->getId(), "integer") . ", " . $this->db->quote($this->field->getId(), "text") . ")";
98 $this->db->manipulate($query);
99 $this->id = $id;
100 }
101
102
106 public function doUpdate() {
107 //$this->loadValue(); //Removed Mantis #0011799
108 if (!$this->id) {
109 $this->doCreate();
110 }
111 $datatype = $this->field->getDatatype();
112 $query = "DELETE FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
113 . $this->db->quote($this->id, "integer");
114 $this->db->manipulate($query);
115 $next_id = $this->db->nextId("il_dcl_stloc" . $datatype->getStorageLocation() . "_value");
116
117 // This is a workaround to ensure that date values in stloc3 are never stored as NULL, which is not allowed
118 if ($datatype->getStorageLocation() == 3 && (is_null($this->value) || empty($this->value))) {
119 $this->value = '0000-00-00 00:00:00';
120 }
121
122 $this->db->insert("il_dcl_stloc" . $datatype->getStorageLocation() . "_value", array(
123 "value" => array( $datatype->getDbType(), $this->value ),
124 "record_field_id " => array( "integer", $this->id ),
125 "id" => array( "integer", $next_id )
126 ));
127 }
128
129
133 public function delete() {
134 $datatype = $this->field->getDatatype();
135 $query = "DELETE FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
136 . $this->db->quote($this->id, "integer");
137 $this->db->manipulate($query);
138
139 $query2 = "DELETE FROM il_dcl_record_field WHERE id = " . $this->db->quote($this->id, "integer");
140 $this->db->manipulate($query2);
141 }
142
143
147 public function getValue() {
148 $this->loadValue();
149
150 return $this->value;
151 }
152
153
160 public function setValue($value, $omit_parsing = false) {
161 $this->loadValue();
162 if (! $omit_parsing) {
163 $tmp = $this->field->getDatatype()->parseValue($value, $this);
164 $old = $this->value;
165 //if parse value fails keep the old value
166 if ($tmp !== false) {
167 $this->value = $tmp;
168 //delete old file from filesystem
169 // TODO Does not belong here, create separate class ilDataCollectionFileField and overwrite setValue method
170 if ($old && $this->field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE) {
171// $this->record->deleteFile($old); // Removed due to #0018064
172 }
173 }
174 } else {
175 $this->value = $value;
176 }
177 }
178
182 public function setValueFromForm(&$form) {
183 if (in_array($this->field->getDatatypeId(), array(ilDataCollectionDatatype::INPUTFORMAT_MOB, ilDataCollectionDatatype::INPUTFORMAT_FILE))
184 && $form->getItemByPostVar("field_" . $this->field->getId())->getDeletionFlag()
185 ) {
186 $value = - 1;
187 } else {
188 $value = $form->getInput("field_" . $this->field->getId());
189 }
190 $this->setValue($value);
191 }
192
199 public function getValueFromExcel($excel, $row, $col) {
200 $value = $excel->val($row, $col);
201 if ($this->field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_DATETIME) {
202 $value = array(
203 'date' => date('Y-m-d', strtotime($value)),
204 'time' => '00:00:00',
205 );
206 }
207 return $value;
208 }
209
213 public function fillFormInput(&$form) {
214 $value = $this->getFormInput();
215 $form->getItemByPostVar('field_'.$this->field->getId())->setValueByArray(array("field_".$this->field->getId() => $value));
216 }
217
218
222 protected function getFormInput() {
223 $datatype = $this->field->getDatatype();
224
225 return $datatype->parseFormInput($this->getValue(), $this);
226 }
227
228
232 public function getExportValue() {
233 $datatype = $this->field->getDatatype();
234
235 return $datatype->parseExportValue($this->getValue());
236 }
237
243 public function fillExcelExport($worksheet, &$row, &$col) {
244 $worksheet->writeString($row, $col, $this->getExportValue());
245 $col ++;
246 }
247
248
252 public function getPlainText() {
253 return $this->getExportValue();
254 }
255
256
260 public function getHTML($link = true) {
261 $datatype = $this->field->getDatatype();
262
263 return $datatype->parseHTML($this->getValue(), $this, $link);
264 }
265
269 public function getSortingValue($link = true) {
270 $datatype = $this->field->getDatatype();
271
272 return $datatype->parseSortingValue($this->getValue(), $this, $link);
273 }
274
279 public function getSingleHTML() {
280 return $this->getHTML(false);
281 }
282
283
287 protected function loadValue() {
288 if ($this->value === NULL) {
289 $datatype = $this->field->getDatatype();
290 switch ($datatype->getId()) {
292 return true;
293 }
294 $query = "SELECT * FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
295 . $this->db->quote($this->id, "integer");
296
297 $set = $this->db->query($query);
298 $rec = $this->db->fetchAssoc($set);
299 $this->value = $rec['value'];
300 }
301 }
302
303
307 public function getField() {
308 return $this->field;
309 }
310
311
315 public function getId() {
316 return $this->id;
317 }
318
319
323 public function getRecord() {
324 return $this->record;
325 }
326}
327
328?>
Class ilDataCollectionField.
__construct(ilDataCollectionRecord $record, ilDataCollectionField $field)
doCreate()
Creates an Id and a database entry.
setValue($value, $omit_parsing=false)
Set value for record field.
doRead()
Read object data from database.
Class ilDataCollectionRecord.
global $ilCtrl
Definition: ilias.php:18
global $ilDB
global $ilUser
Definition: imgupload.php:15