From 889ebfba0fd932f2931ccd2f987ed3c564b60d4d Mon Sep 17 00:00:00 2001 From: Dirk Persky Date: Thu, 6 Jan 2022 15:31:08 +0100 Subject: [PATCH] recursiv cookie loading and version update --- Classes/Controller/CookieController.php | 5 ++- .../Domain/Repository/CookieRepository.php | 36 ++++++++++++++++--- ext_emconf.php | 2 +- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Classes/Controller/CookieController.php b/Classes/Controller/CookieController.php index cac7a51..f25ee66 100644 --- a/Classes/Controller/CookieController.php +++ b/Classes/Controller/CookieController.php @@ -12,6 +12,7 @@ namespace DirkPersky\DpCookieconsent\Controller; use ArrayObject; +use DirkPersky\DpCookieconsent\Domain\Repository\CookieRepository; use TYPO3\CMS\Core\Service\FlexFormService; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Annotation\Inject; @@ -19,8 +20,6 @@ use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; -use DirkPersky\DpCookieconsent\Domain\Repository\CookieRepository; - class CookieController extends ActionController { @@ -46,7 +45,7 @@ public function listAction() // parse Flexform $flexFormData = GeneralUtility::makeInstance(FlexFormService::class)->convertFlexFormContentToArray($cObj->data['pi_flexform']); // get Cookies - $cookies = $this->cookieRepository->findByPid($flexFormData['settings']['startingpoint']); + $cookies = $this->cookieRepository->findByPid($flexFormData['settings']['startingpoint'], $flexFormData['settings']['recursive']); // group cookies $grouped = new ArrayObject([]); foreach ($cookies as $cookie) { diff --git a/Classes/Domain/Repository/CookieRepository.php b/Classes/Domain/Repository/CookieRepository.php index 5cd51ec..0e36c9f 100644 --- a/Classes/Domain/Repository/CookieRepository.php +++ b/Classes/Domain/Repository/CookieRepository.php @@ -11,11 +11,13 @@ namespace DirkPersky\DpCookieconsent\Domain\Repository; +use TYPO3\CMS\Core\Database\QueryGenerator; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings; use TYPO3\CMS\Extbase\Persistence\QueryInterface; use TYPO3\CMS\Extbase\Persistence\Repository; + class CookieRepository extends Repository { // Order by BE sorting @@ -33,24 +35,50 @@ public function initializeObject() $this->setDefaultQuerySettings($querySettings); } + protected function getPidList($pidList, $recursive = '') + { + $recursive = (int)$recursive; + // if no recursiv return pidList + if ($recursive <= 0) return GeneralUtility::intExplode(',', $pidList); + // get DB query for getting pids + $queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class); + // explode list + $storagePids = GeneralUtility::intExplode(',', $pidList); + // build PID list + $recursiveStoragePids = $storagePids; + // loop pids and get tree + foreach ($storagePids as $startPid) { + if ($startPid >= 0) { + // get tree + $pids = $queryGenerator->getTreeList($startPid, $recursive); + // explode to array + $pids = GeneralUtility::intExplode(',', $pids); + // if not empty add to list + if (!empty($pids)) $recursiveStoragePids = array_merge($recursiveStoragePids, $pids); + } + } + // return array + return array_unique($recursiveStoragePids); + } + /** * @param integer $pid * @return mixed */ - public function findByPid(int $pid) + public function findByPid($pid, $recursive = '') { $query = $this->createQuery(); // set new storage PIDs - $query->getQuerySettings()->setStoragePageIds([$pid]); + $query->getQuerySettings()->setStoragePageIds($this->getPidList($pid, $recursive)); // execute statement return $query->execute(); } - public function findActiveScripts(int $pid) + public function findActiveScripts($pid, $recursive = 250) { $query = $this->createQuery(); // set new storage PIDs - $query->getQuerySettings()->setStoragePageIds([$pid]); + $query->getQuerySettings()->setStoragePageIds($this->getPidList($pid, $recursive)); // set filter $query->matching( $query->logicalAnd( diff --git a/ext_emconf.php b/ext_emconf.php index 24ef0c8..76ceb84 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -25,6 +25,6 @@ 'suggests' => [], ], 'state' => 'stable', // stable - 'version' => '11.4.1' + 'version' => '11.5.0' ];