ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
5 
13 abstract 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  return;
156  }
157  if ($a_value !== null) {
158  $_SESSION["form_" . $this->table_gui->getId()][$this->getElementId()] = serialize($a_value);
159  } else {
160  unset($_SESSION["form_" . $this->table_gui->getId()][$this->getElementId()]);
161  }
162  }
163 
169  protected function readFilter()
170  {
171  if (!$this->table_gui instanceof ilTable2GUI) {
172  return;
173  }
174  $value = $_SESSION["form_" . $this->table_gui->getId()][$this->getElementId()];
175  if ($value) {
176  return unserialize($value);
177  }
178  }
179 
183  abstract public function loadFilter();
184 
185 
186  //
187  // form
188  //
189 
195  protected function addToParentElement(ilFormPropertyGUI $a_field)
196  {
197  if ($this->getForm() instanceof ilPropertyFormGUI) {
198  $this->getForm()->addItem($a_field);
199  } elseif ($this->getTableGUI() instanceof ilTable2GUI) {
200  $this->table_filter_fields[$a_field->getFieldId()] = $a_field;
201  $this->getTableGUI()->addFilterItem($a_field);
202 
203  // :TODO:
204  // $a_field->readFromSession();
205  // $this->getTableGUI()->filter[$this->getElementId()] = $a_field->getValue();
206  }
207  }
208 
215  protected function addToElementId($a_add)
216  {
217  return $this->getElementId() . "[" . $a_add . "]";
218  }
219 
223  abstract public function addToForm();
224 
225 
226  //
227  // post data
228  //
229 
236  protected function shouldBeImportedFromPost($a_post)
237  {
238  return true;
239  }
240 
247  protected function extractPostValues(array $a_post = null)
248  {
249  $element_id = $this->getElementId();
250  $multi = strpos($this->getElementId(), "[");
251 
252  if (!$a_post) {
253  $a_post = $_POST;
254  if ($multi !== false) {
255  $post = $a_post[substr($element_id, 0, $multi)][substr($element_id, $multi + 1, -1)];
256  } else {
257  $post = $a_post[$element_id];
258  }
259  } else {
260  if ($multi !== false) {
261  $post = $a_post[substr($element_id, $multi + 1, -1)];
262  } else {
263  $post = $a_post[$element_id];
264  }
265  }
266 
267  return $post;
268  }
269 
275  abstract public function importFromPost(array $a_post = null);
276 
282  abstract public function validate();
283 
284 
285  //
286  // DB
287  //
288 
295  abstract public function getSQLCondition($a_element_id);
296 
303  public function isInCondition(ilADT $a_adt)
304  {
305  return false;
306  }
307 
308 
309  //
310  // import/export
311  //
312 
318  abstract public function getSerializedValue();
319 
325  abstract public function setSerializedValue($a_value);
326 }
setElementId($a_value)
Set element id (aka form field)
setDefinition(ilADTDefinition $a_adt_def)
Set ADT definition.
$_SESSION["AccountId"]
This class represents a property form user interface.
setTitle($a_value)
Set title (aka form field caption)
setForm(ilPropertyFormGUI $a_form)
Set form.
importFromPost(array $a_post=null)
Import values from (search) form request POST data.
isValidADTDefinition(ilADTDefinition $a_adt_def)
Check if given ADT definition is valid.
isNull()
Is null ?
setSerializedValue($a_value)
Set current value(s) in serialized form (for easy persisting)
addToForm()
Add ADT-specific fields to form.
ADT base class.
Definition: class.ilADT.php:11
extractPostValues(array $a_post=null)
Extract data from (post) values.
__construct(ilADTDefinition $a_adt_def)
Constructor.
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
Class ilTable2GUI.
readFilter()
Load value(s) from filter store (in session)
loadFilter()
Load filter value(s) into ADT.
getFieldId()
Get Post Variable.
$post
Definition: post.php:34
validate()
Validate current data.
getTableGUI()
Get table gui.
ADT search bridge base class.
setTableGUI(ilTable2GUI $a_table)
Set table gui (for filter mode)
This class represents a property in a property form.
writeFilter($a_value=null)
Write value(s) to filter store (in session)
ADT definition base class.
getSQLCondition($a_element_id)
Get SQL condition for current value(s)
getElementId()
Get element id.
$_POST["username"]
isInCondition(ilADT $a_adt)
Compare directly against ADT.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
addToElementId($a_add)
Add sub-element.