Update
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
<?
|
||||
namespace Bitrix\Location\Entity\Address\Normalizer;
|
||||
|
||||
class NullNormalizer implements INormalizer
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function normalize($string)
|
||||
{
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user