ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilADTSearchBridge.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
5
13abstract class ilADTSearchBridge
14{
15 protected $form; // [ilPropertyFormGUI]
16 protected $table_gui; // [ilTable2GUI]
17 protected $table_filter_fields; // [array]
18 protected $id; // [string]
19 protected $title; // [string]
20 protected $info; // [string]
21
28 public function __construct(ilADTDefinition $a_adt_def)
29 {
30 $this->setDefinition($a_adt_def);
31 }
32
33
34 //
35 // properties
36 //
37
46 abstract protected function isValidADTDefinition(ilADTDefinition $a_adt_def);
47
53 abstract protected function setDefinition(ilADTDefinition $a_adt_def);
54
60 abstract public function isNull();
61
67 public function setForm(ilPropertyFormGUI $a_form)
68 {
69 $this->form = $a_form;
70 }
71
77 public function getForm()
78 {
79 return $this->form;
80 }
81
87 public function setElementId($a_value)
88 {
89 $this->id = (string)$a_value;
90 }
91
97 public function getElementId()
98 {
99 return $this->id;
100 }
101
107 public function setTitle($a_value)
108 {
109 $this->title = trim($a_value);
110 }
111
117 public function getTitle()
118 {
119 return $this->title;
120 }
121
122
123 //
124 // table2gui / filter
125 //
126
132 public function setTableGUI(ilTable2GUI $a_table)
133 {
134 $this->table_gui = $a_table;
135 }
136
142 public function getTableGUI()
143 {
144 return $this->table_gui;
145 }
146
152 protected function writeFilter($a_value = null)
153 {
154 if(!$this->table_gui instanceof ilTable2GUI)
155 {
156 return;
157 }
158 if($a_value !== null)
159 {
160 $_SESSION["form_".$this->table_gui->getId()][$this->getElementId()] = serialize($a_value);
161 }
162 else
163 {
164 unset($_SESSION["form_".$this->table_gui->getId()][$this->getElementId()]);
165 }
166 }
167
173 protected function readFilter()
174 {
175 if(!$this->table_gui instanceof ilTable2GUI)
176 {
177 return;
178 }
179 $value = $_SESSION["form_".$this->table_gui->getId()][$this->getElementId()];
180 if($value)
181 {
182 return unserialize($value);
183 }
184 }
185
189 abstract public function loadFilter();
190
191
192 //
193 // form
194 //
195
201 protected function addToParentElement(ilFormPropertyGUI $a_field)
202 {
203 if($this->getForm() instanceof ilPropertyFormGUI)
204 {
205 $this->getForm()->addItem($a_field);
206 }
207 else if($this->getTableGUI() instanceof ilTable2GUI)
208 {
209 $this->table_filter_fields[$a_field->getFieldId()] = $a_field;
210 $this->getTableGUI()->addFilterItem($a_field);
211
212 // :TODO:
213 // $a_field->readFromSession();
214 // $this->getTableGUI()->filter[$this->getElementId()] = $a_field->getValue();
215 }
216 }
217
224 protected function addToElementId($a_add)
225 {
226 return $this->getElementId()."[".$a_add."]";
227 }
228
232 abstract public function addToForm();
233
234
235 //
236 // post data
237 //
238
245 protected function shouldBeImportedFromPost($a_post)
246 {
247 return true;
248 }
249
256 protected function extractPostValues(array $a_post = null)
257 {
258 $element_id = $this->getElementId();
259 $multi = strpos($this->getElementId(), "[");
260
261 if(!$a_post)
262 {
263 $a_post = $_POST;
264 if($multi !== false)
265 {
266 $post = $a_post[substr($element_id, 0, $multi)][substr($element_id, $multi+1, -1)];
267 }
268 else
269 {
270 $post = $a_post[$element_id];
271 }
272 }
273 else
274 {
275 if($multi !== false)
276 {
277 $post = $a_post[substr($element_id, $multi+1, -1)];
278 }
279 else
280 {
281 $post = $a_post[$element_id];
282 }
283 }
284
285 return $post;
286 }
287
293 abstract public function importFromPost(array $a_post = null);
294
300 abstract public function validate();
301
302
303 //
304 // DB
305 //
306
313 abstract public function getSQLCondition($a_element_id);
314
321 public function isInCondition(ilADT $a_adt)
322 {
323 return false;
324 }
325
326
327 //
328 // import/export
329 //
330
336 abstract public function getSerializedValue();
337
343 abstract public function setSerializedValue($a_value);
344}
345
346?>
$_SESSION["AccountId"]
ADT definition base class.
ADT search bridge base class.
setTitle($a_value)
Set title (aka form field caption)
loadFilter()
Load filter value(s) into ADT.
setSerializedValue($a_value)
Set current value(s) in serialized form (for easy persisting)
readFilter()
Load value(s) from filter store (in session)
isInCondition(ilADT $a_adt)
Compare directly against ADT.
validate()
Validate current data.
importFromPost(array $a_post=null)
Import values from (search) form request POST data.
extractPostValues(array $a_post=null)
Extract data from (post) values.
addToElementId($a_add)
Add sub-element.
setForm(ilPropertyFormGUI $a_form)
Set form.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
getSQLCondition($a_element_id)
Get SQL condition for current value(s)
getElementId()
Get element id.
isValidADTDefinition(ilADTDefinition $a_adt_def)
Check if given ADT definition is valid.
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
__construct(ilADTDefinition $a_adt_def)
Constructor.
setTableGUI(ilTable2GUI $a_table)
Set table gui (for filter mode)
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
setDefinition(ilADTDefinition $a_adt_def)
Set ADT definition.
writeFilter($a_value=null)
Write value(s) to filter store (in session)
setElementId($a_value)
Set element id (aka form field)
addToForm()
Add ADT-specific fields to form.
isNull()
Is null ?
ADT base class.
Definition: class.ilADT.php:12
This class represents a property in a property form.
getFieldId()
Get Post Variable.
This class represents a property form user interface.
Class ilTable2GUI.
$_POST['username']
Definition: cron.php:12