ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilADTTextSearchBridgeSingle.php
Go to the documentation of this file.
1 <?php
2 
3 require_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 
40  $this->addToParentElement($text);
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  {
87  case self::SQL_STRICT:
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 
120  case self::SQL_LIKE_END:
121  if(!is_array($a_value))
122  {
123  return $ilDB->like($a_element_id, "text", $a_value."%");
124  }
125  break;
126 
127  case self::SQL_LIKE_START:
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(ilADT $a_adt)
137  {
138  assert($a_adt instanceof ilADTText);
139 
140  // :TODO: search mode (see above)
141  return $this->getADT()->equals($a_adt);
142  }
143 
144 
145  // import/export
146 
147  public function getSerializedValue()
148  {
149  if(!$this->isNull() && $this->isValid())
150  {
151  return serialize(array($this->getADT()->getText()));
152  }
153  }
154 
155  public function setSerializedValue($a_value)
156  {
157  $a_value = unserialize($a_value);
158  if(is_array($a_value))
159  {
160  $this->getADT()->setText($a_value[0]);
161  }
162  }
163 }
164 
165 ?>
This class represents a property form user interface.
isValidADTDefinition(ilADTDefinition $a_adt_def)
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)
This class represents a text property in a property form.
Create styles array
The data for the language used.
writeFilter($a_value=null)
Write value(s) to filter store (in session)
global $ilDB
$text
ADT definition base class.
getElementId()
Get element id.
getSQLCondition($a_element_id, $a_mode=self::SQL_LIKE, $a_value=null)
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.