ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTEnumDefinition.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected array $options = [];
24 protected bool $numeric; // [bool]
25
26 public function getType(): string
27 {
28 return "Enum";
29 }
30
31 // default
32
33 public function reset(): void
34 {
35 parent::reset();
36
37 $this->options = array();
38 $this->setNumeric(true);
39 }
40
41 // properties
42
43 public function isNumeric(): bool
44 {
45 return $this->numeric;
46 }
47
48 public function setNumeric(bool $a_value): void
49 {
50 $this->numeric = $a_value;
51 }
52
53 public function getOptions(): array
54 {
55 return $this->options;
56 }
57
58 public function setOptions(array $a_values)
59 {
60 if ($this->isNumeric()) {
61 foreach (array_keys($a_values) as $key) {
62 if (!is_numeric($key)) {
63 throw new Exception("ilADTEnum was expecting numeric option keys");
64 }
65 }
66 }
67
68 $this->options = $a_values;
69 }
70
71 // comparison
72
73 public function isComparableTo(ilADT $a_adt): bool
74 {
75 // has to be enum-based
76 return ($a_adt instanceof ilADTEnum);
77 }
78
79 public function getADTInstance(): ilADTEnum
80 {
81 if ($this->isNumeric()) {
82 $class = "ilADTEnumNumeric";
83 } else {
84 $class = "ilADTEnumText";
85 }
86 return new $class($this);
87 }
88}
ADT definition base class.
isComparableTo(ilADT $a_adt)
Check if given ADT is comparable to self.
reset()
Init property defaults.
getType()
Get type (from class/instance)
ADT base class.
Definition: class.ilADT.php:26