ILIAS  release_8 Revision v8.24
class.ilADTEnum.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5abstract class ilADTEnum extends ilADT
6{
10 protected $value;
11
12 protected function isValidDefinition(ilADTDefinition $a_def): bool
13 {
14 return ($a_def instanceof ilADTEnumDefinition);
15 }
16
17 public function reset(): void
18 {
19 parent::reset();
20 $this->value = null;
21 }
22
23 // properties
24
29 abstract protected function handleSelectionValue($a_value);
30
31 public function setSelection($a_value = null)
32 {
33 if ($a_value !== null) {
34 $a_value = $this->handleSelectionValue($a_value);
35 if (!$this->isValidOption($a_value)) {
36 $a_value = null;
37 }
38 }
39 $this->value = $a_value;
40 }
41
45 public function getSelection()
46 {
47 return $this->value;
48 }
49
50 public function isValidOption($a_value): bool
51 {
52 $a_value = $this->handleSelectionValue($a_value);
53 return array_key_exists($a_value, $this->getDefinition()->getOptions());
54 }
55
56 // comparison
57
58 public function equals(ilADT $a_adt): ?bool
59 {
60 if ($this->getDefinition()->isComparableTo($a_adt)) {
61 return ($this->getSelection() === $a_adt->getSelection());
62 }
63 return null;
64 }
65
66 public function isLarger(ilADT $a_adt): ?bool
67 {
68 return null;
69 }
70
71 public function isSmaller(ilADT $a_adt): ?bool
72 {
73 return null;
74 }
75
76 // null
77
78 public function isNull(): bool
79 {
80 return $this->getSelection() === null;
81 }
82
83 // check
84
85 public function getCheckSum(): ?string
86 {
87 if (!$this->isNull()) {
88 return (string) $this->getSelection();
89 }
90 return null;
91 }
92
93 // stdClass
94
95 public function exportStdClass(): ?stdClass
96 {
97 if (!$this->isNull()) {
98 $obj = new stdClass();
99 $obj->value = $this->getSelection();
100 return $obj;
101 }
102 return null;
103 }
104
105 public function importStdClass(?stdClass $a_std): void
106 {
107 if (is_object($a_std)) {
108 $this->setSelection($a_std->value);
109 }
110 }
111}
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:12
getDefinition()
Get definition.
Definition: class.ilADT.php:92