Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
byqueryconverter.php
1<?php
2
4
10
17{
22 public function convert(array $data)
23 {
24 if(isset($data['status']) && $data['status'] != 'OK')
25 {
26 $errorMessage = $data['error_message'].' ('.$data['status'].')' ?? $data['status'];
27 throw new RuntimeException($errorMessage, Google\ErrorCodes::CONVERTER_BYQUERY_ERROR);
28 }
29
30 if(!isset($data['results']) || !is_array($data['results']))
31 {
32 return null;
33 }
34
35 $result = new Collection;
36
37 foreach($data['results'] as $item)
38 {
39 if(isset($item['types']))
40 {
41 $type = $this->convertTypes($item['types'], Location\Type::class);
42 }
43 else
44 {
45 $type = Address\FieldType::UNKNOWN;
46 }
47
48 $location = (new Location())
49 ->setSourceCode(Google\Repository::getSourceCode())
50 ->setExternalId($item['place_id'])
51 ->setName($item['name'])
52 ->setLongitude($item['geometry']['location']['lng'])
53 ->setLatitude($item['geometry']['location']['lat'])
54 ->setType($type)
55 ->setLanguageId($this->languageId);
56
57 $result->addItem($location);
58 }
59
60 return $result;
61 }
62}
63