ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTSearchBridge.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\HTTP\Services as HttpServices;
22
28abstract 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 {
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 public function addToFilterForm(): void
201 {
202 $this->addToForm();
203 }
204
210 protected function shouldBeImportedFromPost($a_post): bool
211 {
212 return true;
213 }
214
220 protected function extractPostValues(?array $a_post = null)
221 {
222 $element_id = $this->getElementId();
223 $multi = strpos($this->getElementId(), "[");
224
225 // get rid of this case
226 if ($a_post === null) {
227 $a_post = $this->http->request()->getParsedBody();
228 if ($multi !== false) {
229 $post = $a_post[substr($element_id, 0, $multi)][substr($element_id, $multi + 1, -1)] ?? null;
230 } else {
231 $post = $a_post[$element_id] ?? null;
232 }
233 } elseif ($multi !== false) {
234 $post = $a_post[substr($element_id, $multi + 1, -1)] ?? null;
235 } else {
236 $post = $a_post[$element_id] ?? null;
237 }
238 return $post;
239 }
240
244 abstract public function importFromPost(?array $a_post = null): bool;
245
250 abstract public function validate(): bool;
251
252
253 //
254 // DB
255 //
256
260 abstract public function getSQLCondition(
261 string $a_element_id,
262 int $mode = self::SQL_LIKE,
263 array $quotedWords = []
264 ): string;
265
273 public function isInCondition(ilADT $a_adt): bool
274 {
275 return false;
276 }
277
278
279 //
280 // import/export
281 //
282
286 abstract public function getSerializedValue(): string;
287
291 abstract public function setSerializedValue(string $a_value): void;
292}
Class Services.
Definition: Services.php:38
ADT definition base class.
ADT search bridge base class.
addToElementId(string $a_add)
Add sub-element.
loadFilter()
Load filter value(s) into ADT.
readFilter()
Load value(s) from filter store (in session)
isInCondition(ilADT $a_adt)
Compare directly against ADT.
validate()
Validate current data.
extractPostValues(?array $a_post=null)
Extract data from (post) values.
setForm(ilPropertyFormGUI $a_form)
importFromPost(?array $a_post=null)
setElementId(string $a_value)
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
setSerializedValue(string $a_value)
Set current value(s) in serialized form (for easy persisting)
addToFilterForm()
Add ADT-specific fields to filter.
isValidADTDefinition(ilADTDefinition $a_adt_def)
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
__construct(ilADTDefinition $a_adt_def)
setTableGUI(ilTable2GUI $a_table)
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
setDefinition(ilADTDefinition $a_adt_def)
writeFilter($a_value=null)
Write value(s) to filter store (in session)
addToForm()
Add ADT-specific fields to form.
getSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
Get SQL condition for current value(s)
ADT base class.
Definition: class.ilADT.php:26
This class represents a property in a property form.
language handling
This class represents a property form user interface.
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$post
Definition: ltitoken.php:46
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd, string $submit_caption="")
global $DIC
Definition: shib_login.php:26