ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilADTEnumSearchBridgeMulti.php
Go to the documentation of this file.
1<?php
2
3require_once "Services/ADT/classes/Bridges/class.ilADTSearchBridgeMulti.php";
4
6{
7 protected $multi_source; // [bool]
8 protected $search_mode; // [int]
9
10 const SEARCH_MODE_ALL = 1;
11 const SEARCH_MODE_ANY = 2;
12
13 public function setSearchMode($a_mode)
14 {
15 $this->search_mode = (int)$a_mode;
16 }
17
18 protected function isValidADTDefinition(ilADTDefinition $a_adt_def)
19 {
20 return ($a_adt_def instanceof ilADTEnumDefinition ||
21 $a_adt_def instanceof ilADTMultiEnumDefinition);
22 }
23
24 protected function convertADTDefinitionToMulti(ilADTDefinition $a_adt_def)
25 {
26 if($a_adt_def->getType() == "Enum")
27 {
28 $this->multi_source = false;
29 $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("MultiEnum");
30 $def->setNumeric($a_adt_def->isNumeric());
31 $def->setOptions($a_adt_def->getOptions());
32 return $def;
33 }
34 else
35 {
36 $this->multi_source = true;
37 return $a_adt_def;
38 }
39 }
40
41 public function loadFilter()
42 {
43 $value = $this->readFilter();
44 if($value !== null)
45 {
46 $this->getADT()->setSelections($value);
47 }
48 }
49
50
51 // form
52
53 public function addToForm()
54 {
55 global $lng;
56
57 $def = $this->getADT()->getCopyOfDefinition();
58
59 $options = $def->getOptions();
60 asort($options); // ?
61
62 $cbox = new ilCheckboxGroupInputGUI($this->getTitle(), $this->getElementId());
63 $cbox->setValue($this->getADT()->getSelections());
64
65 foreach($options as $value => $caption)
66 {
67 $option = new ilCheckboxOption($caption, $value);
68 $cbox->addOption($option);
69 }
70
71 $this->addToParentElement($cbox);
72 }
73
74 public function importFromPost(array $a_post = null)
75 {
76 $post = $this->extractPostValues($a_post);
77
78 if($post && $this->shouldBeImportedFromPost($post))
79 {
80 if($this->getForm() instanceof ilPropertyFormGUI)
81 {
82 $item = $this->getForm()->getItemByPostVar($this->getElementId());
83 $item->setValue($post);
84 }
85 else if(array_key_exists($this->getElementId(), $this->table_filter_fields))
86 {
87 $this->table_filter_fields[$this->getElementId()]->setValue($post);
88 $this->writeFilter($post);
89 }
90
91 if(is_array($post))
92 {
93 $this->getADT()->setSelections($post);
94 }
95 }
96 else
97 {
98 $this->getADT()->setSelections();
99 }
100 }
101
102
103 // db
104
105 public function getSQLCondition($a_element_id)
106 {
107 global $ilDB;
108
109 if(!$this->isNull() && $this->isValid())
110 {
111 $type = ($this->getADT() instanceof ilADTMultiEnumText)
112 ? "text"
113 : "integer";
114
115 if($this->multi_source)
116 {
117 include_once "Services/ADT/classes/Types/MultiEnum/class.ilADTMultiEnumDBBridge.php";
118
119 // #16827 / #17087
120 $mode_concat = ($this->search_mode == self::SEARCH_MODE_ANY)
121 ? " OR "
122 : " AND ";
123
124 $parts = array();
125 foreach($this->getADT()->getSelections() as $item)
126 {
127 $item = "%".ilADTMultiEnumDBBridge::SEPARATOR.
128 $item.
130 $parts[] = $ilDB->like($a_element_id, "text", $item, false);
131 }
132 return "(".implode($mode_concat, $parts).")";
133 }
134
135 return $ilDB->in($a_element_id, $this->getADT()->getSelections(), "", $type);
136 }
137 }
138
139 public function isInCondition(ilADTMultiEnum $a_adt)
140 {
141 $current = $this->getADT()->getSelections();
142 if(is_array($current) &&
143 sizeof($current))
144 {
145 // #16827 / #17087
146 if($this->search_mode == self::SEARCH_MODE_ANY)
147 {
148 foreach((array)$a_adt->getSelections() as $value)
149 {
150 if(in_array($value, $current))
151 {
152 return true;
153 }
154 }
155 }
156 else
157 {
158 // #18028
159 return !(bool)sizeof(array_diff($current, (array)$a_adt->getSelections()));
160 }
161 }
162 return false;
163 }
164
165
166 // import/export
167
168 public function getSerializedValue()
169 {
170 if(!$this->isNull() && $this->isValid())
171 {
172 return serialize($this->getADT()->getSelections());
173 }
174 }
175
176 public function setSerializedValue($a_value)
177 {
178 $a_value = unserialize($a_value);
179 if(is_array($a_value))
180 {
181 $this->getADT()->setSelections($a_value);
182 }
183 }
184}
185
186?>
ADT definition base class.
getType()
Get type (from class/instance)
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
addToForm()
Add ADT-specific fields to form.
getSQLCondition($a_element_id)
Get SQL condition for current value(s)
setSerializedValue($a_value)
Set current value(s) in serialized form (for easy persisting)
convertADTDefinitionToMulti(ilADTDefinition $a_adt_def)
Convert definition to multi version.
isValidADTDefinition(ilADTDefinition $a_adt_def)
Check if given ADT definition is valid.
importFromPost(array $a_post=null)
Import values from (search) form request POST data.
loadFilter()
Load filter value(s) into ADT.
static getInstance()
Get singleton.
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.
getElementId()
Get element id.
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
writeFilter($a_value=null)
Write value(s) to filter store (in session)
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.
global $lng
Definition: privfeed.php:40
global $ilDB
if(!is_array($argv)) $options