ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $a_value = trim($a_value);
29 }
30 $this->value = $a_value;
31 }
32
33 public function getText()
34 {
35 return $this->value;
36 }
37
38 public function getLength()
39 {
40 // see ilStr::strLen();
41 // not using ilStr to reduce dependencies in this low-level code
42
43 if (function_exists("mb_strlen")) {
44 return mb_strlen($this->getText(), "UTF-8");
45 } else {
46 return strlen($this->getText());
47 }
48 }
49
50
51 // comparison
52
53 public function equals(ilADT $a_adt)
54 {
55 if ($this->getDefinition()->isComparableTo($a_adt)) {
56 return !strcmp($this->getText(), $a_adt->getText());
57 }
58 }
59
60 public function isLarger(ilADT $a_adt)
61 {
62 // return null?
63 }
64
65 public function isSmaller(ilADT $a_adt)
66 {
67 // return null?
68 }
69
70
71 // null
72
73 public function isNull()
74 {
75 return !(bool) $this->getLength();
76 }
77
78
79 // validation
80
81 public function isValid()
82 {
83 $valid = parent::isValid();
84
85 if (!$this->isNull()) {
86 $max = $this->getDefinition()->getMaxLength();
87 if ($max && $max < $this->getLength()) {
88 $valid = false;
89 $this->addValidationError(self::ADT_VALIDATION_ERROR_MAX_LENGTH);
90 }
91 }
92
93 return $valid;
94 }
95
96
97 // check
98
99 public function getCheckSum()
100 {
101 if (!$this->isNull()) {
102 return md5($this->getText());
103 }
104 }
105
106
107 // stdClass
108
109 public function exportStdClass()
110 {
111 if (!$this->isNull()) {
112 $obj = new stdClass();
113 $obj->value = $this->getText();
114 return $obj;
115 }
116 }
117
118 public function importStdClass($a_std)
119 {
120 if (is_object($a_std)) {
121 $this->setText($a_std->value);
122 }
123 }
124}
An exception for terminatinating execution or to throw for unit testing.
ADT definition base class.
importStdClass($a_std)
Import value from stdClass.
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.
exportStdClass()
Export value as stdClass.
ADT base class.
Definition: class.ilADT.php:12
addValidationError($a_error_code)
Add validation error code.
getDefinition()
Get definition.
Definition: class.ilADT.php:97
$valid