Skip to content

Commit

Permalink
[TASK] Reset default query settings before creating query for selecte…
Browse files Browse the repository at this point in the history
…d pages
  • Loading branch information
torben-fr committed Aug 30, 2024
1 parent 3d71ea3 commit 2f95b76
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Classes/Domain/Repository/ProjectRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use FGTCLB\AcademicProjects\Domain\Enumeration\SortingOptions;
use FGTCLB\AcademicProjects\Domain\Model\Dto\ProjectFilter;
use TYPO3\CMS\Core\Type\Exception\InvalidEnumerationValueException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\Repository;

class ProjectRepository extends Repository
Expand All @@ -22,9 +24,17 @@ public function findByFilter(
array $pages = [],
bool $selected = false
): QueryResult {
$query = $this->createQuery();

$constraints = [];

if ($selected && !empty($pages)) {
$defaultQuerySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
$this->setDefaultQuerySettings($defaultQuerySettings->setRespectStoragePage(false));
$query = $this->createQuery();
$constraints[] = $query->in('uid', $pages);
} else {
$query = $this->createQuery();
}

$constraints[] = $query->equals('doktype', Page::TYPE_ACEDEMIC_PROJECT);

if ($filter) {
Expand All @@ -36,9 +46,6 @@ public function findByFilter(
}
}
}
if ($selected && !empty($pages)) {
$constraints[] = $query->in('uid', $pages);
}

$query->matching(
$query->logicalAnd($constraints)
Expand Down

0 comments on commit 2f95b76

Please sign in to comment.