events/Classes/Service/DestinationDataImportService/LocationAssignment.php
Daniel Siepmann 00946af6ad
Properly handle latitude and longitude during Destination One import (#32)
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.
2023-07-06 12:39:47 +02:00

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;
}
}