ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilADTEnumSearchBridgeSingle.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  public const ENUM_SEARCH_COLUMN = 'value_index';
24 
25  protected function isValidADTDefinition(ilADTDefinition $a_adt_def): bool
26  {
27  return ($a_adt_def instanceof ilADTEnumDefinition);
28  }
29 
30  // table2gui / filter
31 
32  public function loadFilter(): void
33  {
34  $value = $this->readFilter();
35  if ($value !== null) {
36  $this->getADT()->setSelection($value);
37  }
38  }
39 
40  public function getSearchColumn(): string
41  {
42  return self::ENUM_SEARCH_COLUMN;
43  }
44 
45  // form
46 
47  public function addToForm(): void
48  {
49  $def = $this->getADT()->getCopyOfDefinition();
50 
51  $options = $def->getOptions();
52 
53  $this->lng->loadLanguageModule("search");
54  $options = array("" => $this->lng->txt("search_any")) + $options;
55 
56  $select = new ilSelectInputGUI($this->getTitle(), $this->getElementId());
57  $select->setOptions($options);
58 
59  $select->setValue($this->getADT()->getSelection());
60 
61  $this->addToParentElement($select);
62  }
63 
64  public function importFromPost(?array $a_post = null): bool
65  {
66  $post = $this->extractPostValues($a_post);
67  if (
68  is_numeric($post) &&
70  ) {
71  if ($this->getForm() instanceof ilPropertyFormGUI) {
72  $item = $this->getForm()->getItemByPostVar($this->getElementId());
73  $item->setValue($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  }
78 
79  $this->getADT()->setSelection($post);
80  } else {
81  $this->writeFilter();
82  $this->getADT()->setSelection();
83  }
84  return true;
85  }
86 
87  // db
88 
89  public function getSQLCondition(string $a_element_id, int $mode = self::SQL_LIKE, array $quotedWords = []): string
90  {
91  $search_column = $this->getSearchColumn();
92  if (!$this->isNull() && $this->isValid()) {
93  return $search_column . ' = ' . $this->db->quote($this->getADT()->getSelection(), ilDBConstants::T_TEXT);
94  }
95  return '';
96  }
97 
98  public function isInCondition(ilADT $a_adt): bool
99  {
100  assert($a_adt instanceof ilADTEnum);
101 
102  return $this->getADT()->equals($a_adt);
103  }
104 
105  // import/export
106 
107  public function getSerializedValue(): string
108  {
109  if (!$this->isNull() && $this->isValid()) {
110  return serialize(array($this->getADT()->getSelection()));
111  }
112  return '';
113  }
114 
115  public function setSerializedValue(string $a_value): void
116  {
117  $a_value = unserialize($a_value);
118  if (is_array($a_value) && !empty($a_value)) {
119  $this->getADT()->setSelection($a_value[0]);
120  }
121  }
122 }
This class represents a selection list property in a property form.
ADT base class.
Definition: class.ilADT.php:25
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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=[])
extractPostValues(?array $a_post=null)
Extract data from (post) values.
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.