ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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  const ENUM_SEARCH_COLUMN = 'value_index';
8 
9  protected $multi_source; // [bool]
10  protected $search_mode; // [int]
11 
12  const SEARCH_MODE_ALL = 1;
13  const SEARCH_MODE_ANY = 2;
14 
15  public function setSearchMode($a_mode)
16  {
17  $this->search_mode = (int) $a_mode;
18  }
19 
20  public function getSearchColumn() : string
21  {
22  return self::ENUM_SEARCH_COLUMN;
23  }
24 
25 
26  protected function isValidADTDefinition(ilADTDefinition $a_adt_def)
27  {
28  return ($a_adt_def instanceof ilADTEnumDefinition ||
29  $a_adt_def instanceof ilADTMultiEnumDefinition);
30  }
31 
32  protected function convertADTDefinitionToMulti(ilADTDefinition $a_adt_def)
33  {
34  if ($a_adt_def->getType() == "Enum") {
35  $this->multi_source = false;
36  $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("MultiEnum");
37  $def->setNumeric($a_adt_def->isNumeric());
38  $def->setOptions($a_adt_def->getOptions());
39  return $def;
40  } else {
41  $this->multi_source = true;
42  return $a_adt_def;
43  }
44  }
45 
46  public function loadFilter()
47  {
48  $value = $this->readFilter();
49  if ($value !== null) {
50  $this->getADT()->setSelections($value);
51  }
52  }
53 
54 
55  // form
56 
57  public function addToForm()
58  {
59  global $DIC;
60 
61  $lng = $DIC['lng'];
62 
63  $def = $this->getADT()->getCopyOfDefinition();
64 
65  $options = $def->getOptions();
66  asort($options); // ?
67 
68  $cbox = new ilCheckboxGroupInputGUI($this->getTitle(), $this->getElementId());
69  $cbox->setValue($this->getADT()->getSelections());
70 
71  foreach ($options as $value => $caption) {
72  $option = new ilCheckboxOption($caption, $value);
73  $cbox->addOption($option);
74  }
75 
76  $this->addToParentElement($cbox);
77  }
78 
79  public function importFromPost(array $a_post = null)
80  {
81  $post = $this->extractPostValues($a_post);
82 
83  if ($post && $this->shouldBeImportedFromPost($post)) {
84  if ($this->getForm() instanceof ilPropertyFormGUI) {
85  $item = $this->getForm()->getItemByPostVar($this->getElementId());
86  $item->setValue($post);
87  } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
88  $this->table_filter_fields[$this->getElementId()]->setValue($post);
89  $this->writeFilter($post);
90  }
91 
92  if (is_array($post)) {
93  $this->getADT()->setSelections($post);
94  }
95  } else {
96  $this->getADT()->setSelections();
97  }
98  }
99 
100 
101  // db
102 
103  public function getSQLCondition($a_element_id)
104  {
105  global $DIC;
106 
107  $ilDB = $DIC->database();
108 
109  if (!$this->isNull() && $this->isValid()) {
110  return $ilDB->in(
111  $this->getSearchColumn(),
112  $this->getADT()->getSelections(),
113  '',
115  );
116  }
117  }
118 
119  public function isInCondition(ilADT $a_adt)
120  {
121  assert($a_adt instanceof ilADTMultiEnum);
122 
123  $current = $this->getADT()->getSelections();
124  if (is_array($current) &&
125  sizeof($current)) {
126  // #16827 / #17087
127  if ($this->search_mode == self::SEARCH_MODE_ANY) {
128  foreach ((array) $a_adt->getSelections() as $value) {
129  if (in_array($value, $current)) {
130  return true;
131  }
132  }
133  } else {
134  // #18028
135  return !(bool) sizeof(array_diff($current, (array) $a_adt->getSelections()));
136  }
137  }
138  return false;
139  }
140 
141 
142  // import/export
143 
144  public function getSerializedValue()
145  {
146  if (!$this->isNull() && $this->isValid()) {
147  return serialize($this->getADT()->getSelections());
148  }
149  }
150 
151  public function setSerializedValue($a_value)
152  {
153  $a_value = unserialize($a_value);
154  if (is_array($a_value)) {
155  $this->getADT()->setSelections($a_value);
156  }
157  }
158 }
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.
readFilter()
Load value(s) from filter store (in session)
$lng
global $DIC
Definition: goto.php:24
This class represents a property in a property form.
isValidADTDefinition(ilADTDefinition $a_adt_def)
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.