1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ym_location.php
См. документацию.
1<?php
2
5
7
13{
14 private $cityNames = null;
15 private $cacheId = "CSaleYMLocations";
16
17 const EXTERNAL_SERVICE_CODE = 'YAMARKET';
18
19 public function __construct(){}
20
24 private function getData()
25 {
26 if($this->cityNames !== null)
27 return $this->cityNames;
28
29 $ttl = 2592000;
30 $cacheManager = \Bitrix\Main\Application::getInstance()->getManagedCache();
31
32 if(false && $cacheManager->read($ttl, $this->cacheId))
33 {
34 $cityNames = $cacheManager->get($this->cacheId);
35 }
36 else
37 {
38 $cityNames = $this->loadDataToCache();
39 $cacheManager->set($this->cacheId, $cityNames);
40 }
41
42 $this->cityNames = $cityNames;
43 return $cityNames;
44 }
45
49
50 private function loadDataToCache()
51 {
52 $result = array();
53
54 $res = \Bitrix\Sale\Location\LocationTable::getList(array(
55 'filter' => array(
56 '=NAME.LANGUAGE_ID' => 'ru',
57 '=TYPE.CODE' => array('CITY')
58 ),
59 'select' => array(
60 'ID',
61 'NAME_NAME' => 'NAME.NAME'
62 )
63 ));
64
65 $replaceFrom = explode(',', Loc::getMessage('SALE_YML_REPLACE_FROM'));
66
67 while($loc = $res->fetch())
68 {
69 $result[$loc['ID']] = str_replace(
70 $replaceFrom,
71 Loc::getMessage('SALE_YML_REPLACE_TO'),
72 mb_strtolower($loc['NAME_NAME'])
73 );
74 }
75
76 return $result;
77 }
78
83 public function getLocationByCityName($cityName)
84 {
85 $this->getData();
86 $result = array_search(
87 str_replace(
88 explode(
89 ',',
90 Loc::getMessage('SALE_YML_REPLACE_FROM')
91 ),
92 Loc::getMessage('SALE_YML_REPLACE_TO'),
93 mb_strtolower($cityName)
94 ),
95 $this->cityNames
96 );
97 return $result;
98 }
99
100 protected function getLocationByExternalIds($yandexLocationsIds)
101 {
102 if(empty($yandexLocationsIds))
103 return array();
104
105 $result = array();
106
107 $res = ExternalTable::getList(array(
108 'filter' => array(
109 '=XML_ID' => $yandexLocationsIds,
110 '=SERVICE.CODE' => self::EXTERNAL_SERVICE_CODE
111 )
112 ));
113
114 while($loc = $res->fetch())
115 $result[$loc['XML_ID']] = $loc['LOCATION_ID'];
116
117 return $result;
118 }
119
120 protected function extractLocations($yandexLocation)
121 {
122 if(empty($yandexLocation) || !is_array($yandexLocation))
123 return array();
124
125 $result = array();
126 $tmp = $yandexLocation;
127 unset($tmp['parent']);
128 $result[$tmp['id']] = $tmp;
129
130 if(!empty($yandexLocation['parent']))
131 $result = $result + $this->extractLocations($yandexLocation['parent']);
132
133 return $result;
134 }
135
136 public function getLocationId($yandexLocation)
137 {
138 if(empty($yandexLocation) || !is_array($yandexLocation))
139 return false;
140
141 $locations = $this->extractLocations($yandexLocation);
142
143 if(empty($locations))
144 return false;
145
146 $mapExternal = $this->getLocationByExternalIds(array_keys($locations));
147
148 if(!empty($mapExternal))
149 foreach($locations as $yLocId => $yLocParams)
150 if(!empty($mapExternal[$yLocId]))
151 return $mapExternal[$yLocId];
152
153 if(empty($yandexLocation["name"]))
154 return false;
155
156 return $this->getLocationByCityName($yandexLocation["name"]);
157 }
158}
static getInstance()
Определения application.php:98
Определения ym_location.php:13
__construct()
Определения ym_location.php:19
extractLocations($yandexLocation)
Определения ym_location.php:120
const EXTERNAL_SERVICE_CODE
Определения ym_location.php:17
getLocationByExternalIds($yandexLocationsIds)
Определения ym_location.php:100
getLocationId($yandexLocation)
Определения ym_location.php:136
getLocationByCityName($cityName)
Определения ym_location.php:83
if(!is_array($prop["VALUES"])) $tmp
Определения component_props.php:203
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778