Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
arrayconverter.php
1
<?php
2
3
namespace
Bitrix\Location\Entity\Address\Converter
;
4
5
use
Bitrix\Location\Entity\Address
;
6
use
Bitrix\Location\Entity\Location
;
7
13
final
class
ArrayConverter
14
{
22
public
static
function
convertToArray
(
Address
$address,
bool
$convertLocation =
true
): array
23
{
24
$result = [
25
'id'
=> $address->
getId
(),
26
'latitude'
=> $address->
getLatitude
(),
27
'longitude'
=> $address->
getLongitude
(),
28
'languageId'
=> $address->
getLanguageId
(),
29
'fieldCollection'
=>
self::convertFieldsToArray
($address->
getAllFieldsValues
()),
30
'links'
=>
self::convertLinksToArray
($address)
31
];
32
33
if
($convertLocation && $location = $address->
getLocation
())
34
{
35
$result[
'location'
] = Location\Converter\ArrayConverter::convertToArray($location);
36
}
37
38
return
$result;
39
}
40
47
public
static
function
convertFromArray
(array $data):
Address
48
{
49
$languageId = (string)($data[
'languageId'
] ??
''
);
50
51
$result =
new
Address
($languageId);
52
53
if
(isset($data[
'id'
]))
54
{
55
$result->setId((
int
)$data[
'id'
]);
56
}
57
58
if
(isset($data[
'latitude'
]))
59
{
60
$result->setLatitude((
string
)$data[
'latitude'
]);
61
}
62
63
if
(isset($data[
'longitude'
]))
64
{
65
$result->setLongitude((
string
)$data[
'longitude'
]);
66
}
67
68
if
(isset($data[
'fieldCollection'
]) && is_array($data[
'fieldCollection'
]))
69
{
70
foreach
($data[
'fieldCollection'
] as $itemType => $itemValue)
71
{
72
$result->setFieldValue((
int
)$itemType, (
string
)$itemValue);
73
}
74
}
75
76
if
(isset($data[
'links'
]) && is_array($data[
'links'
]))
77
{
78
foreach
($data[
'links'
] as $link)
79
{
80
$result->addLink((
string
)$link[
'entityId'
], (
string
)$link[
'entityType'
]);
81
}
82
}
83
84
if
(isset($data[
'location'
]) && is_array($data[
'location'
]))
85
{
86
if
($location =
Location::fromArray
($data[
'location'
]))
87
{
88
$result->setLocation($location);
89
}
90
}
91
92
return
$result;
93
}
94
99
protected
static
function
convertFieldsToArray
(array $fieldsValues): array
100
{
101
$result = [];
102
103
foreach
($fieldsValues as $type => $value)
104
{
105
$result[$type] = $value;
106
}
107
108
return
$result;
109
}
110
115
protected
static
function
convertLinksToArray
(
Address
$address): array
116
{
117
$result = [];
118
119
foreach
($address->
getLinks
() as $link)
120
{
121
$result[] = [
122
'entityId'
=> $link->getAddressLinkEntityId(),
123
'entityType'
=> $link->getAddressLinkEntityType(),
124
];
125
}
126
127
return
$result;
128
}
129
}
Bitrix\Location\Entity\Address\Converter\ArrayConverter
Definition
arrayconverter.php:14
Bitrix\Location\Entity\Address\Converter\ArrayConverter\convertFieldsToArray
static convertFieldsToArray(array $fieldsValues)
Definition
arrayconverter.php:99
Bitrix\Location\Entity\Address\Converter\ArrayConverter\convertLinksToArray
static convertLinksToArray(Address $address)
Definition
arrayconverter.php:115
Bitrix\Location\Entity\Address\Converter\ArrayConverter\convertFromArray
static convertFromArray(array $data)
Definition
arrayconverter.php:47
Bitrix\Location\Entity\Address\Converter\ArrayConverter\convertToArray
static convertToArray(Address $address, bool $convertLocation=true)
Definition
arrayconverter.php:22
Bitrix\Location\Entity\Address
Definition
address.php:22
Bitrix\Location\Entity\Address\getLinks
getLinks()
Definition
address.php:314
Bitrix\Location\Entity\Address\getId
getId()
Definition
address.php:52
Bitrix\Location\Entity\Address\getLocation
getLocation()
Definition
address.php:135
Bitrix\Location\Entity\Address\getAllFieldsValues
getAllFieldsValues()
Definition
address.php:179
Bitrix\Location\Entity\Address\getLanguageId
getLanguageId()
Definition
address.php:106
Bitrix\Location\Entity\Address\getLongitude
getLongitude()
Definition
address.php:88
Bitrix\Location\Entity\Address\getLatitude
getLatitude()
Definition
address.php:70
Bitrix\Location\Entity\Location\fromArray
static fromArray(array $location)
Definition
location.php:550
Bitrix\Location\Entity\Address\Converter
Definition
arrayconverter.php:3
Bitrix\Location\Entity\Address
Definition
addresscollection.php:3
Bitrix\Location\Entity\Location
Definition
collection.php:3
modules
location
lib
entity
address
converter
arrayconverter.php
Создано системой
1.10.0