Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
address.php
1<?php
2
4
16
21final class Address
22{
24 private $id = 0;
26 private $languageId;
28 protected $latitude = '';
30 protected $longitude = '';
32 private $location;
34 private $fieldCollection;
36 private $linkCollection = null;
37
42 public function __construct(string $languageId)
43 {
44 $this->languageId = $languageId;
45 $this->fieldCollection = new FieldCollection();
46 $this->linkCollection = new AddressLinkCollection();
47 }
48
52 public function getId(): int
53 {
54 return $this->id;
55 }
56
61 public function setId(int $id): Address
62 {
63 $this->id = $id;
64 return $this;
65 }
66
70 public function getLatitude(): string
71 {
72 return $this->latitude;
73 }
74
79 public function setLatitude(string $latitude): Address
80 {
81 $this->latitude = $latitude;
82 return $this;
83 }
84
88 public function getLongitude(): string
89 {
90 return $this->longitude;
91 }
92
97 public function setLongitude(string $longitude): Address
98 {
99 $this->longitude = $longitude;
100 return $this;
101 }
102
106 public function getLanguageId(): string
107 {
108 return $this->languageId;
109 }
110
116 {
117 return $this->fieldCollection;
118 }
119
125 public function setFieldCollection(FieldCollection $fieldCollection): Address
126 {
127 $this->fieldCollection = $fieldCollection;
128
129 return $this;
130 }
131
135 public function getLocation():? Location
136 {
137 return $this->location;
138 }
139
144 public function setLocation(?Location $location): self
145 {
146 $this->location = $location;
147 return $this;
148 }
149
157 public function setFieldValue(int $type, string $value): self
158 {
159 if($field = $this->getFieldCollection()->getItemByType($type))
160 {
161 $field->setValue($value);
162 }
163 else
164 {
165 $this->fieldCollection->addItem(
166 (new Field($type))
167 ->setValue($value)
168 );
169 }
170
171 return $this;
172 }
173
179 public function getAllFieldsValues(): array
180 {
181 $result = [];
182
183 foreach ($this->getFieldCollection() as $field)
184 {
185 $result[$field->getType()] = $field->getValue();
186 }
187
188 return $result;
189 }
190
197 public function getFieldValue(int $type): ?string
198 {
199 $result = null;
200
201 if($field = $this->getFieldCollection()->getItemByType($type))
202 {
203 $result = $field->getValue();
204 }
205
206 return $result;
207 }
208
215 public function isFieldExist(int $type): bool
216 {
217 return (bool)$this->getFieldCollection()->getItemByType($type);
218 }
219
229 public static function load(int $id)
230 {
231 return AddressService::getInstance()->findById($id);
232 }
233
243 public function save()
244 {
245 return AddressService::getInstance()->save($this);
246 }
247
254 public function delete(): DeleteResult
255 {
256 return AddressService::getInstance()->delete($this->getId());
257 }
258
265 public function toJson(): string
266 {
267 return Json::encode(ArrayConverter::convertToArray($this));
268 }
269
275 public function toArray(): array
276 {
277 return ArrayConverter::convertToArray($this);
278 }
279
287 public static function fromJson(string $jsonData): Address
288 {
289 return ArrayConverter::convertFromArray(Json::decode($jsonData));
290 }
291
298 public static function fromArray(array $arrayData): Address
299 {
300 return ArrayConverter::convertFromArray($arrayData);
301 }
302
306 public function setLinks(AddressLinkCollection $collection): void
307 {
308 $this->linkCollection = $collection;
309 }
310
315 {
316 return $this->linkCollection;
317 }
318
322 public function clearLinks(): void
323 {
324 $this->linkCollection->clear();
325 }
326
334 public function addLink(string $entityId, string $entityType): void
335 {
336 if($entityId === '')
337 {
338 throw new ArgumentNullException('entityId');
339 }
340
341 if($entityType === '')
342 {
343 throw new ArgumentNullException('entityType');
344 }
345
346 $this->linkCollection->addItem(
347 new AddressLink($entityId, $entityType)
348 );
349 }
350
356 public function hasLinks(): bool
357 {
358 return $this->linkCollection->count() > 0;
359 }
360
370 public function toString(
371 Format $format,
372 string $strategyType = StringConverter::STRATEGY_TYPE_TEMPLATE,
373 string $contentType = StringConverter::CONTENT_TYPE_HTML
374 ): string
375 {
376 return StringConverter::convertToString($this, $format, $strategyType, $contentType);
377 }
378}
setLatitude(string $latitude)
Definition address.php:79
toString(Format $format, string $strategyType=StringConverter::STRATEGY_TYPE_TEMPLATE, string $contentType=StringConverter::CONTENT_TYPE_HTML)
Definition address.php:370
addLink(string $entityId, string $entityType)
Definition address.php:334
setLinks(AddressLinkCollection $collection)
Definition address.php:306
static fromJson(string $jsonData)
Definition address.php:287
static fromArray(array $arrayData)
Definition address.php:298
setFieldValue(int $type, string $value)
Definition address.php:157
setLongitude(string $longitude)
Definition address.php:97
setLocation(?Location $location)
Definition address.php:144
__construct(string $languageId)
Definition address.php:42
setFieldCollection(FieldCollection $fieldCollection)
Definition address.php:125