ILIAS  release_8 Revision v8.24
class.ilADTFloatSearchBridgeSingle.php
Go to the documentation of this file.
1<?php
2
3declare(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 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:12
This class represents a number property in a property form.
$post
Definition: ltitoken.php:49