ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTEnumSearchBridgeMulti.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public const ENUM_SEARCH_COLUMN = 'value_index';
27 public const SEARCH_MODE_ALL = 1;
28 public const SEARCH_MODE_ANY = 2;
29
30 protected bool $multi_source;
32
33 public function setSearchMode(int $a_mode): void
34 {
35 $this->search_mode = $a_mode;
36 }
37
38 public function getSearchColumn(): string
39 {
41 }
42
43 protected function isValidADTDefinition(ilADTDefinition $a_adt_def): bool
44 {
45 return ($a_adt_def instanceof ilADTEnumDefinition ||
46 $a_adt_def instanceof ilADTMultiEnumDefinition);
47 }
48
50 {
51 if ($a_adt_def->getType() == "Enum") {
52 $this->multi_source = false;
53 $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("MultiEnum");
54 $def->setNumeric($a_adt_def->isNumeric());
55 $def->setOptions($a_adt_def->getOptions());
56 return $def;
57 } else {
58 $this->multi_source = true;
59 return $a_adt_def;
60 }
61 }
62
63 public function loadFilter(): void
64 {
65 $value = $this->readFilter();
66 if ($value !== null) {
67 if (is_string($value)) {
68 $value = [$value];
69 }
70 $this->getADT()->setSelections($value);
71 }
72 }
73
74 // form
75
76 public function addToForm(): void
77 {
78 $def = $this->getADT()->getCopyOfDefinition();
79
80 $options = $def->getOptions();
81
82 $cbox = new ilCheckboxGroupInputGUI($this->getTitle(), $this->getElementId());
83 $cbox->setValue($this->getADT()->getSelections());
84
85 foreach ($options as $value => $caption) {
86 $option = new ilCheckboxOption($caption, (string) $value);
87 $cbox->addOption($option);
88 }
89
90 $this->addToParentElement($cbox);
91 }
92
93 public function importFromPost(?array $a_post = null): bool
94 {
95 $post = $this->extractPostValues($a_post);
96
97 if ($post && $this->shouldBeImportedFromPost($post)) {
98 if ($this->getForm() instanceof ilPropertyFormGUI) {
99 $item = $this->getForm()->getItemByPostVar($this->getElementId());
100 $item->setValue($post);
101 } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
102 $this->table_filter_fields[$this->getElementId()]->setValue($post);
103 $this->writeFilter($post);
104 }
105
106 if (is_array($post)) {
107 $this->getADT()->setSelections($post);
108 }
109 } else {
110 $this->getADT()->setSelections();
111 // BT 35593: multi enum filter should reset when nothing is selected
112 if (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
113 $this->writeFilter();
114 }
115 }
116 return true;
117 }
118
119 // db
120
121 public function getSQLCondition(string $a_element_id, int $mode = self::SQL_LIKE, array $quotedWords = []): string
122 {
123 if (!$this->isNull() && $this->isValid()) {
124 return $this->db->in(
125 $this->getSearchColumn(),
126 (array) $this->getADT()->getSelections(),
127 false,
129 );
130 }
131 return '';
132 }
133
134 public function isInCondition(ilADT $a_adt): bool
135 {
136 assert($a_adt instanceof ilADTMultiEnum);
137
138 $current = $this->getADT()->getSelections();
139 if (is_array($current) &&
140 count($current)) {
141 // #16827 / #17087
142 if ($this->search_mode == self::SEARCH_MODE_ANY) {
143 foreach ((array) $a_adt->getSelections() as $value) {
144 if (in_array($value, $current)) {
145 return true;
146 }
147 }
148 } else {
149 // #18028
150 return !count(array_diff($current, (array) $a_adt->getSelections()));
151 }
152 }
153 return false;
154 }
155
156 // import/export
157
158 public function getSerializedValue(): string
159 {
160 if (!$this->isNull() && $this->isValid()) {
161 return serialize($this->getADT()->getSelections());
162 }
163 return '';
164 }
165
166 public function setSerializedValue(string $a_value): void
167 {
168 $a_value = unserialize($a_value);
169 if (is_array($a_value)) {
170 $this->getADT()->setSelections($a_value);
171 }
172 }
173}
ADT definition base class.
getType()
Get type (from class/instance)
Class ilADTEnumSearchBridgeMulti.
isInCondition(ilADT $a_adt)
Compare directly against ADT.
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
addToForm()
Add ADT-specific fields to form.
convertADTDefinitionToMulti(ilADTDefinition $a_adt_def)
getSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
Get SQL condition for current value(s)
isValidADTDefinition(ilADTDefinition $a_adt_def)
loadFilter()
Load filter value(s) into ADT.
setSerializedValue(string $a_value)
Set current value(s) in serialized form (for easy persisting)
Class ilADTSearchBridgeMulti.
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 in a property form.
This class represents an option in a checkbox group.
This class represents a property form user interface.
$post
Definition: ltitoken.php:46