events/Classes/Service/DestinationDataImportService/LocationAssignment.php
Daniel Siepmann 81065f5c67
BREAKING: TYPO3 v12 support (#44)
* Migrated all fixtures to PHP.
* Removed version specific adjustments.
2023-11-27 10:04:42 +01:00

46 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace WerkraumMedia\Events\Service\DestinationDataImportService;
use WerkraumMedia\Events\Domain\Model\Location;
use WerkraumMedia\Events\Domain\Repository\LocationRepository;
final class LocationAssignment
{
public function __construct(
private readonly LocationRepository $repository
) {
}
public function getLocation(array $event): ?Location
{
$newLocation = new Location(
$event['name'] ?? '',
$event['street'] ?? '',
$event['zip'] ?? '',
$event['city'] ?? '',
$event['district'] ?? '',
$event['country'] ?? '',
$event['phone'] ?? '',
(string)($event['geo']['main']['latitude'] ?? ''),
(string)($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;
}
}