From 9f31fb444475df7af63a0122b54e047930d2bea3 Mon Sep 17 00:00:00 2001 From: Torben Hansen Date: Sun, 8 Nov 2020 19:41:49 +0100 Subject: [PATCH] [BUGFIX] Added option to control enableFields setting in eventDemand The `eventDemand` object has been extended, so the `enableFields` setting for queries using `findDemanded` can be controlled. Additionally the event model has been extended with getter/setters for the properties hidden, starttime and endtime. The list action of the administrationController now by default sets the `enableFields` setting to false, so the event module also will show events that are hidden or have a start- or endtime. Refs #805 --- .../Controller/AdministrationController.php | 3 +- Classes/Domain/Model/Dto/EventDemand.php | 21 ++++ Classes/Domain/Model/Event.php | 93 ++++++++++++++++ Classes/Domain/Repository/EventRepository.php | 2 + .../Partials/Administration/ListItem.html | 4 + .../Templates/Administration/List.html | 1 + .../tx_sfeventmgt_domain_model_event.xml | 10 ++ .../Repository/EventRepositoryTest.php | 37 +++++++ Tests/Unit/Domain/Model/EventTest.php | 101 ++++++++++++++++++ 9 files changed, 271 insertions(+), 1 deletion(-) diff --git a/Classes/Controller/AdministrationController.php b/Classes/Controller/AdministrationController.php index 77d63ffb7..9829cd572 100644 --- a/Classes/Controller/AdministrationController.php +++ b/Classes/Controller/AdministrationController.php @@ -349,10 +349,11 @@ public function listAction(SearchDemand $searchDemand = null, array $overwriteDe /** @var EventDemand $eventDemand */ $eventDemand = $this->objectManager->get(EventDemand::class); - $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); + $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand ?? []); $eventDemand->setOrderFieldAllowed($this->settings['orderFieldAllowed']); $eventDemand->setSearchDemand($searchDemand); $eventDemand->setStoragePage($this->pid); + $eventDemand->setIgnoreEnableFields(true); $events = []; if ($this->getBackendUser()->isInWebMount($this->pid)) { diff --git a/Classes/Domain/Model/Dto/EventDemand.php b/Classes/Domain/Model/Dto/EventDemand.php index f7eb778e8..653cdd606 100644 --- a/Classes/Domain/Model/Dto/EventDemand.php +++ b/Classes/Domain/Model/Dto/EventDemand.php @@ -155,6 +155,11 @@ class EventDemand extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity */ protected $organisator = null; + /** + * @var bool + */ + protected $ignoreEnableFields = false; + /** * Sets the displayMode * @@ -587,4 +592,20 @@ public function setSpeaker($speaker) { $this->speaker = $speaker; } + + /** + * @return bool + */ + public function getIgnoreEnableFields(): bool + { + return $this->ignoreEnableFields; + } + + /** + * @param bool $ignoreEnableFields + */ + public function setIgnoreEnableFields(bool $ignoreEnableFields): void + { + $this->ignoreEnableFields = $ignoreEnableFields; + } } diff --git a/Classes/Domain/Model/Event.php b/Classes/Domain/Model/Event.php index edbabaa1c..511b52350 100644 --- a/Classes/Domain/Model/Event.php +++ b/Classes/Domain/Model/Event.php @@ -27,6 +27,21 @@ class Event extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity */ protected $tstamp; + /** + * @var bool + */ + protected $hidden = false; + + /** + * @var \DateTime + */ + protected $starttime; + + /** + * @var \DateTime + */ + protected $endtime; + /** * Title * @@ -343,6 +358,66 @@ public function setTstamp($tstamp) $this->tstamp = $tstamp; } + /** + * Get hidden flag + * + * @return bool + */ + public function getHidden() + { + return $this->hidden; + } + + /** + * Set hidden flag + * + * @param bool $hidden hidden flag + */ + public function setHidden($hidden) + { + $this->hidden = $hidden; + } + + /** + * Get start time + * + * @return \DateTime + */ + public function getStarttime() + { + return $this->starttime; + } + + /** + * Set start time + * + * @param \DateTime $starttime start time + */ + public function setStarttime($starttime) + { + $this->starttime = $starttime; + } + + /** + * Get endtime + * + * @return \DateTime + */ + public function getEndtime() + { + return $this->endtime; + } + + /** + * Set end time + * + * @param \DateTime $endtime end time + */ + public function setEndtime($endtime) + { + $this->endtime = $endtime; + } + /** * Returns the title * @@ -1591,4 +1666,22 @@ public function getSpamCheckChallenge(): string { return MiscUtility::getSpamCheckChallenge($this->getUid()); } + + /** + * Returns a string to be used as overlay value for the ViewHelper in the Backend Modules + * + * @return string + */ + public function getBackendIconOverlay(): string + { + $overlay = ''; + if ($this->getHidden()) { + $overlay = 'overlay-hidden'; + } + if (!$this->getHidden() && ($this->getStarttime() || $this->getEndtime())) { + $overlay = 'overlay-endtime'; + } + + return $overlay; + } } diff --git a/Classes/Domain/Repository/EventRepository.php b/Classes/Domain/Repository/EventRepository.php index d616bef00..3b5d649d9 100644 --- a/Classes/Domain/Repository/EventRepository.php +++ b/Classes/Domain/Repository/EventRepository.php @@ -54,6 +54,8 @@ public function findDemanded(EventDemand $eventDemand) { $constraints = []; $query = $this->createQuery(); + $query->getQuerySettings()->setIgnoreEnableFields($eventDemand->getIgnoreEnableFields()); + $this->setStoragePageConstraint($query, $eventDemand, $constraints); $this->setDisplayModeConstraint($query, $eventDemand, $constraints); $this->setCategoryConstraint($query, $eventDemand, $constraints); diff --git a/Resources/Private/Partials/Administration/ListItem.html b/Resources/Private/Partials/Administration/ListItem.html index a107c23cd..20c5d2237 100644 --- a/Resources/Private/Partials/Administration/ListItem.html +++ b/Resources/Private/Partials/Administration/ListItem.html @@ -1,8 +1,12 @@ + + + {event.title} diff --git a/Resources/Private/Templates/Administration/List.html b/Resources/Private/Templates/Administration/List.html index 862b08d15..ae4f2dba6 100644 --- a/Resources/Private/Templates/Administration/List.html +++ b/Resources/Private/Templates/Administration/List.html @@ -105,6 +105,7 @@

