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