Allow to filter by organizer (#6)

Relates: #10409
This commit is contained in:
Daniel Siepmann 2023-04-03 08:54:48 +02:00 committed by GitHub
parent d682c14252
commit 5721a1d399
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 0 deletions

View file

@ -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;

View file

@ -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']);

View file

@ -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());
}

View file

@ -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
-----

View file

@ -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());
}
}