ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTFloatSearchBridgeSingle.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected function isValidADTDefinition(ilADTDefinition $a_adt_def): bool
24 {
25 return ($a_adt_def instanceof ilADTFloatDefinition);
26 }
27
28 // table2gui / filter
29
30 public function loadFilter(): void
31 {
32 $value = $this->readFilter();
33 if ($value !== null) {
34 $this->getADT()->setNumber($value);
35 }
36 }
37
38 // form
39
40 public function addToForm(): void
41 {
42 $def = $this->getADT()->getCopyOfDefinition();
43
44 $number = new ilNumberInputGUI($this->getTitle(), $this->getElementId());
45 $number->setSize(10);
46 $number->setDecimals($def->getDecimals());
47
48 $min = $def->getMin();
49 if ($min !== null) {
50 $number->setMinValue($min);
51 }
52 $max = $def->getMax();
53 if ($max !== null) {
54 $number->setMaxValue($max);
55
56 $length = strlen((string) $max);
57 $number->setSize($length);
58 $number->setMaxLength($length);
59 }
60 $number->setValue((string) $this->getADT()->getNumber());
61 $this->addToParentElement($number);
62 }
63
64 public function importFromPost(?array $a_post = null): bool
65 {
66 $post = $this->extractPostValues($a_post);
67
68 if ($post && $this->shouldBeImportedFromPost($post)) {
69 $item = $this->getForm()->getItemByPostVar($this->getElementId());
70 $item->setValue($post);
71
72 $this->getADT()->setNumber($post);
73 } else {
74 $this->getADT()->setNumber();
75 }
76 return true;
77 }
78
79 // db
80
81 public function getSQLCondition(string $a_element_id, int $mode = self::SQL_LIKE, array $quotedWords = []): string
82 {
83 if (!$this->isNull() && $this->isValid()) {
84 return $a_element_id . " = " . $this->db->quote($this->getADT()->getNumber(), "float");
85 }
86 return '';
87 }
88
89 public function isInCondition(ilADT $a_adt): bool
90 {
91 if ($this->getADT()->getCopyOfDefinition()->isComparableTo($a_adt)) {
92 return $this->getADT()->equals($a_adt);
93 }
94 return false;
95 }
96
97 // import/export
98
99 public function getSerializedValue(): string
100 {
101 if (!$this->isNull() && $this->isValid()) {
102 return serialize(array($this->getADT()->getNumber()));
103 }
104 return '';
105 }
106
107 public function setSerializedValue(string $a_value): void
108 {
109 $a_value = unserialize($a_value);
110 if (is_array($a_value)) {
111 $this->getADT()->setNumber($a_value[0]);
112 }
113 }
114}
ADT definition base class.
addToForm()
Add ADT-specific fields to form.
isValidADTDefinition(ilADTDefinition $a_adt_def)
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
loadFilter()
Load filter value(s) into ADT.
isInCondition(ilADT $a_adt)
Compare directly against ADT.
getSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
Get SQL condition for current value(s)
setSerializedValue(string $a_value)
Set current value(s) in serialized form (for easy persisting)
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.
ADT base class.
Definition: class.ilADT.php:26
This class represents a number property in a property form.
$post
Definition: ltitoken.php:46