ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilADTEnum.php
Go to the documentation of this file.
1<?php
2
3abstract class ilADTEnum extends ilADT
4{
5 protected $value; // [string]
6
7
8 // definition
9
10 protected function isValidDefinition(ilADTDefinition $a_def)
11 {
12 return ($a_def instanceof ilADTEnumDefinition);
13 }
14
15 public function reset()
16 {
17 parent::reset();
18
19 $this->value = null;
20 }
21
22
23 // properties
24
25 abstract protected function handleSelectionValue($a_value);
26
27 public function setSelection($a_value = null)
28 {
29 if ($a_value !== null) {
30 $a_value = $this->handleSelectionValue($a_value);
31 if (!$this->isValidOption($a_value)) {
32 $a_value = null;
33 }
34 }
35 $this->value = $a_value;
36 }
37
38 public function getSelection()
39 {
40 return $this->value;
41 }
42
43 public function isValidOption($a_value)
44 {
45 $a_value = $this->handleSelectionValue($a_value);
46 return array_key_exists($a_value, $this->getDefinition()->getOptions());
47 }
48
49
50 // comparison
51
52 public function equals(ilADT $a_adt)
53 {
54 if ($this->getDefinition()->isComparableTo($a_adt)) {
55 return ($this->getSelection() === $a_adt->getSelection());
56 }
57 }
58
59 public function isLarger(ilADT $a_adt)
60 {
61 // return null?
62 }
63
64 public function isSmaller(ilADT $a_adt)
65 {
66 // return null?
67 }
68
69
70 // null
71
72 public function isNull()
73 {
74 return ($this->getSelection() === null);
75 }
76
77
78 // check
79
80 public function getCheckSum()
81 {
82 if (!$this->isNull()) {
83 return (string) $this->getSelection();
84 }
85 }
86}
An exception for terminatinating execution or to throw for unit testing.
ADT definition base class.
isLarger(ilADT $a_adt)
Check if given ADT is larger than self.
isValidOption($a_value)
isValidDefinition(ilADTDefinition $a_def)
Check if definition is valid for ADT.
isNull()
Is currently null.
handleSelectionValue($a_value)
isSmaller(ilADT $a_adt)
Check if given ADT is smaller than self.
reset()
Init property defaults.
getCheckSum()
Get unique checksum.
setSelection($a_value=null)
equals(ilADT $a_adt)
Check if given ADT equals self.
ADT base class.
Definition: class.ilADT.php:12
getDefinition()
Get definition.
Definition: class.ilADT.php:97