ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTFloat.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20class ilADTFloat extends ilADT
21{
22 protected ?float $value;
23
24 // definition
25
26 protected function isValidDefinition(ilADTDefinition $a_def): bool
27 {
28 return $a_def instanceof ilADTFloatDefinition;
29 }
30
31 public function reset(): void
32 {
33 parent::reset();
34
35 $this->value = null;
36 }
37
38 // properties
39
40 public function setNumber($a_value = null)
41 {
42 $this->value = $this->getDefinition()->handleNumber($a_value);
43 }
44
45 public function getNumber(): ?float
46 {
47 return $this->value;
48 }
49
50 // comparison
51
52 public function equals(ilADT $a_adt): ?bool
53 {
54 if ($this->getDefinition()->isComparableTo($a_adt)) {
55 return ($this->getNumber() == $a_adt->getNumber());
56 }
57 return null;
58 }
59
60 public function isLarger(ilADT $a_adt): ?bool
61 {
62 if ($this->getDefinition()->isComparableTo($a_adt)) {
63 return ($this->getNumber() > $a_adt->getNumber());
64 }
65 return null;
66 }
67
68 public function isSmaller(ilADT $a_adt): ?bool
69 {
70 if ($this->getDefinition()->isComparableTo($a_adt)) {
71 return ($this->getNumber() < $a_adt->getNumber());
72 }
73 return null;
74 }
75
76 // null
77
78 public function isNull(): bool
79 {
80 return $this->getNumber() === null;
81 }
82
83 public function isValid(): bool
84 {
85 $valid = parent::isValid();
86 $num = $this->getNumber();
87 if ($num !== null) {
88 $min = $this->getDefinition()->getMin();
89 if ($min !== null && $num < $min) {
90 $this->addValidationError(self::ADT_VALIDATION_ERROR_MIN);
91 $valid = false;
92 }
93
94 $max = $this->getDefinition()->getMax();
95 if ($max !== null && $num > $max) {
96 $this->addValidationError(self::ADT_VALIDATION_ERROR_MAX);
97 $valid = false;
98 }
99 }
100 return $valid;
101 }
102
103 public function getCheckSum(): ?string
104 {
105 if (!$this->isNull()) {
106 return (string) $this->getNumber();
107 }
108 return null;
109 }
110
111 // stdClass
112
113 public function exportStdClass(): ?stdClass
114 {
115 if (!$this->isNull()) {
116 $obj = new stdClass();
117 $obj->value = $this->getNumber();
118 return $obj;
119 }
120 return null;
121 }
122
123 public function importStdClass(?stdClass $a_std): void
124 {
125 if (is_object($a_std)) {
126 $this->setNumber($a_std->value);
127 }
128 }
129}
ADT definition base class.
isValidDefinition(ilADTDefinition $a_def)
Check if definition is valid for ADT.
isLarger(ilADT $a_adt)
Check if given ADT is larger than self.
isNull()
Is currently null.
setNumber($a_value=null)
exportStdClass()
Export value as stdClass.
equals(ilADT $a_adt)
Check if given ADT equals self.
getCheckSum()
Get unique checksum.
isSmaller(ilADT $a_adt)
Check if given ADT is smaller than self.
reset()
Init property defaults.
importStdClass(?stdClass $a_std)
Import value from stdClass.
ADT base class.
Definition: class.ilADT.php:26
addValidationError(string $a_error_code)
getDefinition()
Get definition.
$valid