ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilADTEnumSearchBridgeSingle.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 {
7  public const ENUM_SEARCH_COLUMN = 'value_index';
8 
9  protected function isValidADTDefinition(ilADTDefinition $a_adt_def): bool
10  {
11  return ($a_adt_def instanceof ilADTEnumDefinition);
12  }
13 
14  // table2gui / filter
15 
16  public function loadFilter(): void
17  {
18  $value = $this->readFilter();
19  if ($value !== null) {
20  $this->getADT()->setSelection($value);
21  }
22  }
23 
24  public function getSearchColumn(): string
25  {
26  return self::ENUM_SEARCH_COLUMN;
27  }
28 
29  // form
30 
31  public function addToForm(): void
32  {
33  $def = $this->getADT()->getCopyOfDefinition();
34 
35  $options = $def->getOptions();
36 
37  $this->lng->loadLanguageModule("search");
38  $options = array("" => $this->lng->txt("search_any")) + $options;
39 
40  $select = new ilSelectInputGUI($this->getTitle(), $this->getElementId());
41  $select->setOptions($options);
42 
43  $select->setValue($this->getADT()->getSelection());
44 
45  $this->addToParentElement($select);
46  }
47 
48  public function importFromPost(array $a_post = null): bool
49  {
50  $post = $this->extractPostValues($a_post);
51  if (
52  is_numeric($post) &&
54  ) {
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 
63  $this->getADT()->setSelection($post);
64  } else {
65  $this->writeFilter();
66  $this->getADT()->setSelection();
67  }
68  return true;
69  }
70 
71  // db
72 
73  public function getSQLCondition(string $a_element_id, int $mode = self::SQL_LIKE, array $quotedWords = []): string
74  {
75  $search_column = $this->getSearchColumn();
76  if (!$this->isNull() && $this->isValid()) {
77  return $search_column . ' = ' . $this->db->quote($this->getADT()->getSelection(), ilDBConstants::T_TEXT);
78  }
79  return '';
80  }
81 
82  public function isInCondition(ilADT $a_adt): bool
83  {
84  assert($a_adt instanceof ilADTEnum);
85 
86  return $this->getADT()->equals($a_adt);
87  }
88 
89  // import/export
90 
91  public function getSerializedValue(): string
92  {
93  if (!$this->isNull() && $this->isValid()) {
94  return serialize(array($this->getADT()->getSelection()));
95  }
96  return '';
97  }
98 
99  public function setSerializedValue(string $a_value): void
100  {
101  $a_value = unserialize($a_value);
102  if (is_array($a_value) && !empty($a_value)) {
103  $this->getADT()->setSelection($a_value[0]);
104  }
105  }
106 }
This class represents a selection list property in a property form.
ADT base class.
Definition: class.ilADT.php:11
extractPostValues(array $a_post=null)
Extract data from (post) values.
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
readFilter()
Load value(s) from filter store (in session)
Class ilADTSearchBridgeSingle.
getSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
isValidADTDefinition(ilADTDefinition $a_adt_def)
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.