mirror of
https://github.com/werkraum-media/events.git
synced 2024-11-27 01:36:11 +01:00
Daniel Siepmann
00946af6ad
They sometimes use a different separator. The code is adjusted to always use same separator and precision. That will prevent the same location from showing up multiple times due to different latitude and longitude values.
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Wrm\Events\Service\DestinationDataImportService;
|
|
|
|
use Wrm\Events\Domain\Model\Location;
|
|
use Wrm\Events\Domain\Repository\LocationRepository;
|
|
|
|
class LocationAssignment
|
|
{
|
|
/**
|
|
* @var LocationRepository
|
|
*/
|
|
private $repository;
|
|
|
|
public function __construct(
|
|
LocationRepository $repository
|
|
) {
|
|
$this->repository = $repository;
|
|
}
|
|
|
|
public function getLocation(array $event): ?Location
|
|
{
|
|
$newLocation = new Location(
|
|
$event['name'] ?? '',
|
|
$event['street'] ?? '',
|
|
$event['zip'] ?? '',
|
|
$event['city'] ?? '',
|
|
$event['district'] ?? '',
|
|
$event['country'] ?? '',
|
|
$event['phone'] ?? '',
|
|
$event['geo']['main']['latitude'] ?? '',
|
|
$event['geo']['main']['longitude'] ?? '',
|
|
-1
|
|
);
|
|
|
|
if ($newLocation->isValid() === false) {
|
|
return null;
|
|
}
|
|
|
|
$existingLocation = $this->repository->findOneByGlobalId($newLocation->getGlobalId());
|
|
|
|
if ($existingLocation === null) {
|
|
return $newLocation;
|
|
}
|
|
|
|
$existingLocation->updateFromLocation($newLocation);
|
|
|
|
return $existingLocation;
|
|
}
|
|
}
|