ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 $this->addTextInputToForm(true);
43 }
44
45 public function addToFilterForm(): void
46 {
47 $this->addTextInputToForm(false);
48 }
49
50 public function importFromPost(?array $a_post = null): bool
51 {
52 $post = $this->extractPostValues($a_post);
53
54 if ($post && $this->shouldBeImportedFromPost($post)) {
55 if ($this->getForm() instanceof ilPropertyFormGUI) {
56 $item = $this->getForm()->getItemByPostVar($this->getElementId());
57 $item->setValue($post);
58 } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
59 $this->table_filter_fields[$this->getElementId()]->setValue($post);
60 $this->writeFilter($post);
61 }
62 $this->getADT()->setText($post);
63 } else {
64 $this->writeFilter();
65 $this->getADT()->setText();
66 }
67 return true;
68 }
69
70 public function getSQLCondition(string $a_element_id, int $mode = self::SQL_LIKE, array $quotedWords = []): string
71 {
72 if (!$quotedWords) {
73 if ($this->isNull() || !$this->isValid()) {
74 return '';
75 }
76 $quotedWords = $this->getADT()->getText();
77 }
78
79 switch ($mode) {
81 if (!is_array($quotedWords)) {
82 return $a_element_id . " = " . $this->db->quote($quotedWords, "text");
83 } else {
84 return $this->db->in($a_element_id, $quotedWords, false, "text");
85 }
86
87 // no break
88 case self::SQL_LIKE:
89 if (!is_array($quotedWords)) {
90 return $this->db->like($a_element_id, "text", "%" . $quotedWords . "%");
91 } else {
92 $tmp = array();
93 foreach ($quotedWords as $word) {
94 if ($word) {
95 $tmp[] = $this->db->like($a_element_id, "text", "%" . $word . "%");
96 }
97 }
98 if (count($tmp)) {
99 return "(" . implode(" OR ", $tmp) . ")";
100 }
101 }
102 break;
103
105 if (!is_array($quotedWords)) {
106 return $this->db->like($a_element_id, "text", $quotedWords . "%");
107 }
108 break;
109
111 if (!is_array($quotedWords)) {
112 return $this->db->like($a_element_id, "text", "%" . $quotedWords);
113 }
114 break;
115 }
116 return '';
117 }
118
119 public function isInCondition(ilADT $a_adt): bool
120 {
121 if ($this->getADT()->getCopyOfDefinition()->isComparableTo($a_adt)) {
122 $relevant_translation = $a_adt->getCopyOfDefinition()->getMultilingualValueSupport() ?
123 $a_adt->getTranslations() :
124 [$a_adt->getTextForLanguage($a_adt->getCopyOfDefinition()->getDefaultLanguage())];
125
126 foreach ($relevant_translation as $text) {
127 $search_term = strtolower(trim((string) $this->getADT()->getText()));
128 $text = strtolower(trim((string) $text));
129 if (str_contains($text, $search_term)) {
130 return true;
131 }
132 }
133 }
134 return false;
135 }
136
137 // import/export
138
139 public function getSerializedValue(): string
140 {
141 if (!$this->isNull() && $this->isValid()) {
142 return serialize(array($this->getADT()->getText()));
143 }
144 return '';
145 }
146
147 public function setSerializedValue(string $a_value): void
148 {
149 $a_value = unserialize($a_value);
150 if (is_array($a_value)) {
151 $this->getADT()->setText($a_value[0]);
152 }
153 }
154}
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.
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:26
getCopyOfDefinition()
Get copy of definition.
This class represents a property form user interface.
$post
Definition: ltitoken.php:46