ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTGroup.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21class ilADTGroup extends ilADT
22{
23 protected array $elements = [];
24
25 public function __clone()
26 {
27 if (is_array($this->elements)) {
28 foreach ($this->elements as $id => $element) {
29 $this->elements[$id] = clone $element;
30 }
31 }
32 }
33
34 protected function isValidDefinition(ilADTDefinition $a_def): bool
35 {
36 return ($a_def instanceof ilADTGroupDefinition);
37 }
38
39 protected function setDefinition(ilADTDefinition $a_def): void
40 {
41 parent::setDefinition($a_def);
42
43 $this->elements = array();
44
45 foreach ($this->getDefinition()->getElements() as $name => $def) {
46 $this->addElement((string) $name, $def);
47 }
48 }
49
50 public function reset(): void
51 {
52 parent::reset();
53
54 $elements = $this->getElements();
55 if (is_array($elements)) {
56 foreach ($elements as $element) {
57 $element->reset();
58 }
59 }
60 }
61
62 protected function addElement(string $a_name, ilADTDefinition $a_def): void
63 {
64 $this->elements[$a_name] = ilADTFactory::getInstance()->getInstanceByDefinition($a_def);
65 }
66
67 public function hasElement(string $a_name): bool
68 {
69 return array_key_exists($a_name, $this->elements);
70 }
71
72 public function getElement(string $a_name): ?ilADT
73 {
74 if ($this->hasElement($a_name)) {
75 return $this->elements[$a_name];
76 }
77 return null;
78 }
79
80 public function getElements(): array
81 {
82 return $this->elements;
83 }
84
85 public function equals(ilADT $a_adt): ?bool
86 {
87 if ($this->getDefinition()->isComparableTo($a_adt)) {
88 return ($this->getCheckSum() == $a_adt->getCheckSum());
89 }
90 return null;
91 }
92
93 public function isLarger(ilADT $a_adt): ?bool
94 {
95 return null;
96 }
97
98 public function isSmaller(ilADT $a_adt): ?bool
99 {
100 return null;
101 }
102
103 // null
104
105 public function isNull(): bool
106 {
107 return !count($this->getElements());
108 }
109
110 public function getValidationErrorsByElements(): array
111 {
113 }
114
118 public function getValidationErrors(): array
119 {
120 return array_keys($this->validation_errors);
121 }
122
123 protected function addElementValidationError(string $a_element_id, string $a_error_code): void
124 {
125 $this->validation_errors[$a_error_code] = $a_element_id;
126 }
127
128 public function isValid(): bool
129 {
130 $valid = parent::isValid();
131 if (!$this->isNull()) {
132 foreach ($this->getElements() as $element_id => $element) {
133 if (!$element->isValid()) {
134 foreach ($element->getValidationErrors() as $error) {
135 $this->addElementValidationError((string) $element_id, $error);
136 }
137 $valid = false;
138 }
139 }
140 }
141 return $valid;
142 }
143
147 public function translateErrorCode(string $a_code): string
148 {
149 if (isset($this->validation_errors[$a_code])) {
150 $element_id = $this->validation_errors[$a_code];
151 $element = $this->getElement($element_id);
152 if ($element) {
153 return $element->translateErrorCode($a_code);
154 }
155 }
156 return parent::translateErrorCode($a_code);
157 }
158
159 public function getCheckSum(): ?string
160 {
161 if (!$this->isNull()) {
162 $tmp = [];
163 foreach ($this->getElements() as $element) {
164 $tmp[] = $element->getCheckSum();
165 }
166 return md5(implode(",", $tmp));
167 }
168 return null;
169 }
170
171 public function exportStdClass(): ?stdClass
172 {
173 $obj = new stdClass();
174 foreach ($this->getElements() as $id => $element) {
175 $obj->$id = $element->exportStdClass();
176 }
177 return $obj;
178 }
179
180 public function importStdClass(?stdClass $a_std): void
181 {
182 if (is_object($a_std)) {
183 foreach ($this->getElements() as $id => $element) {
184 $element->importStdClass($a_std->$id);
185 }
186 }
187 }
188}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
ADT definition base class.
isLarger(ilADT $a_adt)
Check if given ADT is larger than self.
getCheckSum()
Get unique checksum.
isValidDefinition(ilADTDefinition $a_def)
Check if definition is valid for ADT.
translateErrorCode(string $a_code)
@inheritcoc
isSmaller(ilADT $a_adt)
Check if given ADT is smaller than self.
importStdClass(?stdClass $a_std)
Import value from stdClass.
getValidationErrorsByElements()
getElement(string $a_name)
addElementValidationError(string $a_element_id, string $a_error_code)
isNull()
Is currently null.
equals(ilADT $a_adt)
Check if given ADT equals self.
reset()
Init property defaults.
exportStdClass()
Export value as stdClass.
setDefinition(ilADTDefinition $a_def)
Set definition.
getValidationErrors()
@inheritcoc
hasElement(string $a_name)
addElement(string $a_name, ilADTDefinition $a_def)
ADT base class.
Definition: class.ilADT.php:26
array $validation_errors
Definition: class.ilADT.php:31
getCheckSum()
Get unique checksum.
getDefinition()
Get definition.
$valid