ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTInternalLinkSearchBridgeSingle.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 private $title_query = '';
29
35 protected function isValidADTDefinition(\ilADTDefinition $a_adt_def): bool
36 {
37 return $a_adt_def instanceof ilADTInternalLinkDefinition;
38 }
39
40 public function setTitleQuery(string $query): void
41 {
42 $this->title_query = $query;
43 }
44
45 public function getTitleQuery(): string
46 {
47 return $this->title_query;
48 }
49
50 /*
51 * Add search property to form
52 */
53 public function addToForm(): void
54 {
55 $title = new ilTextInputGUI($this->getTitle(), $this->getElementId());
56 $title->setSize(255);
57 $title->setValue($this->getTitleQuery());
59 }
60
64 public function loadFilter(): void
65 {
66 $value = $this->readFilter();
67 if ($value !== null && $value !== '') {
68 $this->getADT()->setTargetRefId(1);
69 $this->setTitleQuery($value);
70 }
71 }
72
73 public function importFromPost(?array $a_post = null): bool
74 {
75 $post = $this->extractPostValues($a_post);
76
77 if ($post && $this->shouldBeImportedFromPost($post)) {
78 if ($this->getForm() instanceof ilPropertyFormGUI) {
79 $item = $this->getForm()->getItemByPostVar($this->getElementId());
80 $item->setValue($post);
81 $this->setTitleQuery($post);
82 $this->getADT()->setTargetRefId(1);
83 } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
84 $this->table_filter_fields[$this->getElementId()]->setValue($post);
85 $this->writeFilter($post);
86 $this->setTitleQuery($post);
87 $this->getADT()->setTargetRefId(1);
88 }
89 } else {
90 $this->writeFilter();
91 $this->setTitleQuery('');
92 $this->getADT()->setTargetRefId(null);
93 }
94 return true;
95 }
96
104 public function getSQLCondition(string $a_element_id, int $mode = self::SQL_LIKE, array $quotedWords = []): string
105 {
106 $a_value = '';
107 if (!$quotedWords) {
108 if ($this->isNull() || !$this->isValid()) {
109 return '';
110 }
111 $a_value = $this->getADT()->getTargetRefId();
112 } elseif (count($quotedWords)) {
113 $a_value = $quotedWords[0];
114 }
115 if (!strlen($a_value)) {
116 return '';
117 }
118
119 $subselect = $a_element_id . ' IN ' .
120 '( select ref_id from object_reference obr join object_data obd on obr.obj_id = obd.obj_id ' .
121 'where ' . $this->db->like('title', 'text', $a_value . '%') . ' ' .
122 ')';
123 return $subselect;
124 }
125
131 public function isInCondition(ilADT $a_adt): bool
132 {
133 if ($this->getADT()->getCopyOfDefinition()->isComparableTo($a_adt)) {
134 $ref_id = $a_adt->getTargetRefId();
135 $title = strtolower(trim(
137 ));
138 $query = strtolower(trim($this->getTitleQuery()));
139 return str_contains($title, $query);
140 }
141 return false;
142 }
143
148 public function getSerializedValue(): string
149 {
150 if (!$this->isNull() && $this->isValid()) {
151 return serialize(array($this->getADT()->getTargetRefId()));
152 }
153 return '';
154 }
155
160 public function setSerializedValue(string $a_value): void
161 {
162 $a_value = unserialize($a_value);
163 if (is_array($a_value)) {
164 $this->getADT()->setTargetRefId($a_value[0]);
165 }
166 }
167}
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:26
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
This class represents a text property in a property form.
$ref_id
Definition: ltiauth.php:66
$post
Definition: ltitoken.php:46