Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
arrayconverter.php
1<?php
2
4
7
13final class ArrayConverter
14{
21 public static function convertToArray(Entity\Location $location): array
22 {
23 if($address = $location->getAddress())
24 {
25 $address = Entity\Address\Converter\ArrayConverter::convertToArray($address, false);
26 }
27
28 return [
29 'id' => $location->getId(),
30 'code' => $location->getCode(),
31 'externalId' => $location->getExternalId(),
32 'sourceCode' => $location->getSourceCode(),
33 'type' => $location->getType(),
34 'name' => $location->getName(),
35 'languageId' => $location->getLanguageId(),
36 'latitude' => $location->getLatitude(),
37 'longitude' => $location->getLongitude(),
38 'fieldCollection' => self::convertFieldsToArray($location->getAllFieldsValues()),
39 'address' => $address
40 ];
41 }
42
47 private static function convertFieldsToArray(array $fieldsValues): array
48 {
49 $result = [];
50
51 foreach ($fieldsValues as $type => $value)
52 {
53 $result[$type] = $value;
54 }
55
56 return $result;
57 }
58
65 public static function convertParentsToArray(Entity\Location\Parents $parents): array
66 {
67 $result = [];
68
69 foreach ($parents as $location)
70 {
71 $result[] = ArrayConverter::convertToArray($location);
72 }
73
74 return $result;
75 }
76
85 public static function convertFromArray(array $data): Location
86 {
87 $result = (new Location())
88 ->setId((int)$data['id'])
89 ->setCode((string)$data['code'])
90 ->setExternalId((string)$data['externalId'])
91 ->setSourceCode((string)$data['sourceCode'])
92 ->setType((int)$data['type'])
93 ->setName((string)$data['name'])
94 ->setLanguageId((string)$data['languageId'])
95 ->setLatitude((string)$data['latitude'])
96 ->setLongitude((string)$data['longitude']);
97
98 if(is_array($data['fieldCollection']))
99 {
100 foreach ($data['fieldCollection'] as $itemType => $itemValue)
101 {
102 $result->setFieldValue($itemType, (string)$itemValue);
103 }
104 }
105
106 return $result;
107 }
108}
static convertToArray(Address $address, bool $convertLocation=true)
static convertParentsToArray(Entity\Location\Parents $parents)
setFieldValue(int $type, string $value)
Definition location.php:563