ILIAS  release_8 Revision v8.24
class.ilADTLocalizedTextSearchBridgeSingle.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected function isValidADTDefinition(ilADTDefinition $a_adt_def): bool
24 {
25 return ($a_adt_def instanceof ilADTLocalizedTextDefinition);
26 }
27
28 // table2gui / filter
29
30 public function loadFilter(): void
31 {
32 $value = $this->readFilter();
33 if ($value !== null) {
34 $this->getADT()->setText($value);
35 }
36 }
37
38 // form
39
40 public function addToForm(): void
41 {
42 $text = new ilTextInputGUI($this->getTitle(), $this->getElementId());
43 $text->setSize(20);
44 $text->setMaxLength(512);
45 $text->setSubmitFormOnEnter(true);
46
47 $text->setValue($this->getADT()->getText());
48
49 $this->addToParentElement($text);
50 }
51
52 public function importFromPost(array $a_post = null): bool
53 {
54 $post = $this->extractPostValues($a_post);
55
56 if ($post && $this->shouldBeImportedFromPost($post)) {
57 if ($this->getForm() instanceof ilPropertyFormGUI) {
58 $item = $this->getForm()->getItemByPostVar($this->getElementId());
59 $item->setValue($post);
60 } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
61 $this->table_filter_fields[$this->getElementId()]->setValue($post);
62 $this->writeFilter($post);
63 }
64 $this->getADT()->setText($post);
65 } else {
66 $this->writeFilter();
67 $this->getADT()->setText();
68 }
69 return true;
70 }
71
72 public function getSQLCondition(string $a_element_id, int $mode = self::SQL_LIKE, array $quotedWords = []): string
73 {
74 if (!$quotedWords) {
75 if ($this->isNull() || !$this->isValid()) {
76 return '';
77 }
78 $quotedWords = $this->getADT()->getText();
79 }
80
81 switch ($mode) {
83 if (!is_array($quotedWords)) {
84 return $a_element_id . " = " . $this->db->quote($quotedWords, "text");
85 } else {
86 return $this->db->in($a_element_id, $quotedWords, false, "text");
87 }
88
89 // no break
90 case self::SQL_LIKE:
91 if (!is_array($quotedWords)) {
92 return $this->db->like($a_element_id, "text", "%" . $quotedWords . "%");
93 } else {
94 $tmp = array();
95 foreach ($quotedWords as $word) {
96 if ($word) {
97 $tmp[] = $this->db->like($a_element_id, "text", "%" . $word . "%");
98 }
99 }
100 if (count($tmp)) {
101 return "(" . implode(" OR ", $tmp) . ")";
102 }
103 }
104 break;
105
107 if (!is_array($quotedWords)) {
108 return $this->db->like($a_element_id, "text", $quotedWords . "%");
109 }
110 break;
111
113 if (!is_array($quotedWords)) {
114 return $this->db->like($a_element_id, "text", "%" . $quotedWords);
115 }
116 break;
117 }
118 return '';
119 }
120
121 public function isInCondition(ilADT $a_adt): bool
122 {
123 if ($this->getADT()->getCopyOfDefinition()->isComparableTo($a_adt)) {
124 foreach ($a_adt->getTranslations() as $language => $text) {
125 $search_term = strtolower(trim((string) $this->getADT()->getText()));
126 $text = strtolower(trim((string) $text));
127 if (str_contains($text, $search_term)) {
128 return true;
129 }
130 }
131 }
132 return false;
133 }
134
135 // import/export
136
137 public function getSerializedValue(): string
138 {
139 if (!$this->isNull() && $this->isValid()) {
140 return serialize(array($this->getADT()->getText()));
141 }
142 return '';
143 }
144
145 public function setSerializedValue(string $a_value): void
146 {
147 $a_value = unserialize($a_value);
148 if (is_array($a_value)) {
149 $this->getADT()->setText($a_value[0]);
150 }
151 }
152}
ADT definition base class.
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
getSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
Get SQL condition for current value(s)
setSerializedValue(string $a_value)
Set current value(s) in serialized form (for easy persisting)
isInCondition(ilADT $a_adt)
Compare directly against ADT.
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.
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
writeFilter($a_value=null)
Write value(s) to filter store (in session)
ADT base class.
Definition: class.ilADT.php:12
This class represents a property form user interface.
This class represents a text property in a property form.
$post
Definition: ltitoken.php:49