From 3c8e043b8d0914c50b46d9eb38cd22737be232be Mon Sep 17 00:00:00 2001 From: Torben Freudewald Date: Fri, 30 Aug 2024 14:04:31 +0200 Subject: [PATCH] [TASK] Reset default query settings before creating query for selected pages --- Classes/Controller/ProjectController.php | 8 ++++--- .../Domain/Repository/ProjectRepository.php | 23 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Classes/Controller/ProjectController.php b/Classes/Controller/ProjectController.php index 713a099..9e5182c 100644 --- a/Classes/Controller/ProjectController.php +++ b/Classes/Controller/ProjectController.php @@ -35,13 +35,15 @@ public function listAction(?ProjectFilter $filter = null): ResponseInterface $hideCompletedProjects = (bool)$this->settings['hide_completed_projects']; } + $cObject = $this->configurationManager->getContentObject(); + $projects = $this->projectRepository->findByFilter( $hideCompletedProjects, $filter, - $this->configurationManager->getContentObject()->data['pages'] !== '' - ? GeneralUtility::intExplode(',', $this->configurationManager->getContentObject()->data['pages']) + $cObject?->getData('pages') !== '' + ? GeneralUtility::intExplode(',', $cObject?->getData('pages')) : [], - $this->configurationManager->getContentObject()->data['list_type'] === 'academicprojects_projectlistsingle' ? true : false + $$cObject?->getData('list_type') === 'academicprojects_projectlistsingle' ? true : false ); $categories = $this->categoryRepository->findAllApplicable($projects); diff --git a/Classes/Domain/Repository/ProjectRepository.php b/Classes/Domain/Repository/ProjectRepository.php index 8078848..cfce162 100644 --- a/Classes/Domain/Repository/ProjectRepository.php +++ b/Classes/Domain/Repository/ProjectRepository.php @@ -8,6 +8,7 @@ use FGTCLB\AcademicProjects\Domain\Enumeration\SortingOptions; use FGTCLB\AcademicProjects\Domain\Model\Dto\ProjectFilter; use TYPO3\CMS\Core\Type\Exception\InvalidEnumerationValueException; +use TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface; use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult; use TYPO3\CMS\Extbase\Persistence\Repository; @@ -25,7 +26,14 @@ public function findByFilter( ): QueryResult { $query = $this->createQuery(); + /** @var ConstraintInterface[] $constraints */ $constraints = []; + + if ($selected && !empty($pages)) { + $query->getQuerySettings()->setRespectStoragePage(false); + $constraints[] = $query->in('uid', $pages); + } + $constraints[] = $query->equals('doktype', Page::TYPE_ACEDEMIC_PROJECT); if ($filter) { @@ -37,24 +45,19 @@ public function findByFilter( } } } - if ($selected && !empty($pages)) { - $constraints[] = $query->in('uid', $pages); - } if ($hideCompletedProjects) { - $constraints[] = $query->logicalOr( + $constraints[] = $query->logicalOr([ $query->greaterThanOrEqual('tx_academicprojects_end_date', new \DateTime()), $query->equals('tx_academicprojects_end_date', 0) - ); + ]); } else { $query->getQuerySettings()->setIgnoreEnableFields(true); } - if (!empty($constraints)) { - $query->matching( - $query->logicalAnd($constraints) - ); - } + $query->matching( + $query->logicalAnd($constraints) + ); [$sortingField, $sortingDirection] = explode(' ', SortingOptions::__default); if ($filter && $filter->getSorting()) {