ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
40 public function __construct(ilADTDefinition $a_def)
41 {
42 $this->setDefinition($a_def);
43 $this->reset();
44 }
45
51 public function getType()
52 {
53 return $this->getDefinition()->getType();
54 }
55
59 protected function reset()
60 {
61
62 }
63
64
65 //
66 // definition
67 //
68
74 abstract protected function isValidDefinition(ilADTDefinition $a_def);
75
82 protected function setDefinition(ilADTDefinition $a_def)
83 {
84 if($this->isValidDefinition($a_def))
85 {
86 $this->definition = clone $a_def;
87 }
88 else
89 {
90 throw new ilException("ilADT invalid definition");
91 }
92 }
93
99 protected function getDefinition()
100 {
101 return $this->definition;
102 }
103
109 public function getCopyOfDefinition()
110 {
111 return (clone $this->definition);
112 }
113
114
115 //
116 // comparison
117 //
118
125 abstract public function equals(ilADT $a_adt);
126
133 abstract public function isLarger(ilADT $a_adt);
134
141 public function isLargerOrEqual(ilADT $a_adt)
142 {
143 return ($this->equals($a_adt) ||
144 $this->isLarger($a_adt));
145 }
146
153 abstract public function isSmaller(ilADT $a_adt);
154
161 public function isSmallerOrEqual(ilADT $a_adt)
162 {
163 return ($this->equals($a_adt) ||
164 $this->isSmaller($a_adt));
165 }
166
174 public function isInbetween(ilADT $a_adt_from, ilADT $a_adt_to)
175 {
176 return ($this->isLarger($a_adt_from) &&
177 $this->isSmaller($a_adt_to));
178 }
179
187 public function isInbetweenOrEqual(ilADT $a_adt_from, ilADT $a_adt_to)
188 {
189 return ($this->equals($a_adt_from) ||
190 $this->equals($a_adt_to) ||
191 $this->isInbetween($a_adt_from, $a_adt_to));
192 }
193
194
195 //
196 // null
197 //
198
204 abstract public function isNull();
205
206
207 //
208 // validation
209 //
210
216 public function isValid()
217 {
218 $this->validation_errors = array();
219
220 if(!$this->getDefinition()->isNullAllowed() && $this->isNull())
221 {
222 $this->addValidationError(self::ADT_VALIDATION_ERROR_NULL_NOT_ALLOWED);
223 return false;
224 }
225 return true;
226 }
227
233 protected function addValidationError($a_error_code)
234 {
235 $this->validation_errors[] = (string)$a_error_code;
236 }
237
244 public function getValidationErrors()
245 {
246 if(is_array($this->validation_errors) &&
247 sizeof($this->validation_errors))
248 {
249 return array_unique($this->validation_errors);
250 }
251 return array();
252 }
253
261 public function translateErrorCode($a_code)
262 {
263 global $lng;
264
265 // $lng->txt("msg_wrong_format");
266
267 switch($a_code)
268 {
270 return $lng->txt("msg_input_is_required");
271
273 return $lng->txt("adt_error_max_length");
274
276 return $lng->txt("adt_error_max_size");
277
279 return $lng->txt("form_msg_value_too_low");
280
282 return $lng->txt("form_msg_value_too_high");
283
284 // :TODO: currently not used - see ilDateTimeInputGUI
286 return $lng->txt("exc_date_not_valid");
287
288 default:
289 throw new Exception("ADT unknown error code");
290 }
291 }
292
298 abstract public function getCheckSum();
299}
300
301?>
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.
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:51
getCopyOfDefinition()
Get copy of definition.
isValid()
Is currently valid.
__construct(ilADTDefinition $a_def)
Constructor.
Definition: class.ilADT.php:40
reset()
Init property defaults.
Definition: class.ilADT.php:59
addValidationError($a_error_code)
Add validation error code.
setDefinition(ilADTDefinition $a_def)
Set definition.
Definition: class.ilADT.php:82
getValidationErrors()
Get all validation error codes.
getCheckSum()
Get unique checksum.
getDefinition()
Get definition.
Definition: class.ilADT.php:99
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.
global $lng
Definition: privfeed.php:40