The GPL headers named dreipunktnull and an old address and no longer match the license of the code. Co-Authored-By: Claude Opus 5.5 <[email protected]>
103 lines
2.9 KiB
PHP
103 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace EP\EpTheme\DataProcessing;
|
|
|
|
use EP\EpProducts\Service\ResellerDataService;
|
|
use EP\EpProducts\Traits\DbConnectionTrait;
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
|
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
|
|
|
|
class ContextProcessor implements DataProcessorInterface
|
|
{
|
|
use DbConnectionTrait;
|
|
|
|
/**
|
|
* @param ContentObjectRenderer $cObj
|
|
* @param array $contentObjectConfiguration
|
|
* @param array $processorConfiguration
|
|
* @param array $processedData
|
|
* @return array
|
|
* @throws \Doctrine\DBAL\DBALException
|
|
*/
|
|
public function process(
|
|
ContentObjectRenderer $cObj,
|
|
array $contentObjectConfiguration,
|
|
array $processorConfiguration,
|
|
array $processedData
|
|
) {
|
|
$data = $cObj->data;
|
|
$processedData['context'] = [];
|
|
$countryUid = (int) $data['tx_eptheme_context_country'];
|
|
if ($countryUid > 0) {
|
|
$processedData['context']['country'] = $this->getContextRecord($countryUid, 'tx_epproducts_domain_model_country');
|
|
}
|
|
$regionUid = (int) $data['tx_eptheme_context_region'];
|
|
if ($regionUid > 0) {
|
|
$processedData['context']['region'] = $this->getContextRecord($regionUid, 'tx_epproducts_domain_model_region');
|
|
}
|
|
if ($data['tx_eptheme_context_pacode'] ?? null) {
|
|
$processedData['context']['paCode'] = $data['tx_eptheme_context_pacode'];
|
|
} elseif ($paCode = $this->getPaCodeFromRequest()) {
|
|
$processedData['context']['paCode'] = $paCode;
|
|
}
|
|
|
|
return $processedData;
|
|
}
|
|
|
|
/**
|
|
* @return array|bool
|
|
* @throws \Doctrine\DBAL\DBALException
|
|
*/
|
|
private function getResellerData()
|
|
{
|
|
/** @var ResellerDataService $resellerService */
|
|
$resellerService = GeneralUtility::makeInstance(ResellerDataService::class);
|
|
return $resellerService->getResellerForCurrentDomain();
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
private function getPaCodeFromRequest()
|
|
{
|
|
$currentUri = GeneralUtility::getIndpEnv('REQUEST_URI');
|
|
$query = parse_url($currentUri, \PHP_URL_QUERY);
|
|
|
|
if (!$query) {
|
|
return '';
|
|
}
|
|
|
|
parse_str($query, $items);
|
|
|
|
if (array_key_exists('pa', $items)) {
|
|
return $items['pa'];
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* @param int $uid
|
|
* @param string $table
|
|
* @return array
|
|
* @throws \Doctrine\DBAL\DBALException
|
|
*/
|
|
private function getContextRecord($uid, $table)
|
|
{
|
|
$qb = $this->getDbConnection()->createQueryBuilder();
|
|
|
|
$query = $qb
|
|
->select('*')
|
|
->from($table)
|
|
->where('uid = :uid')
|
|
->andWhere('deleted = 0')
|
|
->andWhere('hidden = 0')
|
|
->setParameter('uid', $uid)
|
|
;
|
|
|
|
return $query->executeQuery()->fetchAssociative();
|
|
}
|
|
|
|
}
|