ILIAS  release_8 Revision v8.24
class.ilADTEnumSearchBridgeMulti.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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 asort($options); // ?
82
83 $cbox = new ilCheckboxGroupInputGUI($this->getTitle(), $this->getElementId());
84 $cbox->setValue($this->getADT()->getSelections());
85
86 foreach ($options as $value => $caption) {
87 $option = new ilCheckboxOption($caption, (string) $value);
88 $cbox->addOption($option);
89 }
90
91 $this->addToParentElement($cbox);
92 }
93
94 public function importFromPost(array $a_post = null): bool
95 {
96 $post = $this->extractPostValues($a_post);
97
98 if ($post && $this->shouldBeImportedFromPost($post)) {
99 if ($this->getForm() instanceof ilPropertyFormGUI) {
100 $item = $this->getForm()->getItemByPostVar($this->getElementId());
101 $item->setValue($post);
102 } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
103 $this->table_filter_fields[$this->getElementId()]->setValue($post);
104 $this->writeFilter($post);
105 }
106
107 if (is_array($post)) {
108 $this->getADT()->setSelections($post);
109 }
110 } else {
111 $this->getADT()->setSelections();
112 // BT 35593: multi enum filter should reset when nothing is selected
113 if (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
114 $this->writeFilter();
115 }
116 }
117 return true;
118 }
119
120 // db
121
122 public function getSQLCondition(string $a_element_id, int $mode = self::SQL_LIKE, array $quotedWords = []): string
123 {
124 if (!$this->isNull() && $this->isValid()) {
125 return $this->db->in(
126 $this->getSearchColumn(),
127 (array) $this->getADT()->getSelections(),
128 false,
130 );
131 }
132 return '';
133 }
134
135 public function isInCondition(ilADT $a_adt): bool
136 {
137 assert($a_adt instanceof ilADTMultiEnum);
138
139 $current = $this->getADT()->getSelections();
140 if (is_array($current) &&
141 count($current)) {
142 // #16827 / #17087
143 if ($this->search_mode == self::SEARCH_MODE_ANY) {
144 foreach ((array) $a_adt->getSelections() as $value) {
145 if (in_array($value, $current)) {
146 return true;
147 }
148 }
149 } else {
150 // #18028
151 return !count(array_diff($current, (array) $a_adt->getSelections()));
152 }
153 }
154 return false;
155 }
156
157 // import/export
158
159 public function getSerializedValue(): string
160 {
161 if (!$this->isNull() && $this->isValid()) {
162 return serialize($this->getADT()->getSelections());
163 }
164 return '';
165 }
166
167 public function setSerializedValue(string $a_value): void
168 {
169 $a_value = unserialize($a_value);
170 if (is_array($a_value)) {
171 $this->getADT()->setSelections($a_value);
172 }
173 }
174}
ADT definition base class.
getType()
Get type (from class/instance)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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:12
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
$post
Definition: ltitoken.php:49