ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  // 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) {
266  case self::ADT_VALIDATION_ERROR_NULL_NOT_ALLOWED:
267  return $lng->txt("msg_input_is_required");
268 
269  case self::ADT_VALIDATION_ERROR_MAX_LENGTH:
270  return $lng->txt("adt_error_max_length");
271 
272  case self::ADT_VALIDATION_ERROR_MAX_SIZE:
273  return $lng->txt("adt_error_max_size");
274 
275  case self::ADT_VALIDATION_ERROR_MIN:
276  return $lng->txt("form_msg_value_too_low");
277 
278  case self::ADT_VALIDATION_ERROR_MAX:
279  return $lng->txt("form_msg_value_too_high");
280 
281  // :TODO: currently not used - see ilDateTimeInputGUI
282  case self::ADT_VALIDATION_DATE:
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 }
getType()
Get type (from class/instance)
Definition: class.ilADT.php:53
equals(ilADT $a_adt)
Check if given ADT equals self.
Add rich text string
const ADT_VALIDATION_ERROR_MAX_SIZE
Definition: class.ilADT.php:25
const ADT_VALIDATION_ERROR_INVALID_NODE
Definition: class.ilADT.php:35
isSmaller(ilADT $a_adt)
Check if given ADT is smaller than self.
isValid()
Is currently valid.
global $DIC
Definition: saml.php:7
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)
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:61
__construct(ilADTDefinition $a_def)
Constructor.
Definition: class.ilADT.php:42
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:83
ADT definition base class.
const ADT_VALIDATION_DATE
Definition: class.ilADT.php:32
getDefinition()
Get definition.
Definition: class.ilADT.php:97