ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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; // [boo]
8
9 protected function isValidADTDefinition(ilADTDefinition $a_adt_def)
10 {
11 return ($a_adt_def instanceof ilADTEnumDefinition ||
12 $a_adt_def instanceof ilADTMultiEnumDefinition);
13 }
14
15 protected function convertADTDefinitionToMulti(ilADTDefinition $a_adt_def)
16 {
17 if($a_adt_def->getType() == "Enum")
18 {
19 $this->multi_source = false;
20 $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("MultiEnum");
21 $def->setNumeric($a_adt_def->isNumeric());
22 $def->setOptions($a_adt_def->getOptions());
23 return $def;
24 }
25 else
26 {
27 $this->multi_source = true;
28 return $a_adt_def;
29 }
30 }
31
32 public function loadFilter()
33 {
34 $value = $this->readFilter();
35 if($value !== null)
36 {
37 $this->getADT()->setSelections($value);
38 }
39 }
40
41
42 // form
43
44 public function addToForm()
45 {
46 global $lng;
47
48 $def = $this->getADT()->getCopyOfDefinition();
49
50 $options = $def->getOptions();
51 asort($options); // ?
52
53 $cbox = new ilCheckboxGroupInputGUI($this->getTitle(), $this->getElementId());
54 $cbox->setValue($this->getADT()->getSelections());
55
56 foreach($options as $value => $caption)
57 {
58 $option = new ilCheckboxOption($caption, $value);
59 $cbox->addOption($option);
60 }
61
62 $this->addToParentElement($cbox);
63 }
64
65 public function importFromPost(array $a_post = null)
66 {
67 $post = $this->extractPostValues($a_post);
68
69 if($post && $this->shouldBeImportedFromPost($post))
70 {
71 if($this->getForm() instanceof ilPropertyFormGUI)
72 {
73 $item = $this->getForm()->getItemByPostVar($this->getElementId());
74 $item->setValue($post);
75 }
76 else if(array_key_exists($this->getElementId(), $this->table_filter_fields))
77 {
78 $this->table_filter_fields[$this->getElementId()]->setValue($post);
79 $this->writeFilter($post);
80 }
81
82 if(is_array($post))
83 {
84 $this->getADT()->setSelections($post);
85 }
86 }
87 else
88 {
89 $this->getADT()->setSelections();
90 }
91 }
92
93
94 // db
95
96 public function getSQLCondition($a_element_id)
97 {
98 global $ilDB;
99
100 if(!$this->isNull() && $this->isValid())
101 {
102 $type = ($this->getADT() instanceof ilADTMultiEnumText)
103 ? "text"
104 : "integer";
105
106 if($this->multi_source)
107 {
108 include_once "Services/ADT/classes/Types/MultiEnum/class.ilADTMultiEnumDBBridge.php";
109
110 $parts = array();
111 foreach($this->getADT()->getSelections() as $item)
112 {
113 $item = "%".ilADTMultiEnumDBBridge::SEPARATOR.
114 $item.
116 $parts[] = $ilDB->like($a_element_id, "text", $item, false);
117 }
118 return "(".implode(" AND ", $parts).")";
119 }
120
121 return $ilDB->in($a_element_id, $this->getADT()->getSelections(), "", $type);
122 }
123 }
124
125 public function isInCondition(ilADTMultiEnum $a_adt)
126 {
127 return $this->getADT()->equals($a_adt);
128 }
129
130
131 // import/export
132
133 public function getSerializedValue()
134 {
135 if(!$this->isNull() && $this->isValid())
136 {
137 return serialize($this->getADT()->getSelections());
138 }
139 }
140
141 public function setSerializedValue($a_value)
142 {
143 $a_value = unserialize($a_value);
144 if(is_array($a_value))
145 {
146 $this->getADT()->setSelections($a_value);
147 }
148 }
149}
150
151?>
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