This commit is contained in:
root
2025-11-13 19:52:28 +03:00
parent 8aeeb05b7d
commit 807dec3b6c
4646 changed files with 163445 additions and 626017 deletions

View File

@@ -1,45 +0,0 @@
<?php
namespace Bitrix\Location\Common;
use Bitrix\Main\Loader;
/**
* Class RegionFinder
* @package Bitrix\Location\Common
*/
class RegionFinder
{
/**
* @return string
* @throws \Bitrix\Main\LoaderException
*/
public static function getCurrentRegion(): string
{
$result = null;
if (Loader::includeModule('bitrix24'))
{
$licensePrefix = \CBitrix24::getLicensePrefix();
if ($licensePrefix !== false)
{
$result = (string)$licensePrefix;
}
}
elseif (Loader::includeModule('intranet'))
{
$result = (string)\CIntranetUtils::getPortalZone();
}
elseif (defined('LANGUAGE_ID'))
{
$result = LANGUAGE_ID;
}
if (!$result)
{
$result = 'en';
}
return $result;
}
}

View File

@@ -1,13 +0,0 @@
<?
namespace Bitrix\Location\Entity\Address\Normalizer;
class NullNormalizer implements INormalizer
{
/**
* @inheritdoc
*/
public function normalize($string)
{
return $string;
}
}

View File

@@ -1,43 +0,0 @@
<?php
namespace Bitrix\Location\Entity\Location;
use Bitrix\Location\Entity\Location;
/**
* Calculate distance between two Locations
* Class DistanceCalculator
* @package Bitrix\Location\Entity\Location
*/
class DistanceCalculator
{
private const EARTH_RADIUS = 6371;
/**
* @param Location $location1
* @param Location $location2
* @return bool|float
*/
public function calculate(Location $location1, Location $location2)
{
if(
empty($location1->getLatitude())
|| empty($location1->getLongitude())
|| empty($location2->getLatitude())
|| empty($location2->getLongitude())
)
{
return false;
}
$lat1 = $location1->getLatitude() / 180 * M_PI;
$lat2 = $location2->getLatitude() / 180 * M_PI;
$lon1 = $location1->getLongitude() / 180 * M_PI;
$lon2 = $location2->getLongitude() / 180 * M_PI;
return (float)acos(sin($lat1)*sin($lat2)
+ cos($lat1)*cos($lat2)
* cos($lon2-$lon1))
* self::EARTH_RADIUS;
}
}

View File

@@ -1,79 +0,0 @@
<?php
namespace Bitrix\Location\Entity\Location\Factory;
use Bitrix\Location\Entity\Address\Converter\OrmConverter;
use Bitrix\Location\Entity\Location;
use Bitrix\Location\Model\EO_Hierarchy_Collection;
use Bitrix\Location\Model\EO_Location;
use Bitrix\Location\Model\EO_Location_Collection;
final class OrmFactory
{
public static function createLocation(EO_Location $ormLocation, string $languageId): Location
{
$result = (new Location())
->setId($ormLocation->getId())
->setCode($ormLocation->getCode())
->setExternalId($ormLocation->getExternalId())
->setSourceCode($ormLocation->getSourceCode())
->setType(($ormLocation->getType()))
->setLatitude($ormLocation->getLatitude())
->setLongitude($ormLocation->getLongitude());
if($fields = $ormLocation->getFields())
{
/** @var Location\Field $field */
foreach($fields as $field)
{
$result->setFieldValue($field->getType(), $field->getValue());
}
}
foreach($ormLocation->getName() as $ormName)
{
if($ormName->getLanguageId() === $languageId || $ormName->getLanguageId() == '')
{
$result->setName($ormName->getName());
$result->setLanguageId($ormName->getLanguageId());
if($ormName->getLanguageId() === $languageId)
{
break;
}
}
}
return $result;
}
public static function createCollection(EO_Location_Collection $collection, string $language)
{
$result = new Location\Collection();
foreach ($collection as $item)
{
$result->addItem(
self::createLocation($item, $language)
);
}
return $result;
}
public static function createParentCollection(EO_Hierarchy_Collection $ormHierarchy, string $languageId)
{
$result = new Location\Parents();
foreach ($ormHierarchy as $item)
{
$result->addItem(
self::createLocation(
$item->getAncestor(),
$languageId
)
);
}
return $result;
}
}

