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 d8f65c3 commit 3c8e043
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
8 changes: 5 additions & 3 deletions Classes/Controller/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 13 additions & 10 deletions Classes/Domain/Repository/ProjectRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand All @@ -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()) {
Expand Down

0 comments on commit 3c8e043

Please sign in to comment.