+ diff --git a/Tests/Functional/Fixtures/tx_sfeventmgt_domain_model_event.xml b/Tests/Functional/Fixtures/tx_sfeventmgt_domain_model_event.xml index 6f7c0b12a..2a5954231 100644 --- a/Tests/Functional/Fixtures/tx_sfeventmgt_domain_model_event.xml +++ b/Tests/Functional/Fixtures/tx_sfeventmgt_domain_model_event.xml @@ -571,4 +571,14 @@ 15643008001565013600 + + + + 120 + 120 + 1 + A hidden event + Test for hidden event + link + \ No newline at end of file diff --git a/Tests/Functional/Repository/EventRepositoryTest.php b/Tests/Functional/Repository/EventRepositoryTest.php index 9a45da585..d9ef9d47d 100644 --- a/Tests/Functional/Repository/EventRepositoryTest.php +++ b/Tests/Functional/Repository/EventRepositoryTest.php @@ -807,4 +807,41 @@ public function findSearchDemandedRecordsByStartAndEndDate() $this->assertSame(1, $events->count()); } + + + /** + * DataProvider for findDemandedRecordsBySpeaker + * + * @return array + */ + public function findDemandedRespectsIgnoreEnableFieldsDataProvider() + { + return [ + 'ignoreEnableFields inactive' => [ + false, + 0 + ], + 'ignoreEnableFields active' => [ + true, + 1 + ], + ]; + } + + /** + * Test if ignoreEnableFields setting is respected + * + * @dataProvider findDemandedRespectsIgnoreEnableFieldsDataProvider + * @test + * @param bool $ignoreEnableFields + * @param bool $expected + */ + public function findDemandedRespectsIgnoreEnableFields($ignoreEnableFields, $expected) + { + /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand */ + $demand = $this->objectManager->get(EventDemand::class); + $demand->setStoragePage(120); + $demand->setIgnoreEnableFields($ignoreEnableFields); + $this->assertSame($expected, $this->eventRepository->findDemanded($demand)->count()); + } } diff --git a/Tests/Unit/Domain/Model/EventTest.php b/Tests/Unit/Domain/Model/EventTest.php index 7511043c4..326c34076 100644 --- a/Tests/Unit/Domain/Model/EventTest.php +++ b/Tests/Unit/Domain/Model/EventTest.php @@ -1716,4 +1716,105 @@ public function eventEndsSameDayReturnsExpectedValue($startdate, $enddate, $expe } $this->assertEquals($expected, $this->subject->getEndsSameDay()); } + + + /** + * @test + */ + public function getHiddenReturnsInitialValue() + { + $this->assertFalse($this->subject->getHidden()); + } + + /** + * @test + */ + public function setHiddenSetsValueForBoolean() + { + $this->subject->setHidden(true); + $this->assertTrue($this->subject->getHidden()); + } + + /** + * @test + */ + public function getStarttimeReturnsInitialValue() + { + $this->assertNull($this->subject->getStarttime()); + } + + /** + * @test + */ + public function setStarttimeSetsValueForDateTime() + { + $date = new \DateTime('01.01.2020 18:00:00'); + $this->subject->setStarttime($date); + + $this->assertEquals($date, $this->subject->getStarttime()); + } + + /** + * @test + */ + public function getEndtimeReturnsInitialValue() + { + $this->assertNull($this->subject->getEndtime()); + } + + /** + * @test + */ + public function setEndtimeSetsValueForDateTime() + { + $date = new \DateTime('01.01.2020 18:00:00'); + $this->subject->setEndtime($date); + + $this->assertEquals($date, $this->subject->getEndtime()); + } + + /** + * @test + */ + public function getBackendIconOverlayReturnsEmptyStringIfNotHiddenAndNoStartEndTime() + { + $this->assertEquals('', $this->subject->getBackendIconOverlay()); + } + + /** + * @test + */ + public function getBackendIconOverlayReturnsExpectedValueForHiddenEvent() + { + $this->subject->setHidden(true); + $this->assertEquals('overlay-hidden', $this->subject->getBackendIconOverlay()); + } + + /** + * @test + */ + public function getBackendIconOverlayReturnsExpectedValueForStarttimeEvent() + { + $this->subject->setStarttime(new \DateTime()); + $this->assertEquals('overlay-endtime', $this->subject->getBackendIconOverlay()); + } + + /** + * @test + */ + public function getBackendIconOverlayReturnsExpectedValueForEndtimeEvent() + { + $this->subject->setEndtime(new \DateTime()); + $this->assertEquals('overlay-endtime', $this->subject->getBackendIconOverlay()); + } + + /** + * @test + */ + public function getBackendIconOverlayReturnsExpectedValueForHiddenAndStarttimeEvent() + { + $this->subject->setHidden(true); + $this->subject->setEndtime(new \DateTime()); + $this->assertEquals('overlay-hidden', $this->subject->getBackendIconOverlay()); + } }