ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
4 require_once './Modules/DataCollection/exceptions/class.ilDataCollectionInputException.php';
5 require_once './Modules/DataCollection/classes/class.ilDataCollectionILIASRefField.php';
6 require_once './Modules/DataCollection/classes/class.ilDataCollectionReferenceField.php';
7 require_once 'class.ilDataCollectionRatingField.php';
8 
21 {
22  protected $id;
23  protected $field;
24  protected $record;
25  protected $value;
26 
27  /*
28  * __construct
29  */
31  {
32  $this->record = $record;
33  $this->field = $field;
34  $this->doRead();
35  }
36 
37  /*
38  * doRead
39  */
40  private function doRead()
41  {
42  global $ilDB;
43 
44  $query = "SELECT * FROM il_dcl_record_field WHERE field_id LIKE ".$ilDB->quote($this->field->getId(), "text")." AND record_id = ".$ilDB->quote($this->record->getId(), "integer");
45  $set = $ilDB->query($query);
46  $rec = $ilDB->fetchAssoc($set);
47  $this->id = $rec['id'];
48 
49  if($this->id == NULL)
50  {
51  $this->doCreate();
52  }
53  $this->loadValue();
54  }
55 
56  /*
57  * doCreate
58  */
59  private function doCreate()
60  {
61  global $ilDB;
62 
63  $id = $ilDB->nextId("il_dcl_record_field");
64  $query = "INSERT INTO il_dcl_record_field (id, record_id, field_id) VALUES (".$ilDB->quote($id, "integer").", ".$ilDB->quote($this->record->getId(), "integer").", ".$ilDB->quote($this->field->getId(), "text").")";
65  $ilDB->manipulate($query);
66  $this->id = $id;
67  }
68 
69  /*
70  * doUpdate
71  */
72  public function doUpdate()
73  {
74  global $ilDB;
75 
76  //$this->loadValue(); //Removed Mantis ILIAS #0011799
77  $datatype = $this->field->getDatatype();
78  $query = "DELETE FROM il_dcl_stloc".$datatype->getStorageLocation()."_value WHERE record_field_id = ".$ilDB->quote($this->id, "integer");
79  $ilDB->manipulate($query);
80  $next_id = $ilDB->nextId("il_dcl_stloc".$datatype->getStorageLocation()."_value");
81 
82  $ilDB->insert("il_dcl_stloc".$datatype->getStorageLocation()."_value",
83  array("value" => array($datatype->getDbType(), $this->value),
84  "record_field_id " => array("integer", $this->id),
85  "id" => array("integer", $next_id))
86  );
87  }
88 
89  /*
90  * delete
91  */
92  public function delete()
93  {
94  global $ilDB;
95 
96  $datatype = $this->field->getDatatype();
97  $query = "DELETE FROM il_dcl_stloc".$datatype->getStorageLocation()."_value WHERE record_field_id = ".$ilDB->quote($this->id, "integer");
98  $ilDB->manipulate($query);
99 
100  $query2 = "DELETE FROM il_dcl_record_field WHERE id = ".$ilDB->quote($this->id, "integer");
101  $ilDB->manipulate($query2);
102  }
103 
104  /*
105  * getValue
106  */
107  public function getValue()
108  {
109  $this->loadValue();
110  return $this->value;
111  }
112 
113 
114  /*
115  * setValue
116  */
117  public function setValue($value)
118  {
119  $type = $this->field->getDatatype()->getId();
120  $this->loadValue();
121  $tmp = $this->field->getDatatype()->parseValue($value, $this);
122  $old = $this->value;
123  //if parse value fails keep the old value
124 // if($tmp !== null) //$tmp can be null to store NULL values in DB
125  if ($tmp !== false)
126  {
127  $this->value = $tmp;
128  //delete old file from filesystem
129  if($old && $this->field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE)
130  {
131  $this->record->deleteFile($old);
132  }
133  }
134  }
135 
136  /*
137  * getFormInput
138  */
139  public function getFormInput()
140  {
141  $datatype = $this->field->getDatatype();
142 
143  return $datatype->parseFormInput($this->getValue(), $this);
144  }
145 
146  /*
147  * getExportValue
148  */
149  public function getExportValue()
150  {
151  $datatype = $this->field->getDatatype();
152 
153  return $datatype->parseExportValue($this->getValue());
154  }
155 
159  public function getPlainText(){
160  return $this->getExportValue();
161  }
162 
163  /*
164  * getHTML
165  */
166  public function getHTML()
167  {
168  $datatype = $this->field->getDatatype();
169  return $datatype->parseHTML($this->getValue(), $this);
170  }
171 
176  public function getSingleHTML($link = null){
177  return $this->getHTML($link);
178  }
179 
180  /*
181  * loadValue
182  */
183  protected function loadValue()
184  {
185  if($this->value === NULL)
186  {
187  global $ilDB;
188  $datatype = $this->field->getDatatype();
189  $query = "SELECT * FROM il_dcl_stloc".$datatype->getStorageLocation()."_value WHERE record_field_id = ".$ilDB->quote($this->id, "integer");
190  $set = $ilDB->query($query);
191  $rec = $ilDB->fetchAssoc($set);
192  $this->value = $rec['value'];
193  }
194  }
195 
196  /*
197  * getField
198  */
199  public function getField()
200  {
201  return $this->field;
202  }
203 
204  /*
205  * getId
206  */
207  public function getId()
208  {
209  return $this->id;
210  }
211 
212  /*
213  * getRecord
214  */
215  public function getRecord()
216  {
217  return $this->record;
218  }
219 }
220 ?>