ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTEnum.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21abstract class ilADTEnum extends ilADT
22{
26 protected $value;
27
28 protected function isValidDefinition(ilADTDefinition $a_def): bool
29 {
30 return ($a_def instanceof ilADTEnumDefinition);
31 }
32
33 public function reset(): void
34 {
35 parent::reset();
36 $this->value = null;
37 }
38
39 // properties
40
45 abstract protected function handleSelectionValue($a_value);
46
47 public function setSelection($a_value = null)
48 {
49 if ($a_value !== null) {
50 $a_value = $this->handleSelectionValue($a_value);
51 if (!$this->isValidOption($a_value)) {
52 $a_value = null;
53 }
54 }
55 $this->value = $a_value;
56 }
57
61 public function getSelection()
62 {
63 return $this->value;
64 }
65
66 public function isValidOption($a_value): bool
67 {
68 $a_value = $this->handleSelectionValue($a_value);
69 return array_key_exists($a_value, $this->getDefinition()->getOptions());
70 }
71
72 // comparison
73
74 public function equals(ilADT $a_adt): ?bool
75 {
76 if ($this->getDefinition()->isComparableTo($a_adt)) {
77 return ($this->getSelection() === $a_adt->getSelection());
78 }
79 return null;
80 }
81
82 public function isLarger(ilADT $a_adt): ?bool
83 {
84 return null;
85 }
86
87 public function isSmaller(ilADT $a_adt): ?bool
88 {
89 return null;
90 }
91
92 // null
93
94 public function isNull(): bool
95 {
96 return $this->getSelection() === null;
97 }
98
99 // check
100
101 public function getCheckSum(): ?string
102 {
103 if (!$this->isNull()) {
104 return (string) $this->getSelection();
105 }
106 return null;
107 }
108
109 // stdClass
110
111 public function exportStdClass(): ?stdClass
112 {
113 if (!$this->isNull()) {
114 $obj = new stdClass();
115 $obj->value = $this->getSelection();
116 return $obj;
117 }
118 return null;
119 }
120
121 public function importStdClass(?stdClass $a_std): void
122 {
123 if (is_object($a_std)) {
124 $this->setSelection($a_std->value);
125 }
126 }
127}
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.
importStdClass(?stdClass $a_std)
Import value from stdClass.
handleSelectionValue($a_value)
isSmaller(ilADT $a_adt)
Check if given ADT is smaller than self.
reset()
Init property defaults.
getCheckSum()
Get unique checksum.
exportStdClass()
Export value as stdClass.
setSelection($a_value=null)
equals(ilADT $a_adt)
Check if given ADT equals self.
ADT base class.
Definition: class.ilADT.php:26
getDefinition()
Get definition.