ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
11 foreach($this->elements as $id => $element)
12 {
13 $this->elements[$id] = clone $element;
14 }
15 }
16 }
17
18
19 // definition
20
21 protected function isValidDefinition(ilADTDefinition $a_def)
22 {
23 return ($a_def instanceof ilADTGroupDefinition);
24 }
25
26 protected function setDefinition(ilADTDefinition $a_def)
27 {
28 parent::setDefinition($a_def);
29
30 $this->elements = array();
31
32 foreach($this->getDefinition()->getElements() as $name => $def)
33 {
34 $this->addElement($name, $def);
35 }
36 }
37
38
39 // defaults
40
41 public function reset()
42 {
43 parent::reset();
44
45 $elements = $this->getElements();
46 if(is_array($elements))
47 {
48 foreach($elements as $element)
49 {
50 $element->reset();
51 }
52 }
53 }
54
55
56 // properties
57
58 protected function addElement($a_name, ilADTDefinition $a_def)
59 {
60 $this->elements[$a_name] = ilADTFactory::getInstance()->getInstanceByDefinition($a_def);
61 }
62
63 public function hasElement($a_name)
64 {
65 return array_key_exists($a_name, $this->elements);
66 }
67
68 public function getElement($a_name)
69 {
70 if($this->hasElement($a_name))
71 {
72 return $this->elements[$a_name];
73 }
74 }
75
76 public function getElements()
77 {
78 return $this->elements;
79 }
80
81
82
83 // comparison
84
85 public function equals(ilADT $a_adt)
86 {
87 if($this->getDefinition()->isComparableTo($a_adt))
88 {
89 return ($this->getCheckSum() == $a_adt->getCheckSum());
90 }
91 }
92
93 public function isLarger(ilADT $a_adt)
94 {
95 // return null?
96 }
97
98 public function isSmaller(ilADT $a_adt)
99 {
100 // return null?
101 }
102
103
104 // null
105
106 public function isNull()
107 {
108 return !sizeof($this->getElements());
109 }
110
111
112 // validation
113
115 {
116 return (array)$this->validation_errors;
117 }
118
119 public function getValidationErrors()
120 {
121 return array_keys((array)$this->validation_errors);
122 }
123
124 protected function addValidationError($a_element_id, $a_error_code)
125 {
126 $this->validation_errors[(string)$a_error_code] = $a_element_id;
127 }
128
129 public function isValid()
130 {
131 $valid = parent::isValid();
132
133 if(!$this->isNull())
134 {
135 foreach($this->getElements() as $element_id => $element)
136 {
137 if(!$element->isValid())
138 {
139 foreach($element->getValidationErrors() as $error)
140 {
141 $this->addValidationError($element_id, $error);
142 }
143 $valid = false;
144 }
145 }
146 }
147
148 return $valid;
149 }
150
151 public function translateErrorCode($a_code)
152 {
153 if(isset($this->validation_errors[$a_code]))
154 {
155 $element_id = $this->validation_errors[$a_code];
156 $element = $this->getElement($element_id);
157 if($element)
158 {
159 return $element->translateErrorCode($a_code);
160 }
161 }
162 }
163
164
165 // check
166
167 public function getCheckSum()
168 {
169 if(!$this->isNull())
170 {
171 $tmp = array();
172 foreach($this->getElements() as $element)
173 {
174 $tmp[] = $element->getCheckSum();
175 }
176 return md5(implode(",", $tmp));
177 }
178 }
179}
180
181?>
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.
addValidationError($a_element_id, $a_error_code)
isSmaller(ilADT $a_adt)
Check if given ADT is smaller than self.
getValidationErrorsByElements()
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:99
$valid