ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTEnumSearchBridgeSingle.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public const ENUM_SEARCH_COLUMN = 'value_index';
24
25 protected function isValidADTDefinition(ilADTDefinition $a_adt_def): bool
26 {
27 return ($a_adt_def instanceof ilADTEnumDefinition);
28 }
29
30 // table2gui / filter
31
32 public function loadFilter(): void
33 {
34 $value = $this->readFilter();
35 if ($value !== null) {
36 $this->getADT()->setSelection($value);
37 }
38 }
39
40 public function getSearchColumn(): string
41 {
43 }
44
45 // form
46
47 public function addToForm(): void
48 {
49 $def = $this->getADT()->getCopyOfDefinition();
50
51 $options = $def->getOptions();
52
53 $this->lng->loadLanguageModule("search");
54 $options = array("" => $this->lng->txt("search_any")) + $options;
55
56 $select = new ilSelectInputGUI($this->getTitle(), $this->getElementId());
57 $select->setOptions($options);
58
59 $select->setValue($this->getADT()->getSelection());
60
61 $this->addToParentElement($select);
62 }
63
64 public function importFromPost(?array $a_post = null): bool
65 {
66 $post = $this->extractPostValues($a_post);
67 if (
68 is_numeric($post) &&
70 ) {
71 if ($this->getForm() instanceof ilPropertyFormGUI) {
72 $item = $this->getForm()->getItemByPostVar($this->getElementId());
73 $item->setValue($post);
74 } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
75 $this->table_filter_fields[$this->getElementId()]->setValue($post);
76 $this->writeFilter($post);
77 }
78
79 $this->getADT()->setSelection($post);
80 } else {
81 $this->writeFilter();
82 $this->getADT()->setSelection();
83 }
84 return true;
85 }
86
87 // db
88
89 public function getSQLCondition(string $a_element_id, int $mode = self::SQL_LIKE, array $quotedWords = []): string
90 {
91 $search_column = $this->getSearchColumn();
92 if (!$this->isNull() && $this->isValid()) {
93 return $search_column . ' = ' . $this->db->quote($this->getADT()->getSelection(), ilDBConstants::T_TEXT);
94 }
95 return '';
96 }
97
98 public function isInCondition(ilADT $a_adt): bool
99 {
100 assert($a_adt instanceof ilADTEnum);
101
102 return $this->getADT()->equals($a_adt);
103 }
104
105 // import/export
106
107 public function getSerializedValue(): string
108 {
109 if (!$this->isNull() && $this->isValid()) {
110 return serialize(array($this->getADT()->getSelection()));
111 }
112 return '';
113 }
114
115 public function setSerializedValue(string $a_value): void
116 {
117 $a_value = unserialize($a_value);
118 if (is_array($a_value) && !empty($a_value)) {
119 $this->getADT()->setSelection($a_value[0]);
120 }
121 }
122}
ADT definition base class.
isInCondition(ilADT $a_adt)
Compare directly against ADT.
setSerializedValue(string $a_value)
Set current value(s) in serialized form (for easy persisting)
addToForm()
Add ADT-specific fields to form.
isValidADTDefinition(ilADTDefinition $a_adt_def)
getSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
Get SQL condition for current value(s)
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
loadFilter()
Load filter value(s) into ADT.
Class ilADTSearchBridgeSingle.
readFilter()
Load value(s) from filter store (in session)
extractPostValues(?array $a_post=null)
Extract data from (post) values.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
writeFilter($a_value=null)
Write value(s) to filter store (in session)
ADT base class.
Definition: class.ilADT.php:26
This class represents a property form user interface.
This class represents a selection list property in a property form.
$post
Definition: ltitoken.php:46