ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 $lng;
43 protected $user;
47 protected $ctrl;
51 protected $db;
52
53
59 global $lng, $ilCtrl, $ilUser, $ilDB;
60 $this->record = $record;
61 $this->field = $field;
62 $this->lng = $lng;
63 $this->ctrl = $ilCtrl;
64 $this->user = $ilUser;
65 $this->db = $ilDB;
66 $this->doRead();
67 }
68
69
73 protected function doRead() {
74 $query = "SELECT * FROM il_dcl_record_field WHERE field_id = " . $this->db->quote($this->field->getId(), "integer") . " AND record_id = "
75 . $this->db->quote($this->record->getId(), "integer");
76 $set = $this->db->query($query);
77 $rec = $this->db->fetchAssoc($set);
78 $this->id = $rec['id'];
79
80 if ($this->id == NULL) {
81 $this->doCreate();
82 }
83 $this->loadValue();
84 }
85
86
90 protected function doCreate() {
91 $id = $this->db->nextId("il_dcl_record_field");
92 $query = "INSERT INTO il_dcl_record_field (id, record_id, field_id) VALUES (" . $this->db->quote($id, "integer") . ", "
93 . $this->db->quote($this->record->getId(), "integer") . ", " . $this->db->quote($this->field->getId(), "text") . ")";
94 $this->db->manipulate($query);
95 $this->id = $id;
96 }
97
98
102 public function doUpdate() {
103 //$this->loadValue(); //Removed Mantis #0011799
104 $datatype = $this->field->getDatatype();
105 $query = "DELETE FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
106 . $this->db->quote($this->id, "integer");
107 $this->db->manipulate($query);
108 $next_id = $this->db->nextId("il_dcl_stloc" . $datatype->getStorageLocation() . "_value");
109
110 // This is a workaround to ensure that date values in stloc3 are never stored as NULL, which is not allowed
111 if ($datatype->getStorageLocation() == 3 && (is_null($this->value) || empty($this->value))) {
112 $this->value = '0000-00-00 00:00:00';
113 }
114
115 $this->db->insert("il_dcl_stloc" . $datatype->getStorageLocation() . "_value", array(
116 "value" => array( $datatype->getDbType(), $this->value ),
117 "record_field_id " => array( "integer", $this->id ),
118 "id" => array( "integer", $next_id )
119 ));
120 }
121
122
126 public function delete() {
127 $datatype = $this->field->getDatatype();
128 $query = "DELETE FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
129 . $this->db->quote($this->id, "integer");
130 $this->db->manipulate($query);
131
132 $query2 = "DELETE FROM il_dcl_record_field WHERE id = " . $this->db->quote($this->id, "integer");
133 $this->db->manipulate($query2);
134 }
135
136
140 public function getValue() {
141 $this->loadValue();
142
143 return $this->value;
144 }
145
146
153 public function setValue($value, $omit_parsing = false) {
154 $this->loadValue();
155 if (! $omit_parsing) {
156 $tmp = $this->field->getDatatype()->parseValue($value, $this);
157 $old = $this->value;
158 //if parse value fails keep the old value
159 if ($tmp !== false) {
160 $this->value = $tmp;
161 //delete old file from filesystem
162 // TODO Does not belong here, create separate class ilDataCollectionFileField and overwrite setValue method
163 if ($old && $old != $this->value && $this->field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE) {
164 $this->record->deleteFile($old);
165 }
166 }
167 } else {
168 $this->value = $value;
169 }
170 }
171
172
176 public function getFormInput() {
177 $datatype = $this->field->getDatatype();
178
179 return $datatype->parseFormInput($this->getValue(), $this);
180 }
181
182
186 public function getExportValue() {
187 $datatype = $this->field->getDatatype();
188
189 return $datatype->parseExportValue($this->getValue());
190 }
191
192
196 public function getPlainText() {
197 return $this->getExportValue();
198 }
199
200
204 public function getHTML($link = true) {
205 $datatype = $this->field->getDatatype();
206
207 return $datatype->parseHTML($this->getValue(), $this, $link);
208 }
209
213 public function getSortingValue($link = true) {
214 $datatype = $this->field->getDatatype();
215
216 return $datatype->parseSortingValue($this->getValue(), $this, $link);
217 }
218
219
224 public function getSingleHTML() {
225 return $this->getHTML(false);
226 }
227
228
232 protected function loadValue() {
233 if ($this->value === NULL) {
234 $datatype = $this->field->getDatatype();
235 switch ($datatype->getId()) {
237 return true;
238 }
239 $query = "SELECT * FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
240 . $this->db->quote($this->id, "integer");
241
242 $set = $this->db->query($query);
243 $rec = $this->db->fetchAssoc($set);
244 $this->value = $rec['value'];
245 }
246 }
247
248
252 public function getField() {
253 return $this->field;
254 }
255
256
260 public function getId() {
261 return $this->id;
262 }
263
264
268 public function getRecord() {
269 return $this->record;
270 }
271}
272
273?>
Class ilDataCollectionField.
__construct(ilDataCollectionRecord $record, ilDataCollectionField $field)
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