Skip to content

Commit

Permalink
recursiv cookie loading and version update
Browse files Browse the repository at this point in the history
  • Loading branch information
DirkPersky committed Jan 6, 2022
1 parent b0a6813 commit 889ebfb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
5 changes: 2 additions & 3 deletions Classes/Controller/CookieController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
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;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

use DirkPersky\DpCookieconsent\Domain\Repository\CookieRepository;

class CookieController extends ActionController
{

Expand All @@ -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) {
Expand Down
36 changes: 32 additions & 4 deletions Classes/Domain/Repository/CookieRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
'suggests' => [],
],
'state' => 'stable', // stable
'version' => '11.4.1'
'version' => '11.5.0'
];

0 comments on commit 889ebfb

Please sign in to comment.