ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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  public const DEFAULT_SEARCH_COLUMN = 'value';
16 
17  protected $form; // [ilPropertyFormGUI]
18  protected $table_gui; // [ilTable2GUI]
19  protected $table_filter_fields = []; // [array]
20  protected $id; // [string]
21  protected $title; // [string]
22  protected $info; // [string]
23 
30  public function __construct(ilADTDefinition $a_adt_def)
31  {
32  $this->setDefinition($a_adt_def);
33  }
34 
35 
36  //
37  // properties
38  //
39 
48  abstract protected function isValidADTDefinition(ilADTDefinition $a_adt_def);
49 
55  abstract protected function setDefinition(ilADTDefinition $a_adt_def);
56 
62  abstract public function isNull();
63 
69  public function setForm(ilPropertyFormGUI $a_form)
70  {
71  $this->form = $a_form;
72  }
73 
79  public function getForm()
80  {
81  return $this->form;
82  }
83 
89  public function setElementId($a_value)
90  {
91  $this->id = (string) $a_value;
92  }
93 
99  public function getElementId()
100  {
101  return $this->id;
102  }
103 
109  public function setTitle($a_value)
110  {
111  $this->title = trim($a_value);
112  }
113 
119  public function getTitle()
120  {
121  return $this->title;
122  }
123 
124 
125  public function getSearchColumn() : string
126  {
127  return self::DEFAULT_SEARCH_COLUMN;
128  }
129 
130 
131  //
132  // table2gui / filter
133  //
134 
140  public function setTableGUI(ilTable2GUI $a_table)
141  {
142  $this->table_gui = $a_table;
143  }
144 
150  public function getTableGUI()
151  {
152  return $this->table_gui;
153  }
154 
160  protected function writeFilter($a_value = null)
161  {
162  if (!$this->table_gui instanceof ilTable2GUI) {
163  return;
164  }
165  if ($a_value !== null) {
166  $_SESSION["form_" . $this->table_gui->getId()][$this->getElementId()] = serialize($a_value);
167  } else {
168  unset($_SESSION["form_" . $this->table_gui->getId()][$this->getElementId()]);
169  }
170  }
171 
177  protected function readFilter()
178  {
179  if (!$this->table_gui instanceof ilTable2GUI) {
180  return;
181  }
182  $value = $_SESSION["form_" . $this->table_gui->getId()][$this->getElementId()];
183  if ($value) {
184  return unserialize($value);
185  }
186  }
187 
191  abstract public function loadFilter();
192 
193 
194  //
195  // form
196  //
197 
203  protected function addToParentElement(ilFormPropertyGUI $a_field)
204  {
205  if ($this->getForm() instanceof ilPropertyFormGUI) {
206  $this->getForm()->addItem($a_field);
207  } elseif ($this->getTableGUI() instanceof ilTable2GUI) {
208  $this->table_filter_fields[$a_field->getFieldId()] = $a_field;
209  $this->getTableGUI()->addFilterItem($a_field);
210 
211  // :TODO:
212  // $a_field->readFromSession();
213  // $this->getTableGUI()->filter[$this->getElementId()] = $a_field->getValue();
214  }
215  }
216 
223  protected function addToElementId($a_add)
224  {
225  return $this->getElementId() . "[" . $a_add . "]";
226  }
227 
231  abstract public function addToForm();
232 
233 
234  //
235  // post data
236  //
237 
244  protected function shouldBeImportedFromPost($a_post)
245  {
246  return true;
247  }
248 
255  protected function extractPostValues(array $a_post = null)
256  {
257  $element_id = $this->getElementId();
258  $multi = strpos($this->getElementId(), "[");
259 
260  // get rid of this case
261  if ($a_post === null) {
262  $a_post = $_POST;
263  if ($multi !== false) {
264  $post = $a_post[substr($element_id, 0, $multi)][substr($element_id, $multi + 1, -1)];
265  } else {
266  $post = $a_post[$element_id];
267  }
268  } elseif ($multi !== false) {
269  $post = $a_post[substr($element_id, $multi + 1, -1)];
270  } else {
271  $post = $a_post[$element_id];
272  }
273 
274  return $post;
275  }
276 
282  abstract public function importFromPost(array $a_post = null);
283 
289  abstract public function validate();
290 
291 
292  //
293  // DB
294  //
295 
302  abstract public function getSQLCondition($a_element_id);
303 
310  public function isInCondition(ilADT $a_adt)
311  {
312  return false;
313  }
314 
315 
316  //
317  // import/export
318  //
319 
325  abstract public function getSerializedValue();
326 
332  abstract public function setSerializedValue($a_value);
333 }
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.
readFilter()
Load value(s) from filter store (in session)
loadFilter()
Load filter value(s) into ADT.
getFieldId()
Get Post Variable.
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.