ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilADTGroup.php
Go to the documentation of this file.
1<?php
2
3class ilADTGroup extends ilADT
4{
5 protected $elements; // [array]
6
7 public function __clone()
8 {
9 if (is_array($this->elements)) {
10 foreach ($this->elements as $id => $element) {
11 $this->elements[$id] = clone $element;
12 }
13 }
14 }
15
16
17 // definition
18
19 protected function isValidDefinition(ilADTDefinition $a_def)
20 {
21 return ($a_def instanceof ilADTGroupDefinition);
22 }
23
24 protected function setDefinition(ilADTDefinition $a_def)
25 {
26 parent::setDefinition($a_def);
27
28 $this->elements = array();
29
30 foreach ($this->getDefinition()->getElements() as $name => $def) {
31 $this->addElement($name, $def);
32 }
33 }
34
35
36 // defaults
37
38 public function reset()
39 {
40 parent::reset();
41
42 $elements = $this->getElements();
43 if (is_array($elements)) {
44 foreach ($elements as $element) {
45 $element->reset();
46 }
47 }
48 }
49
50
51 // properties
52
53 protected function addElement($a_name, ilADTDefinition $a_def)
54 {
55 $this->elements[$a_name] = ilADTFactory::getInstance()->getInstanceByDefinition($a_def);
56 }
57
58 public function hasElement($a_name)
59 {
60 return array_key_exists($a_name, $this->elements);
61 }
62
63 public function getElement($a_name)
64 {
65 if ($this->hasElement($a_name)) {
66 return $this->elements[$a_name];
67 }
68 }
69
70 public function getElements()
71 {
72 return $this->elements;
73 }
74
75
76
77 // comparison
78
79 public function equals(ilADT $a_adt)
80 {
81 if ($this->getDefinition()->isComparableTo($a_adt)) {
82 return ($this->getCheckSum() == $a_adt->getCheckSum());
83 }
84 }
85
86 public function isLarger(ilADT $a_adt)
87 {
88 // return null?
89 }
90
91 public function isSmaller(ilADT $a_adt)
92 {
93 // return null?
94 }
95
96
97 // null
98
99 public function isNull()
100 {
101 return !sizeof($this->getElements());
102 }
103
104
105 // validation
106
108 {
109 return (array) $this->validation_errors;
110 }
111
112 public function getValidationErrors()
113 {
114 return array_keys((array) $this->validation_errors);
115 }
116
117 protected function addElementValidationError($a_element_id, $a_error_code)
118 {
119 $this->validation_errors[(string) $a_error_code] = $a_element_id;
120 }
121
122 public function isValid()
123 {
124 $valid = parent::isValid();
125
126 if (!$this->isNull()) {
127 foreach ($this->getElements() as $element_id => $element) {
128 if (!$element->isValid()) {
129 foreach ($element->getValidationErrors() as $error) {
130 $this->addElementValidationError($element_id, $error);
131 }
132 $valid = false;
133 }
134 }
135 }
136
137 return $valid;
138 }
139
140 public function translateErrorCode($a_code)
141 {
142 if (isset($this->validation_errors[$a_code])) {
143 $element_id = $this->validation_errors[$a_code];
144 $element = $this->getElement($element_id);
145 if ($element) {
146 return $element->translateErrorCode($a_code);
147 }
148 }
149 }
150
151
152 // check
153
154 public function getCheckSum()
155 {
156 if (!$this->isNull()) {
157 $tmp = array();
158 foreach ($this->getElements() as $element) {
159 $tmp[] = $element->getCheckSum();
160 }
161 return md5(implode(",", $tmp));
162 }
163 }
164}
An exception for terminatinating execution or to throw for unit testing.
ADT definition base class.
static getInstance()
Get singleton.
isLarger(ilADT $a_adt)
Check if given ADT is larger than self.
addElement($a_name, ilADTDefinition $a_def)
getCheckSum()
Get unique checksum.
getElement($a_name)
isValidDefinition(ilADTDefinition $a_def)
Check if definition is valid for ADT.
isSmaller(ilADT $a_adt)
Check if given ADT is smaller than self.
getValidationErrorsByElements()
addElementValidationError($a_element_id, $a_error_code)
isNull()
Is currently null.
equals(ilADT $a_adt)
Check if given ADT equals self.
isValid()
Is currently valid.
reset()
Init property defaults.
setDefinition(ilADTDefinition $a_def)
Set definition.
translateErrorCode($a_code)
Translate error-code to human-readable message.
getValidationErrors()
Get all validation error codes.
hasElement($a_name)
ADT base class.
Definition: class.ilADT.php:12
$validation_errors
Definition: class.ilADT.php:14
getCheckSum()
Get unique checksum.
getDefinition()
Get definition.
Definition: class.ilADT.php:97
$def
Definition: croninfo.php:21
$valid
if(!array_key_exists('StateId', $_REQUEST)) $id
$error
Definition: Error.php:17
if($format !==null) $name
Definition: metadata.php:146