Browse Source
Allows to import entity of type TouristAttraction. Right now only in German, as this is most important. Add output of tourist attraction via custom content element.pull/4/head
49 changed files with 2667 additions and 133 deletions
@ -0,0 +1,86 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace WerkraumMedia\ThueCat\Domain\Import\Converter; |
||||
|
||||
/* |
||||
* 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. |
||||
*/ |
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility; |
||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser; |
||||
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection; |
||||
use WerkraumMedia\ThueCat\Domain\Import\Model\GenericEntity; |
||||
use WerkraumMedia\ThueCat\Domain\Repository\Backend\OrganisationRepository; |
||||
use WerkraumMedia\ThueCat\Domain\Repository\Backend\TownRepository; |
||||
|
||||
class TouristAttraction implements Converter |
||||
{ |
||||
private Parser $parser; |
||||
private OrganisationRepository $organisationRepository; |
||||
private TownRepository $townRepository; |
||||
|
||||
public function __construct( |
||||
Parser $parser, |
||||
OrganisationRepository $organisationRepository, |
||||
TownRepository $townRepository |
||||
) { |
||||
$this->parser = $parser; |
||||
$this->organisationRepository = $organisationRepository; |
||||
$this->townRepository = $townRepository; |
||||
} |
||||
|
||||
public function convert(array $jsonLD): EntityCollection |
||||
{ |
||||
$storagePid = 10; |
||||
$manager = $this->organisationRepository->findOneByRemoteId($this->parser->getManagerId($jsonLD)); |
||||
$town = $this->townRepository->findOneByRemoteIds($this->parser->getContainedInPlaceIds($jsonLD)); |
||||
$entities = GeneralUtility::makeInstance(EntityCollection::class); |
||||
|
||||
foreach ($this->parser->getLanguages($jsonLD) as $language) { |
||||
if ($language !== 'de') { |
||||
continue; |
||||
} |
||||
$systemLanguageUid = 0; |
||||
|
||||
$entity = GeneralUtility::makeInstance( |
||||
GenericEntity::class, |
||||
$storagePid, |
||||
'tx_thuecat_tourist_attraction', |
||||
$systemLanguageUid, |
||||
$this->parser->getId($jsonLD), |
||||
[ |
||||
'title' => $this->parser->getTitle($jsonLD, $language), |
||||
'description' => $this->parser->getDescription($jsonLD, $language), |
||||
'managed_by' => $manager ? $manager->getUid() : 0, |
||||
'town' => $town ? $town->getUid() : 0, |
||||
'opening_hours' => json_encode($this->parser->getOpeningHours($jsonLD)), |
||||
] |
||||
); |
||||
$entities->add($entity); |
||||
} |
||||
|
||||
return $entities; |
||||
} |
||||
|
||||
public function canConvert(array $type): bool |
||||
{ |
||||
return array_search('schema:TouristAttraction', $type) !== false; |
||||
} |
||||
} |
@ -0,0 +1,140 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace WerkraumMedia\ThueCat\Domain\Import\JsonLD; |
||||
|
||||
/* |
||||
* 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. |
||||
*/ |
||||
|
||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\OpeningHours; |
||||
|
||||
class Parser |
||||
{ |
||||
private OpeningHours $openingHours; |
||||
|
||||
public function __construct( |
||||
OpeningHours $openingHours |
||||
) { |
||||
$this->openingHours = $openingHours; |
||||
} |
||||
public function getId(array $jsonLD): string |
||||
{ |
||||
return $jsonLD['@id']; |
||||
} |
||||
|
||||
public function getTitle(array $jsonLD, string $language = ''): string |
||||
{ |
||||
return $this->getValueForLanguage($jsonLD['schema:name'], $language); |
||||
} |
||||
|
||||
public function getDescription(array $jsonLD, string $language = ''): string |
||||
{ |
||||
return $this->getValueForLanguage($jsonLD['schema:description'], $language); |
||||
} |
||||
|
||||
public function getManagerId(array $jsonLD): string |
||||
{ |
||||
return $jsonLD['thuecat:contentResponsible']['@id']; |
||||
} |
||||
|
||||
/** |
||||
* @return string[] |
||||
*/ |
||||
public function getContainedInPlaceIds(array $jsonLD): array |
||||
{ |
||||
return array_map(function (array $place) { |
||||
return $place['@id']; |
||||
}, $jsonLD['schema:containedInPlace']); |
||||
} |
||||
|
||||
public function getOpeningHours(array $jsonLD): array |
||||
{ |
||||
return $this->openingHours->get($jsonLD); |
||||
} |
||||
|
||||
/** |
||||
* @return string[] |
||||
*/ |
||||
public function getLanguages(array $jsonLD): array |
||||
{ |
||||
if (isset($jsonLD['schema:availableLanguage']) === false) { |
||||
return []; |
||||
} |
||||
|
||||
$languages = $jsonLD['schema:availableLanguage']; |
||||
|
||||
$languages = array_filter($languages, function (array $language) { |
||||
return isset($language['@type']) |
||||
&& $language['@type'] === 'thuecat:Language' |
||||
; |
||||
}); |
||||
|
||||
$languages = array_map(function (array $language) { |
||||
$language = $language['@value']; |
||||
|
||||
if ($language === 'thuecat:German') { |
||||
return 'de'; |
||||
} |
||||
if ($language === 'thuecat:English') { |
||||
return 'en'; |
||||
} |
||||
if ($language === 'thuecat:French') { |
||||
return 'fr'; |
||||
} |
||||
|
||||
throw new \Exception('Unsupported language "' . $language . '".', 1612367481); |
||||
}, $languages); |
||||
|
||||
return $languages; |
||||
} |
||||
|
||||
private function getValueForLanguage( |
||||
array $property, |
||||
string $language |
||||
): string { |
||||
if ( |
||||
$this->doesLanguageMatch($property, $language) |
||||
&& isset($property['@value']) |
||||
) { |
||||
return $property['@value']; |
||||
} |
||||
|
||||
foreach ($property as $languageEntry) { |
||||
if ( |
||||
is_array($languageEntry) |
||||
&& $this->doesLanguageMatch($languageEntry, $language) |
||||
) { |
||||
return $languageEntry['@value']; |
||||
} |
||||
} |
||||
|
||||
return ''; |
||||
} |
||||
|
||||
private function doesLanguageMatch(array $property, string $language): bool |
||||
{ |
||||
return isset($property['@language']) |
||||
&& ( |
||||
$property['@language'] === $language |
||||
|| $language === '' |
||||
) |
||||
; |
||||
} |
||||
} |
@ -0,0 +1,102 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser; |
||||
|
||||
/* |
||||
* 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. |
||||
*/ |
||||
|
||||
class OpeningHours |
||||
{ |
||||
public function get(array $jsonLD): array |
||||
{ |
||||
$openingHours = $jsonLD['schema:openingHoursSpecification'] ?? []; |
||||
if ($openingHours === []) { |
||||
return []; |
||||
} |
||||
|
||||
if (isset($openingHours['@id'])) { |
||||
return [$this->parseSingleEntry($openingHours)]; |
||||
} |
||||
|
||||
return array_values(array_map([$this, 'parseSingleEntry'], $openingHours)); |
||||
} |
||||
|
||||
private function parseSingleEntry(array $openingHour): array |
||||
{ |
||||
return [ |
||||
'opens' => $this->getOpens($openingHour), |
||||
'closes' => $this->getCloses($openingHour), |
||||
'from' => $this->getFrom($openingHour), |
||||
'through' => $this->getThrough($openingHour), |
||||
'daysOfWeek' => $this->getDaysOfWeek($openingHour), |
||||
]; |
||||
} |
||||
|
||||
private function getOpens(array $openingHour): string |
||||
{ |
||||
return $openingHour['schema:opens']['@value'] ?? ''; |
||||
} |
||||
|
||||
private function getCloses(array $openingHour): string |
||||
{ |
||||
return $openingHour['schema:closes']['@value'] ?? ''; |
||||
} |
||||
|
||||
private function getFrom(array $openingHour): ?\DateTimeImmutable |
||||
{ |
||||
if (isset($openingHour['schema:validFrom']['@value'])) { |
||||
return new \DateTimeImmutable($openingHour['schema:validFrom']['@value']); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
private function getThrough(array $openingHour): ?\DateTimeImmutable |
||||
{ |
||||
if (isset($openingHour['schema:validThrough']['@value'])) { |
||||
return new \DateTimeImmutable($openingHour['schema:validThrough']['@value']); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
private function getDaysOfWeek(array $openingHour): array |
||||
{ |
||||
if (isset($openingHour['schema:dayOfWeek']['@value'])) { |
||||
return [$this->getDayOfWeekString($openingHour['schema:dayOfWeek']['@value'])]; |
||||
} |
||||
$daysOfWeek = array_map(function ($dayOfWeek) { |
||||
return $this->getDayOfWeekString($dayOfWeek['@value']); |
||||
}, $openingHour['schema:dayOfWeek'] ?? []); |
||||
|
||||
sort($daysOfWeek); |
||||
return $daysOfWeek; |
||||
} |
||||
|
||||
private function getDayOfWeekString(string $jsonLDValue): string |
||||
{ |
||||
return str_replace( |
||||
'schema:', |
||||
'', |
||||
$jsonLDValue |
||||
); |
||||
} |
||||
} |
@ -0,0 +1,66 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace WerkraumMedia\ThueCat\Domain\Import\Model; |
||||
|
||||
/* |
||||
* 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. |
||||
*/ |
||||
|
||||
class EntityCollection |
||||
{ |
||||
/** |
||||
* @var Entity[] |
||||
*/ |
||||
private array $entities = []; |
||||
|
||||
public function add(Entity $entity): void |
||||
{ |
||||
$this->entities[] = $entity; |
||||
} |
||||
|
||||
/** |
||||
* @return Entity[] |
||||
*/ |
||||
public function getEntities(): array |
||||
{ |
||||
return $this->entities; |
||||
} |
||||
|
||||
public function getDefaultLanguageEntity(): ?Entity |
||||
{ |
||||
foreach ($this->entities as $entity) { |
||||
if ($entity->isForDefaultLanguage()) { |
||||
return $entity; |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* @return Entity[] |
||||
*/ |
||||
public function getTranslatedEntities(): array |
||||
{ |
||||
return array_filter($this->entities, function (Entity $entity) { |
||||
return $entity->isTranslation(); |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,127 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace WerkraumMedia\ThueCat\Domain\Model\Frontend; |
||||
|
||||
/* |
||||
* 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. |
||||
*/ |
||||
|
||||
class OpeningHour |
||||
{ |
||||
private string $opens; |
||||
private string $closes; |
||||
private array $daysOfWeek; |
||||
private ?\DateTimeImmutable $from; |
||||
private ?\DateTimeImmutable $through; |
||||
|
||||
private function __construct( |
||||
string $opens, |
||||
string $closes, |
||||
array $daysOfWeek, |
||||
?\DateTimeImmutable $from, |
||||
?\DateTimeImmutable $through |
||||
) { |
||||
$this->opens = $opens; |
||||
$this->closes = $closes; |
||||
$this->daysOfWeek = $daysOfWeek; |
||||
$this->from = $from; |
||||
$this->through = $through; |
||||
} |
||||
|
||||
public static function createFromArray(array $rawData): self |
||||
{ |
||||
$from = null; |
||||
if (isset($rawData['from'])) { |
||||
$timeZone = new \DateTimeZone($rawData['from']['timezone']); |
||||
$from = new \DateTimeImmutable($rawData['from']['date'], $timeZone); |
||||
} |
||||
$through = null; |
||||
if (isset($rawData['through'])) { |
||||
$timeZone = new \DateTimeZone($rawData['through']['timezone']); |
||||
$through = new \DateTimeImmutable($rawData['through']['date'], $timeZone); |
||||
} |
||||
|
||||
return new self( |
||||
$rawData['opens'] ?? '', |
||||
$rawData['closes'] ?? '', |
||||
$rawData['daysOfWeek'] ?? '', |
||||
$from, |
||||
$through |
||||
); |
||||
} |
||||
|
||||
public function getOpens(): string |
||||
{ |
||||
return $this->opens; |
||||
} |
||||
|
||||
public function getCloses(): string |
||||
{ |
||||
return $this->closes; |
||||
} |
||||
|
||||
public function getDaysOfWeek(): array |
||||
{ |
||||
return $this->daysOfWeek; |
||||
} |
||||
|
||||
public function getDaysOfWeekWithMondayFirstWeekDay(): array |
||||
{ |
||||
return $this->sortedDaysOfWeek([ |
||||
'Monday', |
||||
'Tuesday', |
||||
'Wednesday', |
||||
'Thursday', |
||||
'Friday', |
||||
'Saturday', |
||||
'Sunday', |
||||
]); |
||||
} |
||||
|
||||
public function getFrom(): ?\DateTimeImmutable |
||||
{ |
||||
return $this->from; |
||||
} |
||||
|
||||
public function getThrough(): ?\DateTimeImmutable |
||||
{ |
||||
return $this->through; |
||||
} |
||||
|
||||
private function sortedDaysOfWeek(array $sorting): array |
||||
{ |
||||
if ($this->daysOfWeek === []) { |
||||
return []; |
||||
} |
||||
|
||||
$days = []; |
||||
|
||||
foreach ($sorting as $weekDay) { |
||||
$position = array_search($weekDay, $this->daysOfWeek); |
||||
if ($position === false) { |
||||
continue; |
||||
} |
||||
|
||||
$days[] = $this->daysOfWeek[$position]; |
||||
} |
||||
|
||||
return $days; |
||||
} |
||||
} |
@ -0,0 +1,75 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace WerkraumMedia\ThueCat\Domain\Model\Frontend; |
||||
|
||||
/* |
||||
* 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. |
||||
*/ |
||||
|
||||
use TYPO3\CMS\Core\Type\TypeInterface; |
||||
|
||||
/** |
||||
* @implements \Iterator<int, OpeningHour> |
||||
*/ |
||||
class OpeningHours implements TypeInterface, \Iterator |
||||
{ |
||||
private string $serialized = ''; |
||||
private array $array = []; |
||||
private int $position = 0; |
||||
|
||||
public function __construct(string $serialized) |
||||
{ |
||||
$this->serialized = $serialized; |
||||
$this->array = array_map( |
||||
[OpeningHour::class, 'createFromArray'], |
||||
json_decode($serialized, true) |
||||
); |
||||
} |
||||
|
||||
public function __toString(): string |
||||
{ |
||||
return $this->serialized; |
||||
} |
||||
|
||||
public function current(): OpeningHour |
||||
{ |
||||
return $this->array[$this->position]; |
||||
} |
||||
|
||||
public function next(): void |
||||
{ |
||||
++$this->position; |
||||
} |
||||
|
||||
public function key(): int |
||||
{ |
||||
return $this->position; |
||||
} |
||||
|
||||
public function valid(): bool |
||||
{ |
||||
return isset($this->array[$this->position]); |
||||
} |
||||
|
||||
public function rewind(): void |
||||
{ |
||||
$this->position = 0; |
||||
} |
||||
} |
@ -0,0 +1,54 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace WerkraumMedia\ThueCat\Domain\Model\Frontend; |
||||
|
||||
/* |
||||
* 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. |
||||
*/ |
||||
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; |
||||
|
||||
class TouristAttraction extends AbstractEntity |
||||
{ |
||||
protected string $title = ''; |
||||
protected string $description = ''; |
||||
protected ?OpeningHours $openingHours = null; |
||||
protected ?Town $town = null; |
||||
|
||||
public function getTitle(): string |
||||
{ |
||||
return $this->title; |
||||
} |
||||
|
||||
public function getDescription(): string |
||||
{ |
||||
return $this->description; |
||||
} |
||||
|
||||
public function getOpeningHours(): ?OpeningHours |
||||
{ |
||||
return $this->openingHours; |
||||
} |
||||
|
||||
public function getTown(): ?Town |
||||
{ |
||||
return $this->town; |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace WerkraumMedia\ThueCat\Domain\Model\Frontend; |
||||
|
||||
/* |
||||
* 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. |
||||
*/ |
||||
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; |
||||
|
||||
class Town extends AbstractEntity |
||||
{ |
||||
protected string $title = ''; |
||||
protected string $description = ''; |
||||
|
||||
public function getTitle(): string |
||||
{ |
||||
return $this->title; |
||||
} |
||||
|
||||
public function getDescription(): string |
||||
{ |
||||
return $this->description; |
||||
} |
||||
} |
@ -0,0 +1,85 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace WerkraumMedia\ThueCat\Frontend\DataProcessing; |
||||
|
||||
/* |
||||
* 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. |
||||
*/ |
||||
|
||||
use TYPO3\CMS\Core\Database\Connection; |
||||
use TYPO3\CMS\Core\Database\ConnectionPool; |
||||
use TYPO3\CMS\Core\Utility\GeneralUtility; |
||||
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper; |
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; |
||||
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; |
||||
|
||||
class ResolveEntities implements DataProcessorInterface |
||||
{ |
||||
private ConnectionPool $connectionPool; |
||||
private DataMapper $dataMapper; |
||||
|
||||
public function __construct( |
||||
ConnectionPool $connectionPool, |
||||
DataMapper $dataMapper |
||||
) { |
||||
$this->connectionPool = $connectionPool; |
||||
$this->dataMapper = $dataMapper; |
||||
} |
||||
|
||||
public function process( |
||||
ContentObjectRenderer $cObj, |
||||
array $contentObjectConfiguration, |
||||
array $processorConfiguration, |
||||
array $processedData |
||||
) { |
||||
$as = $cObj->stdWrapValue('as', $processorConfiguration, 'entities'); |
||||
$table = $cObj->stdWrapValue('table', $processorConfiguration, ''); |
||||
$uids = $cObj->stdWrapValue('uids', $processorConfiguration, ''); |
||||
|
||||
$uids = GeneralUtility::intExplode(',', $uids); |
||||
if ($uids === [] || $table === '') { |
||||
return $processedData; |
||||
} |
||||
|
||||
$processedData[$as] = $this->resolveEntities($table, $uids); |
||||
return $processedData; |
||||
} |
||||
|
||||
private function resolveEntities(string $table, array $uids): array |
||||
{ |
||||
$targetType = '\WerkraumMedia\ThueCat\Domain\Model\Frontend\\' . $this->convertTableToEntity($table); |
||||
|
||||
$queryBuilder = $this->connectionPool->getQueryBuilderForTable($table); |
||||
$queryBuilder->select('*'); |
||||
$queryBuilder->from($table); |
||||
$queryBuilder->where($queryBuilder->expr()->in( |
||||
'uid', |
||||
$queryBuilder->createNamedParameter($uids, Connection::PARAM_INT_ARRAY) |
||||
)); |
||||
|
||||
return $this->dataMapper->map($targetType, $queryBuilder->execute()->fetchAll()); |
||||
} |
||||
|
||||
private function convertTableToEntity(string $table): string |
||||
{ |
||||
$entityPart = str_replace('tx_thuecat_', '', $table); |
||||
return GeneralUtility::underscoredToUpperCamelCase($entityPart); |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
<?php |
||||
|
||||
defined('TYPO3') or die(); |
||||
|
||||
(static function (string $extensionKey, string $tableName) { |
||||
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile( |
||||
$extensionKey, |
||||
'Configuration/TypoScript/', |
||||
'ThüCAT' |
||||
); |
||||
})( |
||||
\WerkraumMedia\ThueCat\Extension::EXTENSION_KEY, |
||||
'sys_template' |
||||
); |
@ -0,0 +1,18 @@
|
||||
<?php |
||||
|
||||
defined('TYPO3') or die(); |
||||
|
||||
(static function (string $extensionKey, string $tableName) { |
||||
$languagePath = \WerkraumMedia\ThueCat\Extension::getLanguagePath() |
||||
. 'locallang_tca.xlf:' . $tableName; |
||||
|
||||
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItemGroup( |
||||
$tableName, |
||||
'CType', |
||||
\WerkraumMedia\ThueCat\Extension::TT_CONTENT_GROUP, |
||||
$languagePath . '.group' |
||||
); |
||||
})( |
||||
\WerkraumMedia\ThueCat\Extension::EXTENSION_KEY, |
||||
'tt_content' |
||||
); |
@ -0,0 +1,63 @@
|
||||
<?php |
||||
|
||||
defined('TYPO3') or die(); |
||||
|
||||
(static function (string $extensionKey, string $tableName, string $cType) { |
||||
$languagePath = \WerkraumMedia\ThueCat\Extension::getLanguagePath() |
||||
. 'locallang_tca.xlf:' . $tableName . '.' . $cType; |
||||
|
||||
\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TCA'][$tableName], [ |
||||
'ctrl' => [ |
||||
// TODO: Add Icon |
||||
// 'typeicon_classes' => [ |
||||
// $cType => '', |
||||
// ], |
||||
], |
||||
'types' => [ |
||||
$cType => [ |
||||
'showitem' => |
||||
'--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,' |
||||
. '--palette--;;general,' |
||||
. '--palette--;;headers,' |
||||
. 'records,' |
||||
. '--div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.appearance,' |
||||
. '--palette--;;frames,' |
||||
. '--palette--;;appearanceLinks,' |
||||
. '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language,' |
||||
. '--palette--;;language,' |
||||
. '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,' |
||||
. '--palette--;;hidden,' |
||||
. '--palette--;;access,' |
||||
. '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:categories,' |
||||
. '--div--;LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_category.tabs.category,' |
||||
. 'categories,' |
||||
. '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:notes,' |
||||
. 'rowDescription,' |
||||
. '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:extended', |
||||
'columnsOverrides' => [ |
||||
'records' => [ |
||||
'config' => [ |
||||
'allowed' => 'tx_thuecat_tourist_attraction', |
||||
], |
||||
], |
||||
], |
||||
], |
||||
], |
||||
]); |
||||
|
||||
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem( |
||||
$tableName, |
||||
'CType', |
||||
[ |
||||
$languagePath, |
||||
$cType, |
||||
// TODO: Add Icon |
||||
'', |
||||
\WerkraumMedia\ThueCat\Extension::TT_CONTENT_GROUP, |
||||
] |
||||
); |
||||
})( |
||||
\WerkraumMedia\ThueCat\Extension::EXTENSION_KEY, |
||||
'tt_content', |
||||
'thuecat_tourist_attraction' |
||||
); |
@ -0,0 +1,89 @@
|
||||
<?php |
||||
|
||||
defined('TYPO3') or die(); |
||||
|
||||
return (static function (string $extensionKey, string $tableName) { |
||||
$languagePath = \WerkraumMedia\ThueCat\Extension::getLanguagePath() . 'locallang_tca.xlf:' . $tableName; |
||||
|
||||
return [ |
||||
'ctrl' => [ |
||||
'label' => 'title', |
||||
'default_sortby' => 'title', |
||||
'tstamp' => 'tstamp', |
||||
'crdate' => 'crdate', |
||||
'cruser_id' => 'cruser_id', |
||||
'title' => $languagePath, |
||||
'enablecolumns' => [ |
||||
'disabled' => 'disable', |
||||
], |
||||
'searchFields' => 'title, description', |
||||
], |
||||
'columns' => [ |
||||
'title' => [ |
||||
'label' => $languagePath . '.title', |
||||
'config' => [ |
||||
'type' => 'input', |
||||
'size' => 20, |
||||
'max' => 255, |
||||
'readOnly' => true, |
||||
], |
||||
], |
||||
'description' => [ |
||||
'label' => $languagePath . '.description', |
||||
'config' => [ |
||||
'type' => 'text', |
||||
'readOnly' => true, |
||||
], |
||||
], |
||||
'opening_hours' => [ |
||||
'label' => $languagePath . '.opening_hours', |
||||
'config' => [ |
||||
'type' => 'text', |
||||
'readOnly' => true, |
||||
], |
||||
], |
||||
'remote_id' => [ |
||||
'label' => $languagePath . '.remote_id', |
||||
'config' => [ |
||||
'type' => 'input', |
||||
'readOnly' => true, |
||||
], |
||||
], |
||||
'town' => [ |
||||
'label' => $languagePath . '.town', |
||||
'config' => [ |
||||
'type' => 'select', |
||||
'renderType' => 'selectSingle', |
||||
'foreign_table' => 'tx_thuecat_town', |
||||
'items' => [ |
||||
[ |
||||
$languagePath . '.town.unkown', |
||||
0, |
||||
], |
||||
], |
||||
'readOnly' => true, |
||||
], |
||||
], |
||||
'managed_by' => [ |
||||
'label' => $languagePath . '.managed_by', |
||||
'config' => [ |
||||
'type' => 'select', |
||||
'renderType' => 'selectSingle', |
||||
'foreign_table' => 'tx_thuecat_organisation', |
||||
'items' => [ |
||||
[ |
||||
$languagePath . '.managed_by.unkown', |
||||
0, |
||||
], |
||||
], |
||||
'readOnly' => true, |
||||
], |
||||
], |
||||
], |
||||
'types' => [ |
||||
'0' => [ |
||||
'showitem' => 'title, description, opening_hours, remote_id, town, managed_by', |
||||
], |
||||
], |
||||
]; |
||||
})(\WerkraumMedia\ThueCat\Extension::EXTENSION_KEY, 'tx_thuecat_tourist_attraction'); |
@ -0,0 +1,6 @@
|
||||
lib.thuecatContentElement =< lib.contentElement |
||||
lib.thuecatContentElement { |
||||
templateRootPaths { |
||||
9999 = EXT:thuecat/Resources/Private/Templates/Frontend/ContentElement/ |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
tt_content { |
||||
thuecat_tourist_attraction =< lib.thuecatContentElement |
||||
thuecat_tourist_attraction { |
||||
templateName = TouristAttraction |
||||
dataProcessing { |
||||
10 = WerkraumMedia\ThueCat\Frontend\DataProcessing\ResolveEntities |
||||
10 { |
||||
table = tx_thuecat_tourist_attraction |
||||
uids.data = field:records |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,6 @@
|
||||
lib.thuecatContentElement =< lib.contentElement |
||||
lib.thuecatContentElement { |
||||
templateRootPaths { |
||||
9999 = EXT:thuecat/Resources/Private/Templates/Frontend/ContentElement/ |
||||
} |
||||
} |
@ -0,0 +1 @@
|
||||
@import 'EXT:thuecat/Configuration/TypoScript/Rendering/*.typoscript' |