ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  $this->multi_source = false;
28  $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("MultiEnum");
29  $def->setNumeric($a_adt_def->isNumeric());
30  $def->setOptions($a_adt_def->getOptions());
31  return $def;
32  } else {
33  $this->multi_source = true;
34  return $a_adt_def;
35  }
36  }
37 
38  public function loadFilter()
39  {
40  $value = $this->readFilter();
41  if ($value !== null) {
42  $this->getADT()->setSelections($value);
43  }
44  }
45 
46 
47  // form
48 
49  public function addToForm()
50  {
51  global $lng;
52 
53  $def = $this->getADT()->getCopyOfDefinition();
54 
55  $options = $def->getOptions();
56  asort($options); // ?
57 
58  $cbox = new ilCheckboxGroupInputGUI($this->getTitle(), $this->getElementId());
59  $cbox->setValue($this->getADT()->getSelections());
60 
61  foreach ($options as $value => $caption) {
62  $option = new ilCheckboxOption($caption, $value);
63  $cbox->addOption($option);
64  }
65 
66  $this->addToParentElement($cbox);
67  }
68 
69  public function importFromPost(array $a_post = null)
70  {
71  $post = $this->extractPostValues($a_post);
72 
73  if ($post && $this->shouldBeImportedFromPost($post)) {
74  if ($this->getForm() instanceof ilPropertyFormGUI) {
75  $item = $this->getForm()->getItemByPostVar($this->getElementId());
76  $item->setValue($post);
77  } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
78  $this->table_filter_fields[$this->getElementId()]->setValue($post);
79  $this->writeFilter($post);
80  }
81 
82  if (is_array($post)) {
83  $this->getADT()->setSelections($post);
84  }
85  } else {
86  $this->getADT()->setSelections();
87  }
88  }
89 
90 
91  // db
92 
93  public function getSQLCondition($a_element_id)
94  {
95  global $ilDB;
96 
97  if (!$this->isNull() && $this->isValid()) {
98  $type = ($this->getADT() instanceof ilADTMultiEnumText)
99  ? "text"
100  : "integer";
101 
102  if ($this->multi_source) {
103  include_once "Services/ADT/classes/Types/MultiEnum/class.ilADTMultiEnumDBBridge.php";
104 
105  // #16827 / #17087
106  $mode_concat = ($this->search_mode == self::SEARCH_MODE_ANY)
107  ? " OR "
108  : " AND ";
109 
110  $parts = array();
111  foreach ($this->getADT()->getSelections() as $item) {
112  $item = "%" . ilADTMultiEnumDBBridge::SEPARATOR .
113  $item .
115  $parts[] = $ilDB->like($a_element_id, "text", $item, false);
116  }
117  return "(" . implode($mode_concat, $parts) . ")";
118  }
119 
120  return $ilDB->in($a_element_id, $this->getADT()->getSelections(), "", $type);
121  }
122  }
123 
124  public function isInCondition(ilADT $a_adt)
125  {
126  assert($a_adt instanceof ilADTMultiEnum);
127 
128  $current = $this->getADT()->getSelections();
129  if (is_array($current) &&
130  sizeof($current)) {
131  // #16827 / #17087
132  if ($this->search_mode == self::SEARCH_MODE_ANY) {
133  foreach ((array) $a_adt->getSelections() as $value) {
134  if (in_array($value, $current)) {
135  return true;
136  }
137  }
138  } else {
139  // #18028
140  return !(bool) sizeof(array_diff($current, (array) $a_adt->getSelections()));
141  }
142  }
143  return false;
144  }
145 
146 
147  // import/export
148 
149  public function getSerializedValue()
150  {
151  if (!$this->isNull() && $this->isValid()) {
152  return serialize($this->getADT()->getSelections());
153  }
154  }
155 
156  public function setSerializedValue($a_value)
157  {
158  $a_value = unserialize($a_value);
159  if (is_array($a_value)) {
160  $this->getADT()->setSelections($a_value);
161  }
162  }
163 }
convertADTDefinitionToMulti(ilADTDefinition $a_adt_def)
This class represents an option in a checkbox group.
This class represents a property form user interface.
$type
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.
readFilter()
Load value(s) from filter store (in session)
$post
Definition: post.php:34
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
$def
Definition: croninfo.php:21
getType()
Get type (from class/instance)
ADT definition base class.
getElementId()
Get element id.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20