View File

@@ -1,27 +0,0 @@
<?php
namespace Bitrix\Location\Entity\Location;
use Bitrix\Location\Entity\Location\Collection;
/**
* Interface ILocationRelated
* @package Bitrix\Location
*/
interface IHasLocation
{
/**
* @return int
*/
public function getId(): int;
/**
* @return string
*/
public function getLocationEntityType(): string;
/**
* @return Collection
*/
public function getLocationCollection(): Collection;
}

View File

@@ -1,15 +0,0 @@
<?php
namespace Bitrix\Location\Source\Google\Requesters;
/**
* Interface RequesterBase
* @package Bitrix\Location\Source\Google\Requesters
*/
final class AutocompleteRequester extends BaseRequester
{
protected $url = 'https://maps.googleapis.com/maps/api/place/autocomplete/json';
protected $requiredFields = ['input', 'language', 'key'];
protected $fieldsToEncode = ['input'];
}

View File

@@ -6,10 +6,9 @@ use Bitrix\Location\Entity\Source;
use Bitrix\Location\Repository\Location\IRepository;
use Bitrix\Location\Source\Osm\Api\Api;
use Bitrix\Location\StaticMap\ISourceStaticMapService;
use Bitrix\Main\Application;
use Bitrix\Main\ModuleManager;
use Bitrix\Main\Context;
use Bitrix\Main\License\UrlProvider;
use Bitrix\Main\Config\Option;
/**
* Class OsmSource
@@ -20,12 +19,10 @@ final class OsmSource extends Source
{
public const API_PATH = '/api';
private UrlProvider $urlProvider;
private TokenRequester $tokenRequester;
public function __construct()
{
$this->urlProvider = new UrlProvider();
$this->tokenRequester = (new TokenRequester())->setSource($this);
}
@@ -67,7 +64,7 @@ final class OsmSource extends Source
return [
'serviceUrl' => $this->getOsmApiUrl(),
'mapServiceUrl' => $this->getOsmMapServiceUrl(),
'token' => $token ? $token->getToken() : null,
'token' => $token?->getToken(),
'useGeocodingService' => true,
'hostName' => $this->getOsmHostName()
];
@@ -125,22 +122,12 @@ final class OsmSource extends Source
public function getOsmServiceUrl(): ?string
{
if (defined('LOCATION_OSM_SERVICE_URL') && LOCATION_OSM_SERVICE_URL)
{
return (string)LOCATION_OSM_SERVICE_URL;
}
return 'https://osm-' . $this->getSubDomainSuffix() . '-002.' . $this->urlProvider->getTechDomain();
return Option::get('location', 'osm_service_url');
}
public function getOsmMapServiceUrl(): ?string
{
if (defined('LOCATION_OSM_MAP_SERVICE_URL') && LOCATION_OSM_MAP_SERVICE_URL)
{
return (string)LOCATION_OSM_MAP_SERVICE_URL;
}
return 'https://osm-' . $this->getSubDomainSuffix() . '-001.' . $this->urlProvider->getTechDomain();
return Option::get('location', 'osm_map_service_url');
}
public function getOsmToken(): ?Token
@@ -158,11 +145,4 @@ final class OsmSource extends Source
return !$this->tokenRequester->hasLicenseIssues();
}
private function getSubDomainSuffix(): string
{
$region = Application::getInstance()->getLicense()->getRegion();
return in_array($region, ['ru', 'by', 'kz', 'uz'], true) ? 'ru' : 'de';
}
}