ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
42 return ($this->getNumber() == $a_adt->getNumber());
43 }
44 }
45
46 public function isLarger(ilADT $a_adt)
47 {
48 if($this->getDefinition()->isComparableTo($a_adt))
49 {
50 return ($this->getNumber() > $a_adt->getNumber());
51 }
52 }
53
54 public function isSmaller(ilADT $a_adt)
55 {
56 if($this->getDefinition()->isComparableTo($a_adt))
57 {
58 return ($this->getNumber() < $a_adt->getNumber());
59 }
60 }
61
62
63 // null
64
65 public function isNull()
66 {
67 return ($this->getNumber() === null);
68 }
69
70
71 // validation
72
73 public function isValid()
74 {
75 $valid = parent::isValid();
76
77 $num = $this->getNumber();
78 if($num !== null)
79 {
80 $min = $this->getDefinition()->getMin();
81 if($min !== null && $num < $min)
82 {
83 $this->addValidationError(self::ADT_VALIDATION_ERROR_MIN);
84 $valid = false;
85 }
86
87 $max = $this->getDefinition()->getMax();
88 if($max !== null && $num > $max)
89 {
90 $this->addValidationError(self::ADT_VALIDATION_ERROR_MAX);
91 $valid = false;
92 }
93 }
94
95 return $valid;
96 }
97
98
99 // check
100
101 public function getCheckSum()
102 {
103 if(!$this->isNull())
104 {
105 return (string)$this->getNumber();
106 }
107 }
108}
109
110?>
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:99
$valid