ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTExternalLinkSearchBridgeSingle.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
33 protected function isValidADTDefinition(\ilADTDefinition $a_adt_def): bool
34 {
35 return $a_adt_def instanceof ilADTExternalLinkDefinition;
36 }
37
41 public function loadFilter(): void
42 {
43 $value = $this->readFilter();
44 if ($value !== null) {
45 $this->getADT()->setUrl($value);
46 }
47 }
48
52 public function addToForm(): void
53 {
54 $url = new ilTextInputGUI($this->getTitle(), $this->getElementId());
55 $url->setSize(255);
56 $url->setValue($this->getADT()->getUrl());
58 }
59
60 public function importFromPost(?array $a_post = null): bool
61 {
62 $post = $this->extractPostValues($a_post);
63
64 if ($post && $this->shouldBeImportedFromPost($post)) {
65 if ($this->getForm() instanceof ilPropertyFormGUI) {
66 $item = $this->getForm()->getItemByPostVar($this->getElementId());
67 $item->setValue($post);
68 } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
69 $this->table_filter_fields[$this->getElementId()]->setValue($post);
70 $this->writeFilter($post);
71 }
72
73 $this->getADT()->setUrl($post);
74 } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
75 $this->table_filter_fields[$this->getElementId()]->setValue($post);
76 $this->writeFilter($post);
77 $this->getADT()->setUrl($post);
78 } else {
79 $this->writeFilter();
80 $this->getADT()->setUrl(null);
81 }
82 return true;
83 }
84
92 public function getSQLCondition(string $a_element_id, int $mode = self::SQL_LIKE, array $quotedWords = []): string
93 {
94 return $this->buildSQLCondition($a_element_id, $mode, $quotedWords) . ' OR ' .
95 $this->buildSQLCondition('title', $mode, $quotedWords);
96 }
97
98 protected function buildSQLCondition(string $a_element_id, int $mode = self::SQL_LIKE, array $quotedWords = []): string
99 {
100 if (!$quotedWords) {
101 if ($this->isNull() || !$this->isValid()) {
102 return '';
103 }
104 $quotedWords = $this->getADT()->getUrl();
105 }
106
107 switch ($mode) {
108 case self::SQL_STRICT:
109 if (!is_array($quotedWords)) {
110 return $a_element_id . " = " . $this->db->quote($quotedWords, "text");
111 } else {
112 return $this->db->in($a_element_id, $quotedWords, false, "text");
113 }
114
115 // no break
116 case self::SQL_LIKE:
117 if (!is_array($quotedWords)) {
118 return $this->db->like($a_element_id, "text", "%" . $quotedWords . "%");
119 } else {
120 $tmp = array();
121 foreach ($quotedWords as $word) {
122 if ($word) {
123 $tmp[] = $this->db->like($a_element_id, "text", "%" . $word . "%");
124 }
125 }
126 if (count($tmp)) {
127 return "(" . implode(" OR ", $tmp) . ")";
128 }
129 }
130 break;
131
133 if (!is_array($quotedWords)) {
134 return $this->db->like($a_element_id, "text", $quotedWords . "%");
135 }
136 break;
137
139 if (!is_array($quotedWords)) {
140 return $this->db->like($a_element_id, "text", "%" . $quotedWords);
141 }
142 break;
143 }
144 return '';
145 }
146
152 public function isInCondition(ilADT $a_adt): bool
153 {
154 if ($this->getADT()->getCopyOfDefinition()->isComparableTo($a_adt)) {
155 $search_term = strtolower(trim((string) $this->getADT()->getUrl()));
156 $title = strtolower(trim((string) $a_adt->getTitle()));
157 $url = strtolower(trim((string) $a_adt->getUrl()));
158 return
159 str_contains($title, $search_term) ||
160 str_contains($url, $search_term);
161 }
162 return false;
163 }
164
169 public function getSerializedValue(): string
170 {
171 if (!$this->isNull() && $this->isValid()) {
172 return serialize(array($this->getADT()->getUrl()));
173 }
174 return '';
175 }
176
181 public function setSerializedValue(string $a_value): void
182 {
183 $a_value = unserialize($a_value);
184 if (is_array($a_value)) {
185 $this->getADT()->setUrl($a_value[0]);
186 }
187 }
188}
ADT definition base class.
getSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
Get sql condition.
isValidADTDefinition(\ilADTDefinition $a_adt_def)
Is valid type.
buildSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
Class ilADTSearchBridgeSingle.
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:26
This class represents a property form user interface.
This class represents a text property in a property form.
$post
Definition: ltitoken.php:46
$url
Definition: shib_logout.php:68