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