Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ancestordataconverter.php
1<?php
2
4
7
9{
10 public function convert(array $locationRawData, int $descendantType)
11 {
12 $result = [];
13
14 if(isset($locationRawData['result']['address_components'])
15 && is_array($locationRawData['result']['address_components'])
16 && count($locationRawData['result']['address_components']) > 0
17 )
18 {
19 $items = array_reverse($locationRawData['result']['address_components']);
20 $accumulator = '';
21
22 foreach ($items as $item)
23 {
24 $types =$this->convertTypes($item['types'], $descendantType);
25
26 if(empty($types))
27 {
28 continue;
29 }
30
31 if($accumulator <> '')
32 {
33 $accumulator .= ',';
34 }
35
36 $accumulator .= $item['long_name'];
37
38 $result[] = [
39 'NAME' => $accumulator,
40 'TYPES' => $types
41 ];
42 }
43 }
44
45 return array_reverse($result);
46 }
47
48 protected function convertTypes(array $types, int $descendantType)
49 {
50 $result = [];
51
52 foreach($types as $gType)
53 {
54 $type = PlaceTypeConverter::convert($gType);
55
56 if($type === Type::UNKNOWN)
57 {
58 continue;
59 }
60
61 //Only location type
62 if(!Type::isValueExist($type))
63 {
64 continue;
65 }
66
67 //Type::COUNTRY == 100 Type::LOCALITY == 300
68 if($descendantType !== Type::UNKNOWN && $descendantType <= $type)
69 {
70 continue;
71 }
72
73 $result[] = $type;
74 }
75
76 return $result;
77 }
78}