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