diff --git a/Classes/Domain/Model/Dto/DateDemand.php b/Classes/Domain/Model/Dto/DateDemand.php index 7c1cd66..0e4ed65 100644 --- a/Classes/Domain/Model/Dto/DateDemand.php +++ b/Classes/Domain/Model/Dto/DateDemand.php @@ -51,6 +51,11 @@ class DateDemand */ protected $locations = []; + /** + * @var int[] + */ + protected $organizers = []; + /** * @var bool */ @@ -213,6 +218,19 @@ class DateDemand $this->locations = array_map('intval', $locations); } + /** + * @return int[] + */ + public function getOrganizers(): array + { + return $this->organizers; + } + + public function setOrganizers(array $organizers): void + { + $this->organizers = array_values(array_map('intval', $organizers)); + } + public function getHighlight(): bool { return $this->highlight; diff --git a/Classes/Domain/Model/Dto/DateDemandFactory.php b/Classes/Domain/Model/Dto/DateDemandFactory.php index 352968d..c73a2bf 100644 --- a/Classes/Domain/Model/Dto/DateDemandFactory.php +++ b/Classes/Domain/Model/Dto/DateDemandFactory.php @@ -66,6 +66,9 @@ class DateDemandFactory if (!empty($settings['locations'])) { $demand->setLocations(GeneralUtility::intExplode(',', (string)$settings['locations'], true)); } + if (!empty($settings['organizers'])) { + $demand->setOrganizers(GeneralUtility::intExplode(',', (string)$settings['organizers'], true)); + } if (!empty($settings['categories'])) { $demand->setCategories((string)$settings['categories']); } @@ -118,6 +121,10 @@ class DateDemandFactory $instance->setLocations($submittedValues['locations']); } + if (isset($submittedValues['organizers']) && is_array($submittedValues['organizers'])) { + $instance->setOrganizers($submittedValues['organizers']); + } + $instance->setRegions(GeneralUtility::intExplode(',', $submittedValues['region'] ?? '', true)); if (isset($submittedValues['regions']) && is_array($submittedValues['regions'])) { $instance->setRegions($submittedValues['regions']); diff --git a/Classes/Domain/Repository/DateRepository.php b/Classes/Domain/Repository/DateRepository.php index 5f842a4..4a190d7 100644 --- a/Classes/Domain/Repository/DateRepository.php +++ b/Classes/Domain/Repository/DateRepository.php @@ -61,6 +61,10 @@ class DateRepository extends Repository $constraints['locations'] = $query->in('event.location', $demand->getLocations()); } + if ($demand->getOrganizers() !== []) { + $constraints['organizer'] = $query->in('event.organizer', $demand->getOrganizers()); + } + if ($demand->getRegion() !== '') { $constraints['region'] = $query->equals('event.region', $demand->getRegion()); } diff --git a/Documentation/Changelog/3.3.0.rst b/Documentation/Changelog/3.3.0.rst index 5d12a71..08cce13 100644 --- a/Documentation/Changelog/3.3.0.rst +++ b/Documentation/Changelog/3.3.0.rst @@ -11,6 +11,12 @@ Features * Add PHP 8.2 support. +* Added option to filter dates by organizers. + The new setting works the same way as existing ``locations``. + Add a comma separated list of UIDs. + This can be used via FlexForms or TypoScript. + Can also be used as filter from request, where an array of UIDs is expected. + Fixes ----- diff --git a/Tests/Unit/Domain/Model/Dto/DateDemandFactoryTest.php b/Tests/Unit/Domain/Model/Dto/DateDemandFactoryTest.php index 7282308..b13b74e 100644 --- a/Tests/Unit/Domain/Model/Dto/DateDemandFactoryTest.php +++ b/Tests/Unit/Domain/Model/Dto/DateDemandFactoryTest.php @@ -473,4 +473,42 @@ class DateDemandFactoryTest extends TestCase yield '0 as string' => ['highlight' => '0']; yield 'empty string' => ['highlight' => '']; } + + /** + * @test + */ + public function returnsOrganizersFromSettings(): void + { + $typoScriptService = $this->createStub(TypoScriptService::class); + + $subject = new DateDemandFactory( + $typoScriptService + ); + $result = $subject->fromSettings([ + 'organizers' => '10, ,0, 2,', + ]); + + self::assertSame([10, 0, 2], $result->getOrganizers()); + } + + /** + * @test + */ + public function returnsOrganizersFromRequest(): void + { + $typoScriptService = $this->createStub(TypoScriptService::class); + + $subject = new DateDemandFactory( + $typoScriptService + ); + $result = $subject->createFromRequestValues( + [ + 'organizers' => [10, 0, 2], + ], + [ + ] + ); + + self::assertSame([10, 0, 2], $result->getOrganizers()); + } }