107 if(\CSaleLocation::isLocationProMigrated())
109 if(!intval($locationId) || !mb_strlen($siteId))
112 return Location\SiteLocationTable::checkConnectionExists($siteId, $locationId);
119 $arLocation = \CSaleLocation::GetByID($locationId);
121 if(static::checkCountryId($arLocation[
"COUNTRY_ID"], $siteId)
122 && static::checkRegionId($arLocation[
"REGION_ID"], $siteId)
123 && static::checkCityId($arLocation[
"CITY_ID"], $siteId)
164 $typesAll = \CSaleLocation::getTypes();
167 if(isset($typesAll[
'COUNTRY']))
168 $types[] =
"'".intval($typesAll[
'COUNTRY']).
"'";
169 if(isset($typesAll[
'REGION']))
170 $types[] =
"'".intval($typesAll[
'REGION']).
"'";
171 if(isset($typesAll[
'CITY']))
172 $types[] =
"'".intval($typesAll[
'CITY']).
"'";
174 $typesAll = array_flip($typesAll);
176 if((
string) $siteId !=
'' && \
Bitrix\
Sale\
Location\SiteLocationTable::checkLinkUsageAny($siteId) && !empty($types))
180 $sql = \Bitrix\Sale\Location\SiteLocationTable::getConnectedLocationsSql(
182 array(
'select' => array(
'ID',
'LEFT_MARGIN',
'RIGHT_MARGIN')),
183 array(
'GET_LINKED_THROUGH_GROUPS' =>
true)
186 if((
string) $sql !=
'')
190 select SL.ID, SL.TYPE_ID from b_sale_location SL
197 SL.LEFT_MARGIN >= TT.LEFT_MARGIN
199 SL.RIGHT_MARGIN <= TT.RIGHT_MARGIN
203 SL.LEFT_MARGIN <= TT.LEFT_MARGIN
205 SL.RIGHT_MARGIN >= TT.RIGHT_MARGIN
209 SL.TYPE_ID in (".implode(
', ', $types).
")
215 while($item = $res->fetch())
217 $typeId = $item[
'TYPE_ID'];
218 unset($item[
'TYPE_ID']);
220 $result[$typesAll[$typeId]][$item[
'ID']] = $item[
'ID'];
225 $res = Location\LocationTable::getList(array(
231 'data_type' =>
'integer',
232 'expression' => array(
'COUNT(*)')
240 while($item = $res->fetch())
242 if(intval($item[
'TYPE_ID']))
244 $typeCode = $typesAll[$item[
'TYPE_ID']];
245 if(isset($result[$typeCode]) && $item[
'CNT'] == count($result[$typeCode]))
247 $result[$typeCode][] =
'';
258 'COUNTRY' => array(
''),
259 'REGION' => array(
''),
326 $types = \CSaleLocation::getTypes();
329 Location\Connector::DB_LOCATION_FLAG => array(),
330 Location\Connector::DB_GROUP_FLAG => array()
332 if(is_array($typeList[
'COUNTRY']) && !empty($typeList[
'COUNTRY']))
333 $typeList[
'COUNTRY'] = array_flip($typeList[
'COUNTRY']);
335 if(is_array($typeList[
'REGION']) && !empty($typeList[
'REGION']))
336 $typeList[
'REGION'] = array_flip($typeList[
'REGION']);
338 if(is_array($typeList[
'CITY']) && !empty($typeList[
'CITY']))
339 $typeList[
'CITY'] = array_flip($typeList[
'CITY']);
341 $allCountries = isset($typeList[
'COUNTRY'][
'']);
342 $allRegions = isset($typeList[
'REGION'][
'']);
343 $allCities = isset($typeList[
'CITY'][
'']);
346 $noCountry = isset($typeList[
'COUNTRY'][
'NULL']);
347 $noRegion = isset($typeList[
'REGION'][
'NULL']);
350 $res = Location\LocationTable::getList(array(
'select' => array(
357 ),
'filter' => array(
360 while($item = $res->fetch())
363 $countryId = intval($item[
'COUNTRY_ID']);
364 $regionId = intval($item[
'REGION_ID']);
365 $cityId = intval($item[
'CITY_ID']);
366 $typeId = intval($item[
'TYPE_ID']);
369 $countryTaken =
false;
370 $regionTaken =
false;
372 if($typeId == $types[
'COUNTRY'])
376 isset($typeList[
'COUNTRY'][$countryId])
380 $countryTaken =
true;
384 if($typeId == $types[
'REGION'])
392 isset($typeList[
'REGION'][$regionId])
394 ($noCountry && !$countryId)
402 if($typeId == $types[
'CITY'])
410 isset($typeList[
'REGION'][$regionId])
412 ($noRegion && !$regionId)
420 if(isset($typeList[
'CITY'][$cityId]) && $typeId == $types[
'CITY'])
424 $locations[Location\Connector::DB_LOCATION_FLAG][$id] =
true;
428 $class = self::CONN_ENTITY_NAME.
'Table';
429 $locations[Location\Connector::DB_LOCATION_FLAG] = array_keys($locations[
Location\Connector::DB_LOCATION_FLAG]);
431 $locations[Location\Connector::DB_LOCATION_FLAG] = $class::normalizeLocationList($locations[
Location\Connector::DB_LOCATION_FLAG]);
434 $class::resetMultipleForOwner($siteId <>
''? $siteId : $class::ALL_SITES, $locations);
466 public static function getRegions($countriesIds = array(), $lang = LANGUAGE_ID)
470 $regionsList = static::getAllRegions($lang);
471 $getCountryNull = in_array(
"NULL", $countriesIds);
472 $filter = in_array(
"", $countriesIds) ? array() : array(($getCountryNull ?
"+" :
"").
"COUNTRY_ID" => $countriesIds);
474 $dbLocationsList = \CSaleLocation::GetList(
477 array(
"REGION_ID",
"COUNTRY_ID")
480 while($arRegion = $dbLocationsList->GetNext())
482 if($arRegion[
"REGION_ID"] <>
'' && $arRegion[
"REGION_ID"] !=
"0")
483 $regions[$arRegion[
"REGION_ID"]] = $regionsList[$arRegion[
"REGION_ID"]];
495 public static function getCities($countriesIds = array(), $regionsIds = array(), $lang )
498 $citiesList = static::getAllCities($lang);
499 $getRegionNull = in_array(
"NULL", $regionsIds);
500 $getRegionAll = in_array(
"", $regionsIds);
501 $getCountryNull = in_array(
"NULL", $countriesIds);
502 $getCountryAll = in_array(
"", $countriesIds);
504 $filter = in_array(
"", $regionsIds) ? array() : array(($getRegionNull ?
"+" :
"").
"REGION_ID" => $regionsIds);
506 foreach($countriesIds as $countryId)
508 if(($getRegionNull || $getRegionAll) && !$getCountryAll)
509 $filter[($getCountryNull ?
"+" :
"").
"COUNTRY_ID"] = $countryId;
511 $dbLocationsList = \CSaleLocation::GetList(
517 while($arCity = $dbLocationsList->GetNext())
518 if($arCity[
"CITY_ID"] <>
'')
519 $cities[$arCity[
"CITY_ID"]] = $citiesList[$arCity[
"CITY_ID"]];