Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
addressconverter.php
1<?php
2
4
8
15{
23 public static function convertToAddress(Entity\Location $location): Address
24 {
25 $type = $location->getType() === Location\Type::UNKNOWN ? Address\FieldType::ADDRESS_LINE_2 : $location->getType();
26
27 $result = (new Address($location->getLanguageId()))
28 ->setLatitude($location->getLatitude())
29 ->setLongitude($location->getLongitude())
30 ->setFieldValue($type, $location->getName());
31
32 if($parents = $location->getParents())
33 {
35 foreach ($parents as $parent)
36 {
37 $result->setFieldValue($parent->getType(), $parent->getName());
38 }
39 }
40
41 if($fields = $location->getAllFieldsValues())
42 {
43 foreach($fields as $type => $value)
44 {
45 if(!$result->isFieldExist($type))
46 {
47 $result->setFieldValue($type, $value);
48 }
49 }
50 }
51
52 return $result;
53 }
54}
setFieldValue(int $type, string $value)
Definition address.php:157