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