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