ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilADTEnumSearchBridgeMulti.php
Go to the documentation of this file.
1 <?php
2 
3 require_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(ilADT $a_adt)
140  {
141  assert($a_adt instanceof ilADTMultiEnum);
142 
143  $current = $this->getADT()->getSelections();
144  if(is_array($current) &&
145  sizeof($current))
146  {
147  // #16827 / #17087
148  if($this->search_mode == self::SEARCH_MODE_ANY)
149  {
150  foreach((array)$a_adt->getSelections() as $value)
151  {
152  if(in_array($value, $current))
153  {
154  return true;
155  }
156  }
157  }
158  else
159  {
160  // #18028
161  return !(bool)sizeof(array_diff($current, (array)$a_adt->getSelections()));
162  }
163  }
164  return false;
165  }
166 
167 
168  // import/export
169 
170  public function getSerializedValue()
171  {
172  if(!$this->isNull() && $this->isValid())
173  {
174  return serialize($this->getADT()->getSelections());
175  }
176  }
177 
178  public function setSerializedValue($a_value)
179  {
180  $a_value = unserialize($a_value);
181  if(is_array($a_value))
182  {
183  $this->getADT()->setSelections($a_value);
184  }
185  }
186 }
187 
188 ?>
convertADTDefinitionToMulti(ilADTDefinition $a_adt_def)
This class represents an option in a checkbox group.
This class represents a property form user interface.
static getInstance()
Get singleton.
ADT base class.
Definition: class.ilADT.php:11
extractPostValues(array $a_post=null)
Extract data from (post) values.
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
if(!is_array($argv)) $options
readFilter()
Load value(s) from filter store (in session)
This class represents a property in a property form.
Create styles array
The data for the language used.
isValidADTDefinition(ilADTDefinition $a_adt_def)
global $lng
Definition: privfeed.php:17
writeFilter($a_value=null)
Write value(s) to filter store (in session)
global $ilDB
getType()
Get type (from class/instance)
ADT definition base class.
getElementId()
Get element id.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.