ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilADTInteger.php
Go to the documentation of this file.
1<?php
2
3class ilADTInteger extends ilADT
4{
5 protected $value; // [int]
6
7
8 // definition
9
10 protected function isValidDefinition(ilADTDefinition $a_def)
11 {
12 return ($a_def instanceof ilADTIntegerDefinition);
13 }
14
15 public function reset()
16 {
17 parent::reset();
18
19 $this->value = null;
20 }
21
22
23 // properties
24
25 public function setNumber($a_value = null)
26 {
27 $this->value = $this->getDefinition()->handleNumber($a_value);
28 }
29
30 public function getNumber()
31 {
32 return $this->value;
33 }
34
35
36 // comparison
37
38 public function equals(ilADT $a_adt)
39 {
40 if ($this->getDefinition()->isComparableTo($a_adt)) {
41 return ($this->getNumber() == $a_adt->getNumber());
42 }
43 }
44
45 public function isLarger(ilADT $a_adt)
46 {
47 if ($this->getDefinition()->isComparableTo($a_adt)) {
48 return ($this->getNumber() > $a_adt->getNumber());
49 }
50 }
51
52 public function isSmaller(ilADT $a_adt)
53 {
54 if ($this->getDefinition()->isComparableTo($a_adt)) {
55 return ($this->getNumber() < $a_adt->getNumber());
56 }
57 }
58
59
60 // null
61
62 public function isNull()
63 {
64 return ($this->getNumber() === null);
65 }
66
67
68 // validation
69
70 public function isValid()
71 {
72 $valid = parent::isValid();
73
74 $num = $this->getNumber();
75 if ($num !== null) {
76 $min = $this->getDefinition()->getMin();
77 if ($min !== null && $num < $min) {
78 $this->addValidationError(self::ADT_VALIDATION_ERROR_MIN);
79 $valid = false;
80 }
81
82 $max = $this->getDefinition()->getMax();
83 if ($max !== null && $num > $max) {
84 $this->addValidationError(self::ADT_VALIDATION_ERROR_MAX);
85 $valid = false;
86 }
87 }
88
89 return $valid;
90 }
91
92
93 // check
94
95 public function getCheckSum()
96 {
97 if (!$this->isNull()) {
98 return (string) $this->getNumber();
99 }
100 }
101}
An exception for terminatinating execution or to throw for unit testing.
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.
getCheckSum()
Get unique checksum.
isValid()
Is currently valid.
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($a_error_code)
Add validation error code.
getDefinition()
Get definition.
Definition: class.ilADT.php:97
$valid