2021-02-03 17:20:01 +01:00
|
|
|
<?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;
|
2021-02-16 17:12:47 +01:00
|
|
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
|
2021-02-03 17:20:01 +01:00
|
|
|
|
|
|
|
class ResolveEntities implements DataProcessorInterface
|
|
|
|
{
|
|
|
|
private ConnectionPool $connectionPool;
|
|
|
|
private DataMapper $dataMapper;
|
2021-02-16 17:12:47 +01:00
|
|
|
private TypoScriptFrontendController $tsfe;
|
2021-02-03 17:20:01 +01:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
ConnectionPool $connectionPool,
|
|
|
|
DataMapper $dataMapper
|
|
|
|
) {
|
|
|
|
$this->connectionPool = $connectionPool;
|
|
|
|
$this->dataMapper = $dataMapper;
|
2021-02-16 17:12:47 +01:00
|
|
|
$this->tsfe = $GLOBALS['TSFE'];
|
2021-02-03 17:20:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function process(
|
|
|
|
ContentObjectRenderer $cObj,
|
|
|
|
array $contentObjectConfiguration,
|
|
|
|
array $processorConfiguration,
|
|
|
|
array $processedData
|
|
|
|
) {
|
2021-02-18 08:49:27 +01:00
|
|
|
if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) {
|
|
|
|
return $processedData;
|
|
|
|
}
|
|
|
|
|
2021-02-03 17:20:01 +01:00
|
|
|
$as = $cObj->stdWrapValue('as', $processorConfiguration, 'entities');
|
2021-02-16 17:12:47 +01:00
|
|
|
$tableName = $cObj->stdWrapValue('table', $processorConfiguration, '');
|
2021-02-03 17:20:01 +01:00
|
|
|
$uids = $cObj->stdWrapValue('uids', $processorConfiguration, '');
|
|
|
|
|
|
|
|
$uids = GeneralUtility::intExplode(',', $uids);
|
2021-02-16 17:12:47 +01:00
|
|
|
if ($uids === [] || $tableName === '') {
|
2021-02-03 17:20:01 +01:00
|
|
|
return $processedData;
|
|
|
|
}
|
|
|
|
|
2021-02-16 17:12:47 +01:00
|
|
|
$processedData[$as] = $this->resolveEntities($tableName, $uids);
|
2021-02-03 17:20:01 +01:00
|
|
|
return $processedData;
|
|
|
|
}
|
|
|
|
|
2021-02-16 17:12:47 +01:00
|
|
|
private function resolveEntities(string $tableName, array $uids): array
|
2021-02-03 17:20:01 +01:00
|
|
|
{
|
2021-02-16 17:12:47 +01:00
|
|
|
$targetType = '\WerkraumMedia\ThueCat\Domain\Model\Frontend\\' . $this->convertTableToEntity($tableName);
|
2021-02-03 17:20:01 +01:00
|
|
|
|
2021-02-16 17:12:47 +01:00
|
|
|
$queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
|
2021-02-03 17:20:01 +01:00
|
|
|
$queryBuilder->select('*');
|
2021-02-16 17:12:47 +01:00
|
|
|
$queryBuilder->from($tableName);
|
2021-02-03 17:20:01 +01:00
|
|
|
$queryBuilder->where($queryBuilder->expr()->in(
|
|
|
|
'uid',
|
|
|
|
$queryBuilder->createNamedParameter($uids, Connection::PARAM_INT_ARRAY)
|
|
|
|
));
|
|
|
|
|
2021-02-16 17:12:47 +01:00
|
|
|
$rows = [];
|
|
|
|
foreach ($queryBuilder->execute() as $row) {
|
|
|
|
$row = $this->tsfe->sys_page->getLanguageOverlay($tableName, $row);
|
|
|
|
if (is_array($row)) {
|
|
|
|
$rows[] = $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->dataMapper->map($targetType, $rows);
|
2021-02-03 17:20:01 +01:00
|
|
|
}
|
|
|
|
|
2021-02-16 17:12:47 +01:00
|
|
|
private function convertTableToEntity(string $tableName): string
|
2021-02-03 17:20:01 +01:00
|
|
|
{
|
2021-02-16 17:12:47 +01:00
|
|
|
$entityPart = str_replace('tx_thuecat_', '', $tableName);
|
2021-02-03 17:20:01 +01:00
|
|
|
return GeneralUtility::underscoredToUpperCamelCase($entityPart);
|
|
|
|
}
|
|
|
|
}
|