ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilADTExternalLink.php
Go to the documentation of this file.
1<?php
2
4{
5 const MAX_LENGTH = 500;
6
10 protected $value;
11
15 protected $title;
16
17
22 protected function isValidDefinition(ilADTDefinition $a_def)
23 {
24 return $a_def instanceof ilADTExternalLinkDefinition;
25 }
26
30 public function reset()
31 {
32 parent::reset();
33 $this->value = null;
34 $this->title = null;
35 }
36
41 public function setTitle($a_title = null)
42 {
43 if ($a_title !== null) {
44 $a_title = trim($a_title);
45 }
46 $this->title = $a_title;
47 }
48
53 public function getTitle()
54 {
55 return $this->title;
56 }
57
62 public function setUrl($a_value = null)
63 {
64 if ($a_value !== null) {
65 $a_value = trim($a_value);
66 }
67 $this->value = $a_value;
68 }
69
74 public function getUrl()
75 {
76 return $this->value;
77 }
78
79
85 public function equals(ilADT $a_adt)
86 {
87 if ($this->getDefinition()->isComparableTo($a_adt)) {
88 return strcmp($this->getCheckSum(), $a_adt->getCheckSum()) === 0;
89 }
90 }
91
96 public function isLarger(ilADT $a_adt)
97 {
98 }
99
104 public function isSmaller(ilADT $a_adt)
105 {
106 }
107
112 public function isNull()
113 {
114 return (bool) !$this->getLength();
115 }
116
121 public function getLength()
122 {
123 if (function_exists("mb_strlen")) {
124 return mb_strlen($this->getUrl() . $this->getTitle(), "UTF-8");
125 } else {
126 return strlen($this->getUrl() . $this->getTitle());
127 }
128 }
129
130
135 public function isValid()
136 {
137 $valid = parent::isValid();
138
139 if (!$this->isNull()) {
140 if (self::MAX_LENGTH < $this->getLength()) {
141 $valid = false;
142 $this->addValidationError(self::ADT_VALIDATION_ERROR_MAX_LENGTH);
143 }
144 }
145
146 return $valid;
147 }
148
153 public function getCheckSum()
154 {
155 if (!$this->isNull()) {
156 return md5($this->getUrl() . $this->getTitle());
157 }
158 }
159
160
164 public function exportStdClass()
165 {
166 if (!$this->isNull()) {
167 $obj = new stdClass();
168 $obj->url = $this->getUrl();
169 $obj->title = $this->getTitle();
170
171 return $obj;
172 }
173 }
174
175
179 public function importStdClass($a_std)
180 {
181 if (is_object($a_std)) {
182 $this->setTitle($a_std->title);
183 $this->setUrl($a_std->url);
184 }
185 }
186}
An exception for terminatinating execution or to throw for unit testing.
ADT definition base class.
ADT base class.
Definition: class.ilADT.php:12
addValidationError($a_error_code)
Add validation error code.
getCheckSum()
Get unique checksum.
getDefinition()
Get definition.
Definition: class.ilADT.php:97
$valid