ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilADTSearchBridge.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
28 abstract class ilADTSearchBridge
29 {
30  public const SQL_STRICT = 1;
31  public const SQL_LIKE = 2;
32  public const SQL_LIKE_END = 3;
33  public const SQL_LIKE_START = 4;
34  public const DEFAULT_SEARCH_COLUMN = 'value';
35 
36  protected ?ilPropertyFormGUI $form = null;
37  protected ?ilTable2GUI $table_gui = null;
38  protected array $table_filter_fields = [];
39  protected string $id = '';
40  protected string $title = '';
41  protected string $info = '';
42 
43  protected ilLanguage $lng;
44  protected ilDBInterface $db;
45  protected HttpServices $http;
46 
47  public function __construct(ilADTDefinition $a_adt_def)
48  {
49  global $DIC;
50  $this->setDefinition($a_adt_def);
51 
52  $this->lng = $DIC->language();
53  $this->db = $DIC->database();
54  $this->http = $DIC->http();
55  }
56 
57  abstract protected function isValidADTDefinition(ilADTDefinition $a_adt_def): bool;
58 
59  abstract protected function setDefinition(ilADTDefinition $a_adt_def): void;
60 
61  abstract public function isNull(): bool;
62 
63  public function setForm(ilPropertyFormGUI $a_form): void
64  {
65  $this->form = $a_form;
66  }
67 
68  public function getForm(): ?ilPropertyFormGUI
69  {
70  return $this->form;
71  }
72 
73  public function setElementId(string $a_value): void
74  {
75  $this->id = $a_value;
76  }
77 
78  public function getElementId(): string
79  {
80  return $this->id;
81  }
82 
83  public function setTitle(string $a_value): void
84  {
85  $this->title = trim($a_value);
86  }
87 
88  public function getTitle(): string
89  {
90  return $this->title;
91  }
92 
93  public function getSearchColumn(): string
94  {
95  return self::DEFAULT_SEARCH_COLUMN;
96  }
97 
98  public function setTableGUI(ilTable2GUI $a_table): void
99  {
100  $this->table_gui = $a_table;
101  }
102 
106  public function getTableGUI(): ?ilTable2GUI
107  {
108  return $this->table_gui;
109  }
110 
115  protected function writeFilter($a_value = null): void
116  {
117  if (!$this->table_gui instanceof ilTable2GUI) {
118  return;
119  }
120  /*
121  * BT 35593: changes in ilFormPropertyGUI::clearFromSession make it necessary
122  * to have a flat array for all the filter inputs in the session.
123  */
124  if ($a_value !== null) {
126  "form_" . $this->table_gui->getId() . "_" . $this->getElementId(),
127  serialize($a_value)
128  );
129  } else {
131  "form_" . $this->table_gui->getId() . "_" . $this->getElementId()
132  );
133  }
134  }
135 
140  protected function readFilter()
141  {
142  if (!$this->table_gui instanceof ilTable2GUI) {
143  return null;
144  }
145  /*
146  * BT 35593: changes in ilFormPropertyGUI::clearFromSession make it necessary
147  * to have a flat array of all the filter inputs in the session.
148  */
149  $value = ilSession::get(
150  "form_" . $this->table_gui->getId() . "_" . $this->getElementId()
151  ) ?? '';
152  if ($value) {
153  return unserialize($value);
154  }
155  return '';
156  }
157 
161  abstract public function loadFilter(): void;
162 
167  protected function addToParentElement(ilFormPropertyGUI $a_field): void
168  {
169  if ($this->getForm() instanceof ilPropertyFormGUI) {
170  $this->getForm()->addItem($a_field);
171  } elseif (
172  $this->getTableGUI() instanceof ilTable2GUI &&
173  $a_field instanceof ilTableFilterItem
174  ) {
175  $this->table_filter_fields[$a_field->getFieldId()] = $a_field;
176  $this->getTableGUI()->addFilterItem($a_field);
177  }
178  }
179 
185  protected function addToElementId(string $a_add): string
186  {
187  return $this->getElementId() . "[" . $a_add . "]";
188  }
189 
193  abstract public function addToForm(): void;
194 
200  protected function shouldBeImportedFromPost($a_post): bool
201  {
202  return true;
203  }
204 
210  protected function extractPostValues(array $a_post = null)
211  {
212  $element_id = $this->getElementId();
213  $multi = strpos($this->getElementId(), "[");
214 
215  // get rid of this case
216  if ($a_post === null) {
217  $a_post = $this->http->request()->getParsedBody();
218  if ($multi !== false) {
219  $post = $a_post[substr($element_id, 0, $multi)][substr($element_id, $multi + 1, -1)] ?? null;
220  } else {
221  $post = $a_post[$element_id] ?? null;
222  }
223  } elseif ($multi !== false) {
224  $post = $a_post[substr($element_id, $multi + 1, -1)] ?? null;
225  } else {
226  $post = $a_post[$element_id] ?? null;
227  }
228  return $post;
229  }
230 
234  abstract public function importFromPost(array $a_post = null): bool;
235 
240  abstract public function validate(): bool;
241 
242 
243  //
244  // DB
245  //
246 
250  abstract public function getSQLCondition(
251  string $a_element_id,
252  int $mode = self::SQL_LIKE,
253  array $quotedWords = []
254  ): string;
255 
259  public function isInCondition(ilADT $a_adt): bool
260  {
261  return false;
262  }
263 
264 
265  //
266  // import/export
267  //
268 
272  abstract public function getSerializedValue(): string;
273 
277  abstract public function setSerializedValue(string $a_value): void;
278 }
static get(string $a_var)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setDefinition(ilADTDefinition $a_adt_def)
setForm(ilPropertyFormGUI $a_form)
importFromPost(array $a_post=null)
isValidADTDefinition(ilADTDefinition $a_adt_def)
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
static http()
Fetches the global http state from ILIAS.
readFilter()
Load value(s) from filter store (in session)
getSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
Get SQL condition for current value(s)
loadFilter()
Load filter value(s) into ADT.
validate()
Validate current data.
setElementId(string $a_value)
form( $class_path, string $cmd)
getTableGUI()
Get table gui.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTableGUI(ilTable2GUI $a_table)
This class represents a property in a property form.
writeFilter($a_value=null)
Write value(s) to filter store (in session)
addToElementId(string $a_add)
Add sub-element.
$post
Definition: ltitoken.php:49
ADT definition base class.
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
setSerializedValue(string $a_value)
Set current value(s) in serialized form (for easy persisting)
isInCondition(ilADT $a_adt)
Compare directly against ADT.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.