2021-08-18 13:54:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 Daniel Siepmann <coding@daniel-siepmann.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace WerkraumMedia\ThueCat\Domain\Import\Typo3Converter;
|
|
|
|
|
2023-11-30 13:52:23 +01:00
|
|
|
use Exception;
|
2022-12-15 12:41:35 +01:00
|
|
|
use TYPO3\CMS\Core\Log\Logger;
|
2023-11-30 13:52:23 +01:00
|
|
|
use TYPO3\CMS\Core\Log\LogManager;
|
2021-08-18 13:54:18 +02:00
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
|
2021-08-23 14:20:36 +02:00
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\AccessibilitySpecification;
|
2021-08-18 13:54:18 +02:00
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\Base;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\MapsToType;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\MediaObject;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\Minimum;
|
2022-09-29 14:10:36 +02:00
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\Organisation;
|
2021-08-18 13:54:18 +02:00
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\ParkingFacility;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\Place;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\Properties\ForeignReference;
|
2022-11-28 11:06:54 +01:00
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\Properties\OpeningHour;
|
2021-08-18 13:54:18 +02:00
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\Properties\PriceSpecification;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\TouristAttraction;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\TouristInformation;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\TouristMarketingCompany;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Entity\Town;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Importer;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Model\Entity;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Model\GenericEntity;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\ResolveForeignReference;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportConfiguration;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Repository\Backend\OrganisationRepository;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Repository\Backend\ParkingFacilityRepository;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Repository\Backend\TownRepository;
|
|
|
|
|
2022-12-15 12:41:35 +01:00
|
|
|
class GeneralConverter implements Converter
|
2021-08-18 13:54:18 +02:00
|
|
|
{
|
2022-12-15 12:41:35 +01:00
|
|
|
/**
|
|
|
|
* @var Logger
|
|
|
|
*/
|
|
|
|
private $logger;
|
|
|
|
|
2021-08-18 13:54:18 +02:00
|
|
|
/**
|
|
|
|
* @var ImportConfiguration
|
|
|
|
*/
|
|
|
|
private $importConfiguration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*/
|
|
|
|
private $classToTableMapping = [
|
|
|
|
TouristAttraction::class => 'tx_thuecat_tourist_attraction',
|
|
|
|
ParkingFacility::class => 'tx_thuecat_parking_facility',
|
|
|
|
Town::class => 'tx_thuecat_town',
|
|
|
|
TouristInformation::class => 'tx_thuecat_tourist_information',
|
|
|
|
TouristMarketingCompany::class => 'tx_thuecat_organisation',
|
2022-09-29 14:10:36 +02:00
|
|
|
Organisation::class => 'tx_thuecat_organisation',
|
2021-08-18 13:54:18 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
public function __construct(
|
2023-11-30 13:52:23 +01:00
|
|
|
private readonly ResolveForeignReference $resolveForeignReference,
|
|
|
|
private readonly Importer $importer,
|
|
|
|
private readonly LanguageHandling $languageHandling,
|
|
|
|
private readonly OrganisationRepository $organisationRepository,
|
|
|
|
private readonly TownRepository $townRepository,
|
|
|
|
private readonly ParkingFacilityRepository $parkingFacilityRepository,
|
|
|
|
private readonly NameExtractor $nameExtractor,
|
2022-12-15 12:41:35 +01:00
|
|
|
LogManager $logManager
|
2021-08-18 13:54:18 +02:00
|
|
|
) {
|
2022-12-15 12:41:35 +01:00
|
|
|
$this->logger = $logManager->getLogger(__CLASS__);
|
2021-08-18 13:54:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function convert(
|
|
|
|
MapsToType $entity,
|
|
|
|
ImportConfiguration $importConfiguration,
|
|
|
|
string $language
|
|
|
|
): ?Entity {
|
2021-09-08 15:07:33 +02:00
|
|
|
$this->importConfiguration = $importConfiguration;
|
|
|
|
|
2021-09-02 10:02:24 +02:00
|
|
|
if ($this->shouldConvert($entity, $importConfiguration, $language) === false) {
|
2021-08-18 13:54:18 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-09-02 10:02:24 +02:00
|
|
|
$converted = new GenericEntity(
|
2021-08-18 13:54:18 +02:00
|
|
|
$importConfiguration->getStoragePid(),
|
|
|
|
$this->getTableNameByEntityClass(get_class($entity)),
|
|
|
|
$this->languageHandling->getLanguageUidForString(
|
|
|
|
$importConfiguration->getStoragePid(),
|
|
|
|
$language
|
|
|
|
),
|
|
|
|
$entity->getId(),
|
|
|
|
$this->buildDataArrayFromEntity(
|
|
|
|
$entity,
|
|
|
|
$language
|
|
|
|
)
|
|
|
|
);
|
2021-09-02 10:02:24 +02:00
|
|
|
$this->logger->debug('Converted Entity', [
|
|
|
|
'remoteId' => $entity->getId(),
|
|
|
|
'storagePid' => $converted->getTypo3StoragePid(),
|
|
|
|
'table' => $converted->getTypo3DatabaseTableName(),
|
|
|
|
'language' => $converted->getTypo3SystemLanguageUid(),
|
|
|
|
]);
|
|
|
|
return $converted;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function shouldConvert(
|
|
|
|
MapsToType $entity,
|
|
|
|
ImportConfiguration $importConfiguration,
|
|
|
|
string $language
|
|
|
|
): bool {
|
2021-09-08 15:07:33 +02:00
|
|
|
$tableName = $this->getTableNameByEntityClass(get_class($entity));
|
|
|
|
|
2021-09-02 10:02:24 +02:00
|
|
|
if (!$entity instanceof Minimum) {
|
2022-12-15 12:41:35 +01:00
|
|
|
$this->logger->info('Skipped conversion of entity, got unexpected type', [
|
2021-09-02 10:02:24 +02:00
|
|
|
'expectedType' => Minimum::class,
|
|
|
|
'actualType' => get_class($entity),
|
|
|
|
]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($entity->hasName() === false) {
|
2022-12-15 12:41:35 +01:00
|
|
|
$this->logger->info('Skipped conversion of entity, had no name', [
|
2021-09-02 10:02:24 +02:00
|
|
|
'remoteId' => $entity->getId(),
|
|
|
|
]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$languageUid = $this->languageHandling->getLanguageUidForString(
|
|
|
|
$importConfiguration->getStoragePid(),
|
|
|
|
$language
|
|
|
|
);
|
|
|
|
if (
|
|
|
|
$languageUid > 0
|
|
|
|
&& isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) === false
|
|
|
|
) {
|
2022-12-15 12:41:35 +01:00
|
|
|
$this->logger->info('Skipped conversion of entity, table does not support translations', [
|
2021-09-02 10:02:24 +02:00
|
|
|
'remoteId' => $entity->getId(),
|
|
|
|
'requestedLanguage' => $language,
|
|
|
|
'resolvedLanguageUid' => $languageUid,
|
|
|
|
'resolvedTableName' => $tableName,
|
|
|
|
]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:07:33 +02:00
|
|
|
if ($tableName !== 'tx_thuecat_organisation' && $this->getManagerUid($entity) === '') {
|
2022-12-15 12:41:35 +01:00
|
|
|
$this->logger->info('Skipped conversion of entity, is not an organisation and no manager was available', [
|
2021-09-08 15:07:33 +02:00
|
|
|
'remoteId' => $entity->getId(),
|
|
|
|
]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-02 10:02:24 +02:00
|
|
|
return true;
|
2021-08-18 13:54:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getTableNameByEntityClass(string $className): string
|
|
|
|
{
|
|
|
|
$tableName = $this->classToTableMapping[$className] ?? '';
|
|
|
|
if ($tableName == '') {
|
2023-11-30 13:52:23 +01:00
|
|
|
throw new Exception('No table name configured for class ' . $className, 1629376990);
|
2021-08-18 13:54:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $tableName;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildDataArrayFromEntity(
|
|
|
|
Minimum $entity,
|
|
|
|
string $language
|
|
|
|
): array {
|
|
|
|
return [
|
|
|
|
'title' => $entity->getName(),
|
|
|
|
'description' => trim($entity->getDescription()),
|
|
|
|
'sanitation' => method_exists($entity, 'getSanitations') ? implode(',', $entity->getSanitations()) : '',
|
|
|
|
'managed_by' => $this->getManagerUid($entity),
|
|
|
|
'town' => $this->getTownUid($entity),
|
|
|
|
'media' => $entity instanceof Base ? $this->getMedia($entity, $language) : '',
|
|
|
|
|
|
|
|
'parking_facility_near_by' => $entity instanceof Base ? implode(',', $this->getParkingFacilitiesNearByUids($entity)) : '',
|
|
|
|
|
2022-11-28 11:06:54 +01:00
|
|
|
'opening_hours' => $entity instanceof Place ? $this->getOpeningHours($entity->getOpeningHoursSpecification()) : '',
|
|
|
|
'special_opening_hours' => $entity instanceof Place ? $this->getOpeningHours($entity->getSpecialOpeningHoursSpecification()) : '',
|
2021-08-18 13:54:18 +02:00
|
|
|
'address' => $entity instanceof Place ? $this->getAddress($entity) : '',
|
2022-11-29 11:50:22 +01:00
|
|
|
'url' => $entity->getUrls()[0] ?? '',
|
2021-08-18 13:54:18 +02:00
|
|
|
'offers' => $entity instanceof Place ? $this->getOffers($entity) : '',
|
|
|
|
'other_service' => method_exists($entity, 'getOtherServices') ? implode(',', $entity->getOtherServices()) : '',
|
|
|
|
'traffic_infrastructure' => method_exists($entity, 'getTrafficInfrastructures') ? implode(',', $entity->getTrafficInfrastructures()) : '',
|
|
|
|
'payment_accepted' => method_exists($entity, 'getPaymentsAccepted') ? implode(',', $entity->getPaymentsAccepted()) : '',
|
|
|
|
'distance_to_public_transport' => method_exists($entity, 'getDistanceToPublicTransport') ? $entity->getDistanceToPublicTransport() : '',
|
|
|
|
|
|
|
|
'slogan' => method_exists($entity, 'getSlogan') ? $entity->getSlogan() : '',
|
|
|
|
'start_of_construction' => method_exists($entity, 'getStartOfConstruction') ? $entity->getStartOfConstruction() : '',
|
|
|
|
'museum_service' => method_exists($entity, 'getMuseumServices') ? implode(',', $entity->getMuseumServices()) : '',
|
|
|
|
'architectural_style' => method_exists($entity, 'getArchitecturalStyles') ? implode(',', $entity->getArchitecturalStyles()) : '',
|
|
|
|
'digital_offer' => method_exists($entity, 'getDigitalOffers') ? implode(',', $entity->getDigitalOffers()) : '',
|
|
|
|
'photography' => method_exists($entity, 'getPhotographies') ? implode(',', $entity->getPhotographies()) : '',
|
|
|
|
'pets_allowed' => method_exists($entity, 'getPetsAllowed') ? $entity->getPetsAllowed() : '',
|
|
|
|
'is_accessible_for_free' => method_exists($entity, 'getIsAccessibleForFree') ? $entity->getIsAccessibleForFree() : '',
|
|
|
|
'public_access' => method_exists($entity, 'getPublicAccess') ? $entity->getPublicAccess() : '',
|
|
|
|
'available_languages' => method_exists($entity, 'getAvailableLanguages') ? implode(',', $entity->getAvailableLanguages()) : '',
|
2021-08-23 14:20:36 +02:00
|
|
|
|
|
|
|
'accessibility_specification' => $this->getAccessibilitySpecification($entity, $language),
|
2021-08-18 13:54:18 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getManagerUid(object $entity): string
|
|
|
|
{
|
|
|
|
if (
|
|
|
|
method_exists($entity, 'getManagedBy') === false
|
|
|
|
|| !$entity->getManagedBy() instanceof ForeignReference
|
|
|
|
) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->importer->importConfiguration(
|
|
|
|
ImportConfiguration::createFromBaseWithForeignReferences(
|
|
|
|
$this->importConfiguration,
|
|
|
|
[$entity->getManagedBy()]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$manager = $this->organisationRepository->findOneByRemoteId(
|
|
|
|
$entity->getManagedBy()->getId()
|
|
|
|
);
|
|
|
|
|
|
|
|
return $manager ? (string)$manager->getUid() : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getTownUid(object $entity): string
|
|
|
|
{
|
|
|
|
if (
|
|
|
|
$entity instanceof Town
|
|
|
|
|| method_exists($entity, 'getContainedInPlaces') === false
|
|
|
|
) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->importer->importConfiguration(
|
|
|
|
ImportConfiguration::createFromBaseWithForeignReferences(
|
|
|
|
$this->importConfiguration,
|
|
|
|
$entity->getContainedInPlaces(),
|
|
|
|
['thuecat:Town']
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$town = $this->townRepository->findOneByEntity($entity);
|
2023-11-30 13:52:23 +01:00
|
|
|
return $town ? (string)$town->getUid() : '';
|
2021-08-18 13:54:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getParkingFacilitiesNearByUids(Base $entity): array
|
|
|
|
{
|
|
|
|
if (method_exists($entity, 'getParkingFacilitiesNearBy') === false) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->importer->importConfiguration(
|
|
|
|
ImportConfiguration::createFromBaseWithForeignReferences(
|
|
|
|
$this->importConfiguration,
|
|
|
|
$entity->getParkingFacilitiesNearBy()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->getUids(
|
|
|
|
$this->parkingFacilityRepository->findByEntity($entity)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-23 14:20:36 +02:00
|
|
|
private function getAccessibilitySpecification(
|
|
|
|
object $entity,
|
|
|
|
string $language
|
|
|
|
): string {
|
|
|
|
if (
|
|
|
|
method_exists($entity, 'getAccessibilitySpecification') === false
|
|
|
|
|| $entity->getAccessibilitySpecification() === null
|
|
|
|
) {
|
|
|
|
return '{}';
|
|
|
|
}
|
|
|
|
|
|
|
|
$access = $this->resolveForeignReference->resolve(
|
|
|
|
$entity->getAccessibilitySpecification(),
|
|
|
|
$language
|
|
|
|
);
|
|
|
|
if (!$access instanceof AccessibilitySpecification) {
|
|
|
|
return '{}';
|
|
|
|
}
|
|
|
|
|
|
|
|
$cert = $access->getAccessibilityCertification();
|
|
|
|
|
|
|
|
$result = json_encode(array_filter([
|
|
|
|
'accessibilityCertificationStatus' => $cert ? $cert->getAccessibilityCertificationStatus() : '',
|
|
|
|
'certificationAccessibilityDeaf' => $cert ? $cert->getCertificationAccessibilityDeaf() : '',
|
|
|
|
'certificationAccessibilityMental' => $cert ? $cert->getCertificationAccessibilityMental() : '',
|
|
|
|
'certificationAccessibilityPartiallyDeaf' => $cert ? $cert->getCertificationAccessibilityPartiallyDeaf() : '',
|
|
|
|
'certificationAccessibilityPartiallyVisual' => $cert ? $cert->getCertificationAccessibilityPartiallyVisual() : '',
|
|
|
|
'certificationAccessibilityVisual' => $cert ? $cert->getCertificationAccessibilityVisual() : '',
|
|
|
|
'certificationAccessibilityWalking' => $cert ? $cert->getCertificationAccessibilityWalking() : '',
|
|
|
|
'certificationAccessibilityWheelchair' => $cert ? $cert->getCertificationAccessibilityWheelchair() : '',
|
|
|
|
'accessibilitySearchCriteria' => $access->getAccessibilitySearchCriteria(),
|
|
|
|
'shortDescriptionAccessibilityAllGenerations' => $access->getShortDescriptionAccessibilityAllGenerations(),
|
|
|
|
'shortDescriptionAccessibilityAllergic' => $access->getShortDescriptionAccessibilityAllergic(),
|
|
|
|
'shortDescriptionAccessibilityDeaf' => $access->getShortDescriptionAccessibilityDeaf(),
|
|
|
|
'shortDescriptionAccessibilityMental' => $access->getShortDescriptionAccessibilityMental(),
|
|
|
|
'shortDescriptionAccessibilityVisual' => $access->getShortDescriptionAccessibilityVisual(),
|
|
|
|
'shortDescriptionAccessibilityWalking' => $access->getShortDescriptionAccessibilityWalking(),
|
|
|
|
]));
|
|
|
|
if ($result === false || $result === '[]') {
|
|
|
|
return '{}';
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2021-08-18 13:54:18 +02:00
|
|
|
private function getMedia(
|
|
|
|
Base $entity,
|
|
|
|
string $language
|
|
|
|
): string {
|
|
|
|
$data = [];
|
2022-11-30 10:35:44 +01:00
|
|
|
$idMainImage = '';
|
2021-08-18 13:54:18 +02:00
|
|
|
|
|
|
|
if ($entity->getPhoto() instanceof ForeignReference) {
|
|
|
|
$photo = $this->resolveForeignReference->resolve(
|
|
|
|
$entity->getPhoto(),
|
|
|
|
$language
|
|
|
|
);
|
|
|
|
if ($photo instanceof MediaObject) {
|
2022-11-30 10:35:44 +01:00
|
|
|
$idMainImage = $photo->getId();
|
2022-11-24 11:05:13 +01:00
|
|
|
$data[] = $this->getSingleMedia($photo, true, $language);
|
2021-08-18 13:54:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($entity->getImages() as $image) {
|
|
|
|
$image = $this->resolveForeignReference->resolve(
|
|
|
|
$image,
|
|
|
|
$language
|
|
|
|
);
|
2022-11-30 10:35:44 +01:00
|
|
|
// Do not import main image again as image.
|
|
|
|
// It is very likely that the same resource is provided as photo and image.
|
|
|
|
if ($image instanceof MediaObject && $image->getId() !== $idMainImage) {
|
2022-11-24 11:05:13 +01:00
|
|
|
$data[] = $this->getSingleMedia($image, false, $language);
|
2021-08-18 13:54:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return json_encode($data) ?: '';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getSingleMedia(
|
|
|
|
MediaObject $mediaObject,
|
2022-11-24 11:05:13 +01:00
|
|
|
bool $mainImage,
|
|
|
|
string $language
|
2021-08-18 13:54:18 +02:00
|
|
|
): array {
|
|
|
|
return [
|
|
|
|
'mainImage' => $mainImage,
|
|
|
|
'type' => $mediaObject->getType(),
|
|
|
|
'title' => $mediaObject->getName(),
|
|
|
|
'description' => $mediaObject->getDescription(),
|
2021-08-31 08:10:46 +02:00
|
|
|
'url' => $mediaObject->getUrls()[0] ?? '',
|
2022-11-24 11:05:13 +01:00
|
|
|
'author' => $this->nameExtractor->extract($mediaObject->getAuthor(), $language),
|
2021-08-18 13:54:18 +02:00
|
|
|
'copyrightYear' => $mediaObject->getCopyrightYear(),
|
|
|
|
'license' => [
|
|
|
|
'type' => $mediaObject->getLicense(),
|
|
|
|
'author' => $mediaObject->getLicenseAuthor(),
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-11-28 11:06:54 +01:00
|
|
|
/**
|
|
|
|
* @param OpeningHour[] $openingHours
|
|
|
|
*/
|
|
|
|
private function getOpeningHours(array $openingHours): string
|
2021-08-18 13:54:18 +02:00
|
|
|
{
|
|
|
|
$data = [];
|
|
|
|
|
2022-11-28 11:06:54 +01:00
|
|
|
foreach ($openingHours as $openingHour) {
|
2021-09-02 15:13:18 +02:00
|
|
|
$data[] = array_filter([
|
2021-08-18 13:54:18 +02:00
|
|
|
'opens' => $openingHour->getOpens()->format('H:i:s'),
|
|
|
|
'closes' => $openingHour->getCloses()->format('H:i:s'),
|
|
|
|
'from' => $openingHour->getValidFrom() ?? '',
|
|
|
|
'through' => $openingHour->getValidThrough() ?? '',
|
|
|
|
'daysOfWeek' => $openingHour->getDaysOfWeek(),
|
2021-09-02 15:13:18 +02:00
|
|
|
]);
|
2021-08-18 13:54:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return json_encode($data) ?: '';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getAddress(Place $entity): string
|
|
|
|
{
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
$address = $entity->getAddress();
|
|
|
|
if ($address !== null) {
|
|
|
|
$data += [
|
|
|
|
'street' => $address->getStreetAddress(),
|
|
|
|
'zip' => $address->getPostalCode(),
|
|
|
|
'city' => $address->getAddressLocality(),
|
|
|
|
'email' => $address->getEmail(),
|
|
|
|
'phone' => $address->getTelephone(),
|
|
|
|
'fax' => $address->getFaxNumber(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
$geo = $entity->getGeo();
|
|
|
|
if ($geo !== null) {
|
|
|
|
$data += [
|
|
|
|
'geo' => [
|
|
|
|
'latitude' => $geo->getLatitude(),
|
|
|
|
'longitude' => $geo->getLongitude(),
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return json_encode($data) ?: '';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getOffers(Place $entity): string
|
|
|
|
{
|
|
|
|
$data = [];
|
|
|
|
foreach ($entity->getOffers() as $offer) {
|
|
|
|
$data[] = [
|
2022-09-29 14:33:19 +02:00
|
|
|
'types' => $offer->getOfferTypes(),
|
2021-08-18 13:54:18 +02:00
|
|
|
'title' => $offer->getName(),
|
|
|
|
'description' => $offer->getDescription(),
|
|
|
|
'prices' => array_map([$this, 'getPrice'], $offer->getPrices()),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return json_encode($data) ?: '';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPrice(PriceSpecification $priceSpecification): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'title' => $priceSpecification->getName(),
|
|
|
|
'description' => $priceSpecification->getDescription(),
|
|
|
|
'price' => $priceSpecification->getPrice(),
|
|
|
|
'currency' => $priceSpecification->getCurrency(),
|
2021-08-31 14:01:07 +02:00
|
|
|
'rule' => implode(',', $priceSpecification->getCalculationRules()),
|
2021-08-18 13:54:18 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getUids(?QueryResultInterface $result): array
|
|
|
|
{
|
|
|
|
if ($result === null) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$uids = [];
|
|
|
|
foreach ($result as $entry) {
|
|
|
|
$uids[] = $entry->getUid();
|
|
|
|
}
|
|
|
|
return $uids;
|
|
|
|
}
|
|
|
|
}
|