ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilADTFloatSearchBridgeSingle.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 {
7  protected function isValidADTDefinition(ilADTDefinition $a_adt_def): bool
8  {
9  return ($a_adt_def instanceof ilADTFloatDefinition);
10  }
11 
12  // table2gui / filter
13 
14  public function loadFilter(): void
15  {
16  $value = $this->readFilter();
17  if ($value !== null) {
18  $this->getADT()->setNumber($value);
19  }
20  }
21 
22  // form
23 
24  public function addToForm(): void
25  {
26  $def = $this->getADT()->getCopyOfDefinition();
27 
28  $number = new ilNumberInputGUI($this->getTitle(), $this->getElementId());
29  $number->setSize(10);
30  $number->setDecimals($def->getDecimals());
31 
32  $min = $def->getMin();
33  if ($min !== null) {
34  $number->setMinValue($min);
35  }
36  $max = $def->getMax();
37  if ($max !== null) {
38  $number->setMaxValue($max);
39 
40  $length = strlen((string) $max);
41  $number->setSize($length);
42  $number->setMaxLength($length);
43  }
44  $number->setValue((string) $this->getADT()->getNumber());
45  $this->addToParentElement($number);
46  }
47 
48  public function importFromPost(array $a_post = null): bool
49  {
50  $post = $this->extractPostValues($a_post);
51 
52  if ($post && $this->shouldBeImportedFromPost($post)) {
53  $item = $this->getForm()->getItemByPostVar($this->getElementId());
54  $item->setValue($post);
55 
56  $this->getADT()->setNumber($post);
57  } else {
58  $this->getADT()->setNumber();
59  }
60  return true;
61  }
62 
63  // db
64 
65  public function getSQLCondition(string $a_element_id, int $mode = self::SQL_LIKE, array $quotedWords = []): string
66  {
67  if (!$this->isNull() && $this->isValid()) {
68  return $a_element_id . " = " . $this->db->quote($this->getADT()->getNumber(), "float");
69  }
70  return '';
71  }
72 
73  public function isInCondition(ilADT $a_adt): bool
74  {
75  if ($this->getADT()->getCopyOfDefinition()->isComparableTo($a_adt)) {
76  return $this->getADT()->equals($a_adt);
77  }
78  return false;
79  }
80 
81  // import/export
82 
83  public function getSerializedValue(): string
84  {
85  if (!$this->isNull() && $this->isValid()) {
86  return serialize(array($this->getADT()->getNumber()));
87  }
88  return '';
89  }
90 
91  public function setSerializedValue(string $a_value): void
92  {
93  $a_value = unserialize($a_value);
94  if (is_array($a_value)) {
95  $this->getADT()->setNumber($a_value[0]);
96  }
97  }
98 }
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.
This class represents a number property in a property form.
getSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
$post
Definition: ltitoken.php:49
ADT definition base class.
isValidADTDefinition(ilADTDefinition $a_adt_def)
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.