ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilADTInternalLinkSearchBridgeSingle.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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());
58  $this->addToParentElement($title);
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 base class.
Definition: class.ilADT.php:25
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
$ref_id
Definition: ltiauth.php:65
static _lookupTitle(int $obj_id)
readFilter()
Load value(s) from filter store (in session)
Class ilADTSearchBridgeSingle.
setSerializedValue(string $a_value)
Set serialized value.
getSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
Get sql condition.
isValidADTDefinition(\ilADTDefinition $a_adt_def)
Is valid type.
extractPostValues(?array $a_post=null)
Extract data from (post) values.
writeFilter($a_value=null)
Write value(s) to filter store (in session)
$post
Definition: ltitoken.php:46
ADT definition base class.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.