ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilADTGroup.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 class ilADTGroup extends ilADT
6 {
7  protected array $elements = [];
8 
9  public function __clone()
10  {
11  if (is_array($this->elements)) {
12  foreach ($this->elements as $id => $element) {
13  $this->elements[$id] = clone $element;
14  }
15  }
16  }
17 
18  protected function isValidDefinition(ilADTDefinition $a_def): bool
19  {
20  return ($a_def instanceof ilADTGroupDefinition);
21  }
22 
23  protected function setDefinition(ilADTDefinition $a_def): void
24  {
25  parent::setDefinition($a_def);
26 
27  $this->elements = array();
28 
29  foreach ($this->getDefinition()->getElements() as $name => $def) {
30  $this->addElement((string) $name, $def);
31  }
32  }
33 
34  public function reset(): void
35  {
36  parent::reset();
37 
38  $elements = $this->getElements();
39  if (is_array($elements)) {
40  foreach ($elements as $element) {
41  $element->reset();
42  }
43  }
44  }
45 
46  protected function addElement(string $a_name, ilADTDefinition $a_def): void
47  {
48  $this->elements[$a_name] = ilADTFactory::getInstance()->getInstanceByDefinition($a_def);
49  }
50 
51  public function hasElement(string $a_name): bool
52  {
53  return array_key_exists($a_name, $this->elements);
54  }
55 
56  public function getElement(string $a_name): ?ilADT
57  {
58  if ($this->hasElement($a_name)) {
59  return $this->elements[$a_name];
60  }
61  return null;
62  }
63 
64  public function getElements(): array
65  {
66  return $this->elements;
67  }
68 
69  public function equals(ilADT $a_adt): ?bool
70  {
71  if ($this->getDefinition()->isComparableTo($a_adt)) {
72  return ($this->getCheckSum() == $a_adt->getCheckSum());
73  }
74  return null;
75  }
76 
77  public function isLarger(ilADT $a_adt): ?bool
78  {
79  return null;
80  }
81 
82  public function isSmaller(ilADT $a_adt): ?bool
83  {
84  return null;
85  }
86 
87  // null
88 
89  public function isNull(): bool
90  {
91  return !count($this->getElements());
92  }
93 
94  public function getValidationErrorsByElements(): array
95  {
97  }
98 
102  public function getValidationErrors(): array
103  {
104  return array_keys($this->validation_errors);
105  }
106 
107  protected function addElementValidationError(string $a_element_id, string $a_error_code): void
108  {
109  $this->validation_errors[$a_error_code] = $a_element_id;
110  }
111 
112  public function isValid(): bool
113  {
114  $valid = parent::isValid();
115  if (!$this->isNull()) {
116  foreach ($this->getElements() as $element_id => $element) {
117  if (!$element->isValid()) {
118  foreach ($element->getValidationErrors() as $error) {
119  $this->addElementValidationError((string) $element_id, $error);
120  }
121  $valid = false;
122  }
123  }
124  }
125  return $valid;
126  }
127 
131  public function translateErrorCode(string $a_code): string
132  {
133  if (isset($this->validation_errors[$a_code])) {
134  $element_id = $this->validation_errors[$a_code];
135  $element = $this->getElement($element_id);
136  if ($element) {
137  return $element->translateErrorCode($a_code);
138  }
139  }
140  return parent::translateErrorCode($a_code);
141  }
142 
143  public function getCheckSum(): ?string
144  {
145  if (!$this->isNull()) {
146  $tmp = [];
147  foreach ($this->getElements() as $element) {
148  $tmp[] = $element->getCheckSum();
149  }
150  return md5(implode(",", $tmp));
151  }
152  return null;
153  }
154 
155  public function exportStdClass(): ?stdClass
156  {
157  $obj = new stdClass();
158  foreach ($this->getElements() as $id => $element) {
159  $obj->$id = $element->exportStdClass();
160  }
161  return $obj;
162  }
163 
164  public function importStdClass(?stdClass $a_std): void
165  {
166  if (is_object($a_std)) {
167  foreach ($this->getElements() as $id => $element) {
168  $element->importStdClass($a_std->$id);
169  }
170  }
171  }
172 }
hasElement(string $a_name)
getValidationErrorsByElements()
$valid
isValidDefinition(ilADTDefinition $a_def)
ADT base class.
Definition: class.ilADT.php:11
if($format !==null) $name
Definition: metadata.php:247
addElementValidationError(string $a_element_id, string $a_error_code)
equals(ilADT $a_adt)
array $validation_errors
Definition: class.ilADT.php:17
importStdClass(?stdClass $a_std)
translateErrorCode(string $a_code)
isLarger(ilADT $a_adt)
addElement(string $a_name, ilADTDefinition $a_def)
getCheckSum()
Get unique checksum.
isSmaller(ilADT $a_adt)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setDefinition(ilADTDefinition $a_def)
ADT definition base class.
getElement(string $a_name)
getDefinition()
Get definition.
Definition: class.ilADT.php:92