mirror of
https://github.com/werkraum-media/events.git
synced 2024-12-22 13:06:10 +01:00
Extend demand and provide search to templates
This commit is contained in:
parent
6e6e914e36
commit
3b4ecbe6ce
7 changed files with 338 additions and 11 deletions
|
@ -91,9 +91,14 @@ class DateController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
public function listAction(): void
|
||||
/**
|
||||
* @param array $search
|
||||
*/
|
||||
public function listAction(array $search = []): void
|
||||
{
|
||||
if (
|
||||
if ($search !== []) {
|
||||
$demand = DateDemand::createFromRequestValues($search, $this->settings);
|
||||
} elseif (
|
||||
($this->request->hasArgument('searchword') && $this->request->getArgument('searchword') != '')
|
||||
|| ($this->request->hasArgument('region') && $this->request->getArgument('region') != '')
|
||||
|| ($this->request->hasArgument('start') && $this->request->getArgument('start') != '')
|
||||
|
@ -104,17 +109,24 @@ class DateController extends AbstractController
|
|||
} else {
|
||||
$demand = $this->demandFactory->fromSettings($this->settings);
|
||||
}
|
||||
$dates = $this->dateRepository->findByDemand($demand);
|
||||
$this->view->assign('dates', $this->dateRepository->findByDemand($demand));
|
||||
|
||||
$this->view->assignMultiple([
|
||||
'search' => $search,
|
||||
'demand' => $demand,
|
||||
'dates' => $this->dateRepository->findByDemand($demand),
|
||||
]);
|
||||
}
|
||||
|
||||
public function searchAction(): void
|
||||
/**
|
||||
* @param array $search
|
||||
*/
|
||||
public function searchAction(array $search = []): void
|
||||
{
|
||||
$arguments = GeneralUtility::_GET('tx_events_datelist') ?? [];
|
||||
$arguments = GeneralUtility::_GET('tx_events_datelist') ?? $search;
|
||||
if (is_array($arguments) === false) {
|
||||
$arguments = [];
|
||||
}
|
||||
if (isset($arguments['events_search'])) {
|
||||
if (isset($arguments['events_search']) && is_array($arguments['events_search'])) {
|
||||
$arguments += $arguments['events_search'];
|
||||
unset($arguments['events_search']);
|
||||
}
|
||||
|
@ -125,6 +137,7 @@ class DateController extends AbstractController
|
|||
'start' => $arguments['start'] ?? '',
|
||||
'end' => $arguments['end'] ?? '',
|
||||
'considerDate' => $arguments['considerDate'] ?? '',
|
||||
'search' => $search,
|
||||
'demand' => DateDemand::createFromRequestValues($arguments, $this->settings),
|
||||
'regions' => $this->regionRepository->findAll(),
|
||||
'categories' => $this->categoryRepository->findAllCurrentlyAssigned(),
|
||||
|
|
|
@ -66,6 +66,11 @@ class Date extends AbstractEntity
|
|||
$this->start = $start;
|
||||
}
|
||||
|
||||
public function getHasUsefulStartTime(): bool
|
||||
{
|
||||
return $this->getStart()->format('H:i') !== '00:00';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime end
|
||||
*/
|
||||
|
@ -83,7 +88,15 @@ class Date extends AbstractEntity
|
|||
$this->end = $end;
|
||||
}
|
||||
|
||||
public function getHasUsefulEndTime(): bool
|
||||
{
|
||||
return $this->getEnd()->format('H:i') !== '23:59';
|
||||
}
|
||||
|
||||
public function getEndsOnSameDay(): bool
|
||||
{
|
||||
return $this->getStart()->format('Y-m-d') === $this->getEnd()->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Event
|
||||
|
|
|
@ -22,7 +22,7 @@ class DateDemand
|
|||
protected $categories = '';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @var int[]
|
||||
*/
|
||||
protected $userCategories = [];
|
||||
|
||||
|
@ -38,9 +38,15 @@ class DateDemand
|
|||
|
||||
/**
|
||||
* @var string
|
||||
* Legacy, superceeded by regions which allows multi select / filter.
|
||||
*/
|
||||
protected $region = '';
|
||||
|
||||
/**
|
||||
* @var int[]
|
||||
*/
|
||||
protected $regions = [];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
|
@ -99,6 +105,9 @@ class DateDemand
|
|||
$instance->setSynonyms($settings['synonyms'] ?? []);
|
||||
|
||||
$instance->setRegion($submittedValues['region'] ?? '');
|
||||
if (isset($submittedValues['regions']) && is_array($submittedValues['regions'])) {
|
||||
$instance->setRegions($submittedValues['regions']);
|
||||
}
|
||||
|
||||
if ($submittedValues['highlight'] ?? false) {
|
||||
$instance->setHighlight($settings['highlight'] ?? false);
|
||||
|
@ -114,8 +123,8 @@ class DateDemand
|
|||
$instance->setConsiderDate((bool)$submittedValues['considerDate']);
|
||||
}
|
||||
|
||||
if (is_array($submittedValues['userCategories'])) {
|
||||
$instance->userCategories = array_map('intval', $submittedValues['userCategories']);
|
||||
if (isset($submittedValues['userCategories']) && is_array($submittedValues['userCategories'])) {
|
||||
$instance->setUserCategories($submittedValues['userCategories']);
|
||||
}
|
||||
|
||||
$instance->setSortBy($settings['sortByDate'] ?? '');
|
||||
|
@ -154,6 +163,17 @@ class DateDemand
|
|||
return $this->categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $categories
|
||||
*/
|
||||
public function setUserCategories(array $categories): void
|
||||
{
|
||||
$this->userCategories = array_map('intval', $categories);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
public function getUserCategories(): array
|
||||
{
|
||||
return $this->userCategories;
|
||||
|
@ -194,6 +214,19 @@ class DateDemand
|
|||
$this->region = $region;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
public function getRegions(): array
|
||||
{
|
||||
return $this->regions;
|
||||
}
|
||||
|
||||
public function setRegions(array $regions): void
|
||||
{
|
||||
$this->regions = array_map('intval', $regions);
|
||||
}
|
||||
|
||||
public function getHighlight(): bool
|
||||
{
|
||||
return $this->highlight;
|
||||
|
|
47
Documentation/Changelog/2.5.0.rst
Normal file
47
Documentation/Changelog/2.5.0.rst
Normal file
|
@ -0,0 +1,47 @@
|
|||
2.5.0
|
||||
=====
|
||||
|
||||
Breaking
|
||||
--------
|
||||
|
||||
Nothing
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Respect search in list and search action of date controller.
|
||||
The argument prefix has to be ``search``.
|
||||
The value is used to create the demand and filter the dates.
|
||||
The value is also provided to the view.
|
||||
|
||||
That uses Extbase native argument mapping by name. No need for hardcoded plugin
|
||||
namespaces or to provide some arguments from request to the view.
|
||||
|
||||
The search is a plain array and therefore allows to pass whatever the templates
|
||||
provide.
|
||||
|
||||
* Extend ``DateDemand``. It now supports filtering by request values for Regions.
|
||||
|
||||
* Extend ``Date`` to provide helpful methods for templates.
|
||||
New methods:
|
||||
|
||||
* ``getHasUsefulStartTime()``
|
||||
|
||||
* ``getHasUsefulEndTime()``
|
||||
|
||||
* ``getEndsOnSameDay()``
|
||||
|
||||
Fixes
|
||||
-----
|
||||
|
||||
Nothing
|
||||
|
||||
Tasks
|
||||
-----
|
||||
|
||||
Nothing
|
||||
|
||||
Deprecation
|
||||
-----------
|
||||
|
||||
Nothing
|
93
Tests/Unit/Domain/Model/DateTest.php
Normal file
93
Tests/Unit/Domain/Model/DateTest.php
Normal file
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace Wrm\Events\Tests\Unit\Domain\Model;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Wrm\Events\Domain\Model\Date;
|
||||
|
||||
/**
|
||||
* @covers \Wrm\Events\Domain\Model\Date
|
||||
*/
|
||||
class DateTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function canBeCreated(): void
|
||||
{
|
||||
$subject = new Date();
|
||||
|
||||
self::assertInstanceOf(
|
||||
Date::class,
|
||||
$subject
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsThatItHasUsefulStartTime(): void
|
||||
{
|
||||
$subject = new Date();
|
||||
$subject->setStart(new \DateTime('2022-07-11T13:48:00'));
|
||||
|
||||
self::assertTrue($subject->getHasUsefulStartTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsThatItDoesNotHaveUsefulStartTime(): void
|
||||
{
|
||||
$subject = new Date();
|
||||
$subject->setStart(new \DateTime('2022-07-11T00:00:00'));
|
||||
|
||||
self::assertFalse($subject->getHasUsefulStartTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsThatItHasUsefulEndTime(): void
|
||||
{
|
||||
$subject = new Date();
|
||||
$subject->setEnd(new \DateTime('2022-07-11T00:00:00'));
|
||||
|
||||
self::assertTrue($subject->getHasUsefulEndTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsThatItDoesNotHaveUsefulEndTime(): void
|
||||
{
|
||||
$subject = new Date();
|
||||
$subject->setEnd(new \DateTime('2022-07-11T23:59:00'));
|
||||
|
||||
self::assertFalse($subject->getHasUsefulEndTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsThatItEndsOnSameDay(): void
|
||||
{
|
||||
$subject = new Date();
|
||||
$subject->setStart(new \DateTime('2022-07-11T14:00:00'));
|
||||
$subject->setEnd(new \DateTime('2022-07-11T22:00:00'));
|
||||
|
||||
self::assertTrue($subject->getEndsOnSameDay());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsThatItDoesNotEndOnSameDay(): void
|
||||
{
|
||||
$subject = new Date();
|
||||
$subject->setStart(new \DateTime('2022-07-11T14:00:00'));
|
||||
$subject->setEnd(new \DateTime('2022-07-13T22:00:00'));
|
||||
|
||||
self::assertFalse($subject->getEndsOnSameDay());
|
||||
}
|
||||
}
|
128
Tests/Unit/Domain/Model/Dto/DateDemandTest.php
Normal file
128
Tests/Unit/Domain/Model/Dto/DateDemandTest.php
Normal file
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
namespace Wrm\Events\Tests\Unit\Domain\Model\Dto;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Wrm\Events\Domain\Model\Dto\DateDemand;
|
||||
|
||||
/**
|
||||
* @covers \Wrm\Events\Domain\Model\Dto\DateDemand
|
||||
*/
|
||||
class DateDemandTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function canBeCreated(): void
|
||||
{
|
||||
$subject = new DateDemand();
|
||||
|
||||
self::assertInstanceOf(
|
||||
DateDemand::class,
|
||||
$subject
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function searchWordIsSetByRequest(): void
|
||||
{
|
||||
$result = DateDemand::createFromRequestValues(
|
||||
[
|
||||
'searchword' => 'This is the search word',
|
||||
],
|
||||
[
|
||||
]
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
'This is the search word',
|
||||
$result->getSearchword()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function synonymsAreSetBySettings(): void
|
||||
{
|
||||
$result = DateDemand::createFromRequestValues(
|
||||
[
|
||||
'searchword' => 'synonym1',
|
||||
],
|
||||
[
|
||||
'synonyms' => [
|
||||
[
|
||||
'word' => 'Word1',
|
||||
'synonyms' => 'synonym1, synonym2',
|
||||
],
|
||||
[
|
||||
'word' => 'Word2',
|
||||
'synonyms' => 'synonym3, synonym4',
|
||||
],
|
||||
[
|
||||
'word' => 'Word3',
|
||||
'synonyms' => 'synonym1',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
[
|
||||
'Word1',
|
||||
'Word3',
|
||||
],
|
||||
$result->getSynonymsForSearchword()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function categoriesAreSetByRequest(): void
|
||||
{
|
||||
$result = DateDemand::createFromRequestValues(
|
||||
[
|
||||
'userCategories' => [
|
||||
'10', '20',
|
||||
],
|
||||
],
|
||||
[
|
||||
]
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
[
|
||||
10,
|
||||
20,
|
||||
],
|
||||
$result->getUserCategories()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function regionsAreSetByRequest(): void
|
||||
{
|
||||
$result = DateDemand::createFromRequestValues(
|
||||
[
|
||||
'regions' => [
|
||||
'10', '20',
|
||||
],
|
||||
],
|
||||
[
|
||||
]
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
[
|
||||
10,
|
||||
20,
|
||||
],
|
||||
$result->getRegions()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ $EM_CONF['events'] = [
|
|||
'state' => 'alpha',
|
||||
'createDirs' => '',
|
||||
'clearCacheOnLoad' => 0,
|
||||
'version' => '2.4.4',
|
||||
'version' => '2.5.0',
|
||||
'constraints' => [
|
||||
'depends' => [
|
||||
'typo3' => '10.4.00-11.5.99',
|
||||
|
|
Loading…
Reference in a new issue