ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilADTMultiEnum.php
Go to the documentation of this file.
1 <?php
2 
3 abstract 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 addSelection(int $value_index)
33  {
34  if (!$this->isValidOption($value_index)) {
35  return;
36  }
37  $this->values[] = $value_index;
38  }
39 
40 
41  public function setSelections(array $a_values = null)
42  {
43  if ($a_values === null) {
44  return;
45  }
46  $checked_values = [];
47  foreach ($a_values as $value_index) {
48  $clean_value = $this->handleSelectionValue($value_index);
49  if ($this->isValidOption($clean_value)) {
50  $checked_values[] = (int) $clean_value;
51  }
52  }
53  $this->values = count($checked_values) ? $checked_values : null;
54  }
55 
56  public function getSelections()
57  {
58  return $this->values;
59  }
60 
61  public function isValidOption($a_value)
62  {
63  $a_value = $this->handleSelectionValue($a_value);
64  return array_key_exists($a_value, $this->getDefinition()->getOptions());
65  }
66 
67 
68  // comparison
69 
70  public function equals(ilADT $a_adt)
71  {
72  if ($this->getDefinition()->isComparableTo($a_adt)) {
73  return ($this->getCheckSum() === $a_adt->getCheckSum());
74  }
75  }
76 
77  public function isLarger(ilADT $a_adt)
78  {
79  // return null?
80  }
81 
82  public function isSmaller(ilADT $a_adt)
83  {
84  // return null?
85  }
86 
87 
88  // null
89 
90  public function isNull()
91  {
92  return ($this->getSelections() === null);
93  }
94 
95 
96  // check
97 
98  public function getCheckSum()
99  {
100  if (!$this->isNull()) {
101  $current = $this->getSelections();
102  sort($current);
103  return md5(implode(",", $current));
104  }
105  }
106 
107 
108  // stdClass
109 
110  public function exportStdClass()
111  {
112  if (!$this->isNull()) {
113  $obj = new stdClass();
114  $obj->value = $this->getSelections();
115  return $obj;
116  }
117  }
118 
119  public function importStdClass($a_std)
120  {
121  if (is_object($a_std)) {
122  $this->setSelections($a_std->value);
123  }
124  }
125 }
equals(ilADT $a_adt)
addSelection(int $value_index)
setSelections(array $a_values=null)
isSmaller(ilADT $a_adt)
ADT base class.
Definition: class.ilADT.php:11
isLarger(ilADT $a_adt)
handleSelectionValue($a_value)
getCheckSum()
Get unique checksum.
isValidDefinition(ilADTDefinition $a_def)
ADT definition base class.
getDefinition()
Get definition.
Definition: class.ilADT.php:97