Skip to content

Commit

Permalink
[BUGFIX] Added option to control enableFields setting in eventDemand
Browse files Browse the repository at this point in the history
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
  • Loading branch information
derhansen committed Nov 8, 2020
1 parent d7e831c commit 9f31fb4
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Classes/Controller/AdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
21 changes: 21 additions & 0 deletions Classes/Domain/Model/Dto/EventDemand.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ class EventDemand extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
*/
protected $organisator = null;

/**
* @var bool
*/
protected $ignoreEnableFields = false;

/**
* Sets the displayMode
*
Expand Down Expand Up @@ -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;
}
}
93 changes: 93 additions & 0 deletions Classes/Domain/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -1591,4 +1666,22 @@ public function getSpamCheckChallenge(): string
{
return MiscUtility::getSpamCheckChallenge($this->getUid());
}

/**
* Returns a string to be used as overlay value for the <core:icon> 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;
}
}
2 changes: 2 additions & 0 deletions Classes/Domain/Repository/EventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/Partials/Administration/ListItem.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
xmlns:e="http://typo3.org/ns/DERHANSEN/SfEventMgt/ViewHelpers"
data-namespace-typo3-fluid="true">

<tr>
<td class="event-icon">
<core:icon overlay="{event.backendIconOverlay}" identifier="ext-sfeventmgt-event" size="small" />
</td>
<td class="title">
<a href="{e:Be.EditRecord(uid:event.uid)}" title="UID: {event.uid}">
{event.title}
Expand Down
1 change: 1 addition & 0 deletions Resources/Private/Templates/Administration/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ <h1>
<table cellpadding="0" cellspacing="0" class="table table-striped table-hover">
<thead>
<tr>
<th class="event-icon"></th>
<th class="title">
<f:translate key="tx_sfeventmgt_domain_model_event.title"/>
</th>
Expand Down
10 changes: 10 additions & 0 deletions Tests/Functional/Fixtures/tx_sfeventmgt_domain_model_event.xml
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,14 @@
<startdate>1564300800</startdate>
<enddate>1565013600</enddate>
</tx_sfeventmgt_domain_model_event>

<!-- findDemandedRespectsIgnoreEnableFields -->
<tx_sfeventmgt_domain_model_event>
<uid>120</uid>
<pid>120</pid>
<hidden>1</hidden>
<title>A hidden event</title>
<description>Test for hidden event</description>
<link>link</link>
</tx_sfeventmgt_domain_model_event>
</dataset>
37 changes: 37 additions & 0 deletions Tests/Functional/Repository/EventRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
101 changes: 101 additions & 0 deletions Tests/Unit/Domain/Model/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 9f31fb4

Please sign in to comment.