ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilADTTextSearchBridgeSingle.php
Go to the documentation of this file.
1<?php
2
3require_once "Services/ADT/classes/Bridges/class.ilADTSearchBridgeSingle.php";
4
6{
7 const SQL_STRICT = 1;
8 const SQL_LIKE = 2;
9 const SQL_LIKE_END = 3;
10 const SQL_LIKE_START = 4;
11
12 protected function isValidADTDefinition(ilADTDefinition $a_adt_def)
13 {
14 return ($a_adt_def instanceof ilADTTextDefinition);
15 }
16
17 // table2gui / filter
18
19 public function loadFilter()
20 {
21 $value = $this->readFilter();
22 if($value !== null)
23 {
24 $this->getADT()->setText($value);
25 }
26 }
27
28
29 // form
30
31 public function addToForm()
32 {
33 $text = new ilTextInputGUI($this->getTitle(), $this->getElementId());
34 $text->setSize(20);
35 $text->setMaxLength(512);
36 $text->setSubmitFormOnEnter(true);
37
38 $text->setValue($this->getADT()->getText());
39
41 }
42
43 public function importFromPost(array $a_post = null)
44 {
45 $post = $this->extractPostValues($a_post);
46
47 if($post && $this->shouldBeImportedFromPost($post))
48 {
49 if($this->getForm() instanceof ilPropertyFormGUI)
50 {
51 $item = $this->getForm()->getItemByPostVar($this->getElementId());
52 $item->setValue($post);
53 }
54 else if(array_key_exists($this->getElementId(), $this->table_filter_fields))
55 {
56 $this->table_filter_fields[$this->getElementId()]->setValue($post);
57 $this->writeFilter($post);
58 }
59
60 $this->getADT()->setText($post);
61 }
62 else
63 {
64 $this->writeFilter();
65 $this->getADT()->setText();
66 }
67 }
68
69
70 // db
71
72 public function getSQLCondition($a_element_id, $a_mode = self::SQL_LIKE, $a_value = null)
73 {
74 global $ilDB;
75
76 if(!$a_value)
77 {
78 if($this->isNull() || !$this->isValid())
79 {
80 return;
81 }
82 $a_value = $this->getADT()->getText();
83 }
84
85 switch($a_mode)
86 {
88 if(!is_array($a_value))
89 {
90 return $a_element_id." = ".$ilDB->quote($a_value, "text");
91 }
92 else
93 {
94 return $ilDB->in($a_element_id, $a_value, "", "text");
95 }
96 break;
97
98 case self::SQL_LIKE:
99 if(!is_array($a_value))
100 {
101 return $ilDB->like($a_element_id, "text", "%".$a_value."%");
102 }
103 else
104 {
105 $tmp = array();
106 foreach($a_value as $word)
107 {
108 if($word)
109 {
110 $tmp[] = $ilDB->like($a_element_id, "text", "%".$word."%");
111 }
112 }
113 if(sizeof($tmp))
114 {
115 return "(".implode(" OR ", $tmp).")";
116 }
117 }
118 break;
119
121 if(!is_array($a_value))
122 {
123 return $ilDB->like($a_element_id, "text", $a_value."%");
124 }
125 break;
126
128 if(!is_array($a_value))
129 {
130 return $ilDB->like($a_element_id, "text", "%".$a_value);
131 }
132 break;
133 }
134 }
135
136 public function isInCondition(ilADTText $a_adt)
137 {
138 // :TODO: search mode (see above)
139 return $this->getADT()->equals($a_adt);
140 }
141
142
143 // import/export
144
145 public function getSerializedValue()
146 {
147 if(!$this->isNull() && $this->isValid())
148 {
149 return serialize(array($this->getADT()->getText()));
150 }
151 }
152
153 public function setSerializedValue($a_value)
154 {
155 $a_value = unserialize($a_value);
156 if(is_array($a_value))
157 {
158 $this->getADT()->setText($a_value[0]);
159 }
160 }
161}
162
163?>
ADT definition base class.
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)
isValidADTDefinition(ilADTDefinition $a_adt_def)
Check if given ADT definition is valid.
setSerializedValue($a_value)
Set current value(s) in serialized form (for easy persisting)
importFromPost(array $a_post=null)
Import values from (search) form request POST data.
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
loadFilter()
Load filter value(s) into ADT.
getSQLCondition($a_element_id, $a_mode=self::SQL_LIKE, $a_value=null)
addToForm()
Add ADT-specific fields to form.
This class represents a property form user interface.
This class represents a text property in a property form.
$text
global $ilDB