ILIAS  release_8 Revision v8.24
class.ilADTEnumDefinition.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6{
7 protected array $options = [];
8 protected bool $numeric; // [bool]
9
10 public function getType(): string
11 {
12 return "Enum";
13 }
14
15 // default
16
17 public function reset(): void
18 {
19 parent::reset();
20
21 $this->options = array();
22 $this->setNumeric(true);
23 }
24
25 // properties
26
27 public function isNumeric(): bool
28 {
29 return $this->numeric;
30 }
31
32 public function setNumeric(bool $a_value): void
33 {
34 $this->numeric = $a_value;
35 }
36
37 public function getOptions(): array
38 {
39 return $this->options;
40 }
41
42 public function setOptions(array $a_values)
43 {
44 if ($this->isNumeric()) {
45 foreach (array_keys($a_values) as $key) {
46 if (!is_numeric($key)) {
47 throw new Exception("ilADTEnum was expecting numeric option keys");
48 }
49 }
50 }
51
52 $this->options = $a_values;
53 }
54
55 // comparison
56
57 public function isComparableTo(ilADT $a_adt): bool
58 {
59 // has to be enum-based
60 return ($a_adt instanceof ilADTEnum);
61 }
62
63 public function getADTInstance(): ilADTEnum
64 {
65 if ($this->isNumeric()) {
66 $class = "ilADTEnumNumeric";
67 } else {
68 $class = "ilADTEnumText";
69 }
70 return new $class($this);
71 }
72}
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:12
string $key
Consumer key/client ID value.
Definition: System.php:193