ILIAS  release_8 Revision v8.24
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 if (!$quotedWords) {
95 if ($this->isNull() || !$this->isValid()) {
96 return '';
97 }
98 $quotedWords = $this->getADT()->getUrl();
99 }
100
101 switch ($mode) {
102 case self::SQL_STRICT:
103 if (!is_array($quotedWords)) {
104 return $a_element_id . " = " . $this->db->quote($quotedWords, "text");
105 } else {
106 return $this->db->in($a_element_id, $quotedWords, false, "text");
107 }
108
109 // no break
110 case self::SQL_LIKE:
111 if (!is_array($quotedWords)) {
112 return $this->db->like($a_element_id, "text", "%" . $quotedWords . "%");
113 } else {
114 $tmp = array();
115 foreach ($quotedWords as $word) {
116 if ($word) {
117 $tmp[] = $this->db->like($a_element_id, "text", "%" . $word . "%");
118 }
119 }
120 if (count($tmp)) {
121 return "(" . implode(" OR ", $tmp) . ")";
122 }
123 }
124 break;
125
127 if (!is_array($quotedWords)) {
128 return $this->db->like($a_element_id, "text", $quotedWords . "%");
129 }
130 break;
131
133 if (!is_array($quotedWords)) {
134 return $this->db->like($a_element_id, "text", "%" . $quotedWords);
135 }
136 break;
137 }
138 return '';
139 }
140
146 public function isInCondition(ilADT $a_adt): bool
147 {
148 if ($this->getADT()->getCopyOfDefinition()->isComparableTo($a_adt)) {
149 $search_term = strtolower(trim((string) $this->getADT()->getUrl()));
150 $title = strtolower(trim((string) $a_adt->getTitle()));
151 $url = strtolower(trim((string) $a_adt->getUrl()));
152 return
153 str_contains($title, $search_term) ||
154 str_contains($url, $search_term);
155 }
156 return false;
157 }
158
163 public function getSerializedValue(): string
164 {
165 if (!$this->isNull() && $this->isValid()) {
166 return serialize(array($this->getADT()->getUrl()));
167 }
168 return '';
169 }
170
175 public function setSerializedValue(string $a_value): void
176 {
177 $a_value = unserialize($a_value);
178 if (is_array($a_value)) {
179 $this->getADT()->setUrl($a_value[0]);
180 }
181 }
182}
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.
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:12
This class represents a property form user interface.
This class represents a text property in a property form.
$post
Definition: ltitoken.php:49
$url