Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
repository.php
1<?php
2
4
16
23{
25 protected static $sourceCode = 'OSM';
26
28 protected $api;
29
31 protected $osmSource;
32
39 {
40 $this->api = $api;
41 $this->osmSource = $osmSource;
42 }
43
47 public function findByExternalId(string $externalId, string $sourceCode, string $languageId)
48 {
49 $osmType = ExternalIdBuilder::getOsmTypeByExternalId($externalId);
50 $osmId = ExternalIdBuilder::getOsmIdByExternalId($externalId);
51
52 if ($sourceCode !== self::$sourceCode || is_null($osmType) || is_null($osmId))
53 {
54 return null;
55 }
56
57 $details = $this->api->details(
58 [
59 'osm_type' => $osmType,
60 'osm_id' => $osmId,
61 'addressdetails' => 1,
62 'accept-language' => $this->osmSource->convertLang($languageId),
63 ]
64 );
65
66 $location = Factory::make($details)->convert(
67 $languageId, $details
68 );
69
70 if (
71 $location
72 && isset($details['centroid'])
73 )
74 {
75 $centroid = Manager::makeConverter(Manager::FORMAT_ARRAY)->read($details['centroid']);
76
77 if ($centroid instanceof Point)
78 {
79 $disputedScenario = DisputedAreaService::getInstance()->getDisputeByPoint($centroid);
80 if ($disputedScenario)
81 {
82 $disputedScenario->adjustLocation($location);
83 }
84 }
85 }
86
87 return $location;
88 }
89
93 public function autocomplete(array $params): array
94 {
95 $result = $this->api->autocomplete([
96 'q' => $params['q'],
97 'lang' => $this->osmSource->convertLang($params['lang']),
98 'lat' => $params['lat'] ?? null,
99 'lon' => $params['lon'] ?? null,
100 ]);
101
102 if (
103 is_array($result)
104 && isset($result['features'])
105 && is_array($result['features'])
106 )
107 {
108 foreach ($result['features'] as $key => $feature)
109 {
110 if (!isset($feature['geometry']))
111 {
112 continue;
113 }
114
115 $geometry = Manager::makeConverter(Manager::FORMAT_ARRAY)->read($feature['geometry']);
116 if (!$geometry instanceof Point)
117 {
118 continue;
119 }
120
121 $disputeScenario = DisputedAreaService::getInstance()->getDisputeByPoint($geometry);
122 if (!$disputeScenario)
123 {
124 continue;
125 }
126 $disputeScenario->adjustAutocompleteItem($result['features'][$key]['properties']);
127 }
128 }
129
130 return $result;
131 }
132
136 public static function getSourceCode(): string
137 {
138 return self::$sourceCode;
139 }
140}
findByExternalId(string $externalId, string $sourceCode, string $languageId)
__construct(Api $api, OsmSource $osmSource)