ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilADTText.php
Go to the documentation of this file.
1<?php
2
3class ilADTText extends ilADT
4{
5 protected $value; // [string]
6
7
8 // definition
9
10 protected function isValidDefinition(ilADTDefinition $a_def)
11 {
12 return ($a_def instanceof ilADTTextDefinition);
13 }
14
15 public function reset()
16 {
17 parent::reset();
18
19 $this->value = null;
20 }
21
22
23 // properties
24
25 public function setText($a_value = null)
26 {
27 if($a_value !== null)
28 {
29 $a_value = trim($a_value);
30 }
31 $this->value = $a_value;
32 }
33
34 public function getText()
35 {
36 return $this->value;
37 }
38
39 public function getLength()
40 {
41 // see ilStr::strLen();
42 // not using ilStr to reduce dependencies in this low-level code
43
44 if(function_exists("mb_strlen"))
45 {
46 return mb_strlen($this->getText(), "UTF-8");
47 }
48 else
49 {
50 return strlen($this->getText());
51 }
52 }
53
54
55 // comparison
56
57 public function equals(ilADT $a_adt)
58 {
59 if($this->getDefinition()->isComparableTo($a_adt))
60 {
61 return !strcmp($this->getText(), $a_adt->getText());
62 }
63 }
64
65 public function isLarger(ilADT $a_adt)
66 {
67 // return null?
68 }
69
70 public function isSmaller(ilADT $a_adt)
71 {
72 // return null?
73 }
74
75
76 // null
77
78 public function isNull()
79 {
80 return !(bool)$this->getLength();
81 }
82
83
84 // validation
85
86 public function isValid()
87 {
88 $valid = parent::isValid();
89
90 if(!$this->isNull())
91 {
92 $max = $this->getDefinition()->getMaxLength();
93 if($max && $max < $this->getLength())
94 {
95 $valid = false;
96 $this->addValidationError(self::ADT_VALIDATION_ERROR_MAX_LENGTH);
97 }
98 }
99
100 return $valid;
101 }
102
103
104 // check
105
106 public function getCheckSum()
107 {
108 if(!$this->isNull())
109 {
110 return md5($this->getText());
111 }
112 }
113}
114
115?>
An exception for terminatinating execution or to throw for unit testing.
ADT definition base class.
reset()
Init property defaults.
isValid()
Is currently valid.
isNull()
Is currently null.
getCheckSum()
Get unique checksum.
isLarger(ilADT $a_adt)
Check if given ADT is larger than self.
equals(ilADT $a_adt)
Check if given ADT equals self.
setText($a_value=null)
isValidDefinition(ilADTDefinition $a_def)
Check if definition is valid for ADT.
isSmaller(ilADT $a_adt)
Check if given ADT is smaller than self.
ADT base class.
Definition: class.ilADT.php:12
addValidationError($a_error_code)
Add validation error code.
getDefinition()
Get definition.
Definition: class.ilADT.php:99
$valid