ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
11 abstract 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
28  const ADT_VALIDATION_ERROR_MIN = "adt4";
29  const ADT_VALIDATION_ERROR_MAX = "adt5";
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  {
269  case self::ADT_VALIDATION_ERROR_NULL_NOT_ALLOWED:
270  return $lng->txt("msg_input_is_required");
271 
272  case self::ADT_VALIDATION_ERROR_MAX_LENGTH:
273  return $lng->txt("adt_error_max_length");
274 
275  case self::ADT_VALIDATION_ERROR_MAX_SIZE:
276  return $lng->txt("adt_error_max_size");
277 
278  case self::ADT_VALIDATION_ERROR_MIN:
279  return $lng->txt("form_msg_value_too_low");
280 
281  case self::ADT_VALIDATION_ERROR_MAX:
282  return $lng->txt("form_msg_value_too_high");
283 
284  // :TODO: currently not used - see ilDateTimeInputGUI
285  case self::ADT_VALIDATION_DATE:
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 ?>
getType()
Get type (from class/instance)
Definition: class.ilADT.php:51
equals(ilADT $a_adt)
Check if given ADT equals self.
Base class for ILIAS Exception handling.
const ADT_VALIDATION_ERROR_MAX_SIZE
Definition: class.ilADT.php:25
isSmaller(ilADT $a_adt)
Check if given ADT is smaller than self.
isValid()
Is currently valid.
const ADT_VALIDATION_ERROR_MIN
Definition: class.ilADT.php:28
isLarger(ilADT $a_adt)
Check if given ADT is larger than self.
addValidationError($a_error_code)
Add validation error code.
isLargerOrEqual(ilADT $a_adt)
Check if given ADT is larger or equal than self.
const ADT_VALIDATION_ERROR_MAX_LENGTH
Definition: class.ilADT.php:22
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)
Add rich text string
The name of the decorator.
isSmallerOrEqual(ilADT $a_adt)
Check if given ADT is smaller or equal than self.
$validation_errors
Definition: class.ilADT.php:14
ADT base class.
Definition: class.ilADT.php:11
isValidDefinition(ilADTDefinition $a_def)
Check if definition is valid for ADT.
const ADT_VALIDATION_ERROR_MAX
Definition: class.ilADT.php:29
reset()
Init property defaults.
Definition: class.ilADT.php:59
__construct(ilADTDefinition $a_def)
Constructor.
Definition: class.ilADT.php:40
getValidationErrors()
Get all validation error codes.
isInbetween(ilADT $a_adt_from, ilADT $a_adt_to)
Check if self is inbetween given ADTs (exclusive)
isNull()
Is currently null.
Create styles array
The data for the language used.
getCopyOfDefinition()
Get copy of definition.
getCheckSum()
Get unique checksum.
global $lng
Definition: privfeed.php:17
const ADT_VALIDATION_ERROR_NULL_NOT_ALLOWED
Definition: class.ilADT.php:19
setDefinition(ilADTDefinition $a_def)
Set definition.
Definition: class.ilADT.php:82
ADT definition base class.
const ADT_VALIDATION_DATE
Definition: class.ilADT.php:32
getDefinition()
Get definition.
Definition: class.ilADT.php:99