ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilADT.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11abstract class ilADT
12{
13 protected $definition; // [ilADTDefinition]
14 protected $validation_errors = []; // [array]
15
16
17 // :TODO: error codes for ALL types - see self::translateErrorMessage()
18
20
21 // text-based
23
24 // multi
26
27 // number-based
30
31 // date-based
32 const ADT_VALIDATION_DATE = "adt6";
33
34 // invalid target node for internal link
36
42 public function __construct(ilADTDefinition $a_def)
43 {
44 $this->setDefinition($a_def);
45 $this->reset();
46 }
47
53 public function getType()
54 {
55 return $this->getDefinition()->getType();
56 }
57
61 protected function reset()
62 {
63 }
64
65
66 //
67 // definition
68 //
69
75 abstract protected function isValidDefinition(ilADTDefinition $a_def);
76
83 protected function setDefinition(ilADTDefinition $a_def)
84 {
85 if ($this->isValidDefinition($a_def)) {
86 $this->definition = clone $a_def;
87 } else {
88 throw new ilException("ilADT invalid definition");
89 }
90 }
91
97 protected function getDefinition()
98 {
99 return $this->definition;
100 }
101
107 public function getCopyOfDefinition()
108 {
109 return (clone $this->definition);
110 }
111
112
113 //
114 // comparison
115 //
116
123 abstract public function equals(ilADT $a_adt);
124
131 abstract public function isLarger(ilADT $a_adt);
132
139 public function isLargerOrEqual(ilADT $a_adt)
140 {
141 return ($this->equals($a_adt) ||
142 $this->isLarger($a_adt));
143 }
144
151 abstract public function isSmaller(ilADT $a_adt);
152
159 public function isSmallerOrEqual(ilADT $a_adt)
160 {
161 return ($this->equals($a_adt) ||
162 $this->isSmaller($a_adt));
163 }
164
172 public function isInbetween(ilADT $a_adt_from, ilADT $a_adt_to)
173 {
174 return ($this->isLarger($a_adt_from) &&
175 $this->isSmaller($a_adt_to));
176 }
177
185 public function isInbetweenOrEqual(ilADT $a_adt_from, ilADT $a_adt_to)
186 {
187 return ($this->equals($a_adt_from) ||
188 $this->equals($a_adt_to) ||
189 $this->isInbetween($a_adt_from, $a_adt_to));
190 }
191
192
193 //
194 // null
195 //
196
202 abstract public function isNull();
203
204
205 //
206 // validation
207 //
208
214 public function isValid()
215 {
216 $this->validation_errors = array();
217
218 if (!$this->getDefinition()->isNullAllowed() && $this->isNull()) {
219 $this->addValidationError(self::ADT_VALIDATION_ERROR_NULL_NOT_ALLOWED);
220 return false;
221 }
222 return true;
223 }
224
230 protected function addValidationError($a_error_code)
231 {
232 $this->validation_errors[] = (string) $a_error_code;
233 }
234
241 public function getValidationErrors()
242 {
243 if (is_array($this->validation_errors) &&
244 sizeof($this->validation_errors)) {
245 return array_unique($this->validation_errors);
246 }
247 return array();
248 }
249
257 public function translateErrorCode($a_code)
258 {
259 global $DIC;
260
261 $lng = $DIC['lng'];
262
263 // $lng->txt("msg_wrong_format");
264
265 switch ($a_code) {
267 return $lng->txt("msg_input_is_required");
268
270 return $lng->txt("adt_error_max_length");
271
273 return $lng->txt("adt_error_max_size");
274
276 return $lng->txt("form_msg_value_too_low");
277
279 return $lng->txt("form_msg_value_too_high");
280
281 // :TODO: currently not used - see ilDateTimeInputGUI
283 return $lng->txt("exc_date_not_valid");
284
285 default:
286 throw new Exception("ADT unknown error code");
287 }
288 }
289
295 abstract public function getCheckSum();
296
302 abstract public function exportStdClass();
303
309 abstract public function importStdClass($a_std);
310}
An exception for terminatinating execution or to throw for unit testing.
ADT definition base class.
ADT base class.
Definition: class.ilADT.php:12
$validation_errors
Definition: class.ilADT.php:14
const ADT_VALIDATION_ERROR_MAX_SIZE
Definition: class.ilADT.php:25
equals(ilADT $a_adt)
Check if given ADT equals self.
isSmaller(ilADT $a_adt)
Check if given ADT is smaller than self.
isSmallerOrEqual(ilADT $a_adt)
Check if given ADT is smaller or equal than self.
const ADT_VALIDATION_ERROR_MAX_LENGTH
Definition: class.ilADT.php:22
isNull()
Is currently null.
importStdClass($a_std)
Import value from stdClass.
const ADT_VALIDATION_ERROR_MAX
Definition: class.ilADT.php:29
isLargerOrEqual(ilADT $a_adt)
Check if given ADT is larger or equal than self.
getType()
Get type (from class/instance)
Definition: class.ilADT.php:53
getCopyOfDefinition()
Get copy of definition.
isValid()
Is currently valid.
exportStdClass()
Export value as stdClass.
__construct(ilADTDefinition $a_def)
Constructor.
Definition: class.ilADT.php:42
const ADT_VALIDATION_ERROR_INVALID_NODE
Definition: class.ilADT.php:35
reset()
Init property defaults.
Definition: class.ilADT.php:61
addValidationError($a_error_code)
Add validation error code.
setDefinition(ilADTDefinition $a_def)
Set definition.
Definition: class.ilADT.php:83
getValidationErrors()
Get all validation error codes.
getCheckSum()
Get unique checksum.
getDefinition()
Get definition.
Definition: class.ilADT.php:97
isValidDefinition(ilADTDefinition $a_def)
Check if definition is valid for ADT.
isInbetween(ilADT $a_adt_from, ilADT $a_adt_to)
Check if self is inbetween given ADTs (exclusive)
const ADT_VALIDATION_ERROR_MIN
Definition: class.ilADT.php:28
const ADT_VALIDATION_ERROR_NULL_NOT_ALLOWED
Definition: class.ilADT.php:19
const ADT_VALIDATION_DATE
Definition: class.ilADT.php:32
isLarger(ilADT $a_adt)
Check if given ADT is larger than self.
translateErrorCode($a_code)
Translate error-code to human-readable message.
isInbetweenOrEqual(ilADT $a_adt_from, ilADT $a_adt_to)
Check if self is inbetween given ADTs (inclusive)
Base class for ILIAS Exception handling.
$lng
$DIC
Definition: xapitoken.php:46