ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  $this->getADT()->setText($value);
24  }
25  }
26 
27 
28  // form
29 
30  public function addToForm()
31  {
32  $text = new ilTextInputGUI($this->getTitle(), $this->getElementId());
33  $text->setSize(20);
34  $text->setMaxLength(512);
35  $text->setSubmitFormOnEnter(true);
36 
37  $text->setValue($this->getADT()->getText());
38 
39  $this->addToParentElement($text);
40  }
41 
42  public function importFromPost(array $a_post = null)
43  {
44  $post = $this->extractPostValues($a_post);
45 
46  if ($post && $this->shouldBeImportedFromPost($post)) {
47  if ($this->getForm() instanceof ilPropertyFormGUI) {
48  $item = $this->getForm()->getItemByPostVar($this->getElementId());
49  $item->setValue($post);
50  } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
51  $this->table_filter_fields[$this->getElementId()]->setValue($post);
52  $this->writeFilter($post);
53  }
54 
55  $this->getADT()->setText($post);
56  } else {
57  $this->writeFilter();
58  $this->getADT()->setText();
59  }
60  }
61 
62 
63  // db
64 
65  public function getSQLCondition($a_element_id, $a_mode = self::SQL_LIKE, $a_value = null)
66  {
67  global $DIC;
68 
69  $ilDB = $DIC['ilDB'];
70 
71  if (!$a_value) {
72  if ($this->isNull() || !$this->isValid()) {
73  return;
74  }
75  $a_value = $this->getADT()->getText();
76  }
77 
78  switch ($a_mode) {
79  case self::SQL_STRICT:
80  if (!is_array($a_value)) {
81  return $a_element_id . " = " . $ilDB->quote($a_value, "text");
82  } else {
83  return $ilDB->in($a_element_id, $a_value, "", "text");
84  }
85  break;
86 
87  case self::SQL_LIKE:
88  if (!is_array($a_value)) {
89  return $ilDB->like($a_element_id, "text", "%" . $a_value . "%");
90  } else {
91  $tmp = array();
92  foreach ($a_value as $word) {
93  if ($word) {
94  $tmp[] = $ilDB->like($a_element_id, "text", "%" . $word . "%");
95  }
96  }
97  if (sizeof($tmp)) {
98  return "(" . implode(" OR ", $tmp) . ")";
99  }
100  }
101  break;
102 
103  case self::SQL_LIKE_END:
104  if (!is_array($a_value)) {
105  return $ilDB->like($a_element_id, "text", $a_value . "%");
106  }
107  break;
108 
109  case self::SQL_LIKE_START:
110  if (!is_array($a_value)) {
111  return $ilDB->like($a_element_id, "text", "%" . $a_value);
112  }
113  break;
114  }
115  }
116 
117  public function isInCondition(ilADT $a_adt)
118  {
119  assert($a_adt instanceof ilADTText);
120 
121  // :TODO: search mode (see above)
122  return $this->getADT()->equals($a_adt);
123  }
124 
125 
126  // import/export
127 
128  public function getSerializedValue()
129  {
130  if (!$this->isNull() && $this->isValid()) {
131  return serialize(array($this->getADT()->getText()));
132  }
133  }
134 
135  public function setSerializedValue($a_value)
136  {
137  $a_value = unserialize($a_value);
138  if (is_array($a_value)) {
139  $this->getADT()->setText($a_value[0]);
140  }
141  }
142 }
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
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)
$text
Definition: errorreport.php:18
This class represents a text property in a property form.
$post
Definition: post.php:34
writeFilter($a_value=null)
Write value(s) to filter store (in session)
global $ilDB
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.