diff --git a/Classes/Domain/Model/Dto/Search.php b/Classes/Domain/Model/Dto/Search.php index 6b119ebd..7a915eb3 100644 --- a/Classes/Domain/Model/Dto/Search.php +++ b/Classes/Domain/Model/Dto/Search.php @@ -8,7 +8,10 @@ class Search { protected $fullText = ''; - protected $category = 0; + /** + * @var int[] + */ + protected $categories = []; public function getFullText(): string { @@ -20,14 +23,40 @@ public function setFullText(string $fullText): void $this->fullText = $fullText; } + /** + * @return int + * + * @deprecated Use categories instead! + */ public function getCategory(): int { - return $this->category; + return $this->categories[0] ?? 0; } + /** + * @param int $category + * + * @deprecated Use categories instead! + */ public function setCategory(int $category): void { - $this->category = $category; + $this->categories = [$category]; + } + + /** + * @return int[] + */ + public function getCategories(): array + { + return $this->categories; + } + + /** + * @param int[] $categories + */ + public function setCategories(array $categories): void + { + $this->categories = $categories; } public function isSearch(): bool diff --git a/Classes/Domain/Repository/EventRepository.php b/Classes/Domain/Repository/EventRepository.php index e6383a84..211fcda5 100644 --- a/Classes/Domain/Repository/EventRepository.php +++ b/Classes/Domain/Repository/EventRepository.php @@ -47,8 +47,12 @@ public function findBySearch(Search $search) $query->like('description', '%' . $search->getFullText() . '%'), ]); } - if ($search->getCategory()) { - $constraints['categories'] = $query->contains('categories', $search->getCategory()); + if ($search->getCategories()) { + $categories = []; + foreach ($search->getCategories() as $category) { + $categories[] = $query->contains('categories', $category); + } + $constraints['categories'] = $query->logicalOr($categories); } $query->matching($query->logicalAnd($constraints)); $rows = $query->execute(true); diff --git a/Classes/EventListener/DefaultEventSearchListener.php b/Classes/EventListener/DefaultEventSearchListener.php index 93b8808f..2de15f91 100644 --- a/Classes/EventListener/DefaultEventSearchListener.php +++ b/Classes/EventListener/DefaultEventSearchListener.php @@ -6,6 +6,7 @@ use HDNET\Calendarize\Domain\Repository\EventRepository; use HDNET\Calendarize\Event\IndexRepositoryFindBySearchEvent; use HDNET\Calendarize\Register; +use TYPO3\CMS\Core\Utility\MathUtility; class DefaultEventSearchListener { @@ -48,8 +49,14 @@ protected function getSearchDto(IndexRepositoryFindBySearchEvent $event): Search $customSearch = $event->getCustomSearch(); $search = new Search(); - $search->setFullText(trim((string)$customSearch['fullText'] ?? '')); - $search->setCategory((int)$customSearch['category'] ?? 0); + $search->setFullText(trim((string)($customSearch['fullText'] ?? ''))); + if (\is_array($customSearch['categories'])) { + $categories = array_map('intval', $customSearch['categories']); + $search->setCategories($categories); + } elseif (MathUtility::canBeInterpretedAsInteger($customSearch['category'] ?? '')) { + // Fallback for previous mode + $search->setCategories([(int)$customSearch['category']]); + } return $search; }