ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTExternalLink.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public const MAX_LENGTH = 2000;
24
25 protected ?string $value;
26 protected ?string $title;
27
32 protected function isValidDefinition(ilADTDefinition $a_def): bool
33 {
34 return $a_def instanceof ilADTExternalLinkDefinition;
35 }
36
40 public function reset(): void
41 {
42 parent::reset();
43 $this->value = null;
44 $this->title = null;
45 }
46
51 public function setTitle(?string $a_title = null): void
52 {
53 if ($a_title !== null) {
54 $a_title = trim($a_title);
55 }
56 $this->title = $a_title;
57 }
58
63 public function getTitle(): ?string
64 {
65 return $this->title;
66 }
67
72 public function setUrl(?string $a_value = null): void
73 {
74 if ($a_value !== null) {
75 $a_value = trim($a_value);
76 }
77 $this->value = $a_value;
78 }
79
84 public function getUrl(): ?string
85 {
86 return $this->value;
87 }
88
93 public function equals(ilADT $a_adt): ?bool
94 {
95 if ($this->getDefinition()->isComparableTo($a_adt)) {
96 return strcmp($this->getCheckSum() ?? '', $a_adt->getCheckSum() ?? '') === 0;
97 }
98 return null;
99 }
100
101 public function isLarger(ilADT $a_adt): ?bool
102 {
103 return null;
104 }
105
106 public function isSmaller(ilADT $a_adt): ?bool
107 {
108 return null;
109 }
110
115 public function isNull(): bool
116 {
117 return !$this->getLength();
118 }
119
124 public function getLength(): int
125 {
126 if (function_exists("mb_strlen")) {
127 return mb_strlen($this->getUrl() . $this->getTitle(), "UTF-8");
128 } else {
129 return strlen($this->getUrl() . $this->getTitle());
130 }
131 }
132
133 public function isValid(): bool
134 {
135 $valid = parent::isValid();
136 if (!$this->isNull()) {
137 if (self::MAX_LENGTH < $this->getLength()) {
138 $valid = false;
139 $this->addValidationError(self::ADT_VALIDATION_ERROR_MAX_LENGTH);
140 }
141 }
142 return $valid;
143 }
144
149 public function getCheckSum(): ?string
150 {
151 if (!$this->isNull()) {
152 return md5($this->getUrl() . $this->getTitle());
153 }
154 return null;
155 }
156
160 public function exportStdClass(): ?stdClass
161 {
162 if (!$this->isNull()) {
163 $obj = new stdClass();
164 $obj->url = $this->getUrl();
165 $obj->title = $this->getTitle();
166 return $obj;
167 }
168 return null;
169 }
170
174 public function importStdClass(?stdClass $a_std): void
175 {
176 if (is_object($a_std)) {
177 $this->setTitle($a_std->title);
178 $this->setUrl($a_std->url);
179 }
180 }
181}
ADT definition base class.
ADT base class.
Definition: class.ilADT.php:26
addValidationError(string $a_error_code)
getCheckSum()
Get unique checksum.
getDefinition()
Get definition.
$valid