Skip to content

[FEATURE] Display the vacancies in the new list view #4033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- Add `Venue.city` property (#3908, #3914)
- Add a new plugin for the event archive, outlook and single view
(#3895, #3909, #3910, #3911, #3913, #3915, #3986, #3969, #4024, #4025, #4026,
#4027, #4028, #4029, #4030)
#4027, #4028, #4029, #4030, #4031, #4033)
- Re-add the FE editor (#3894, #3903, #3904)
- Add `EventRepository::findUpcoming()` (#3892, #3904)
- Add `EventRepository::findInPast()` (#3885, #3887, #3891, #3904)
Expand Down
19 changes: 17 additions & 2 deletions Classes/Controller/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use OliverKlee\Seminars\Domain\Model\Event\Event;
use OliverKlee\Seminars\Domain\Repository\Event\EventRepository;
use OliverKlee\Seminars\Service\EventStatisticsCalculator;
use OliverKlee\Seminars\Service\RegistrationGuard;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Extbase\Annotation\IgnoreValidation;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
Expand All @@ -17,9 +19,18 @@ class EventController extends ActionController
{
protected EventRepository $eventRepository;

public function __construct(EventRepository $eventRepository)
{
protected EventStatisticsCalculator $eventStatisticsCalculator;

protected RegistrationGuard $registrationGuard;

public function __construct(
EventRepository $eventRepository,
EventStatisticsCalculator $eventStatisticsCalculator,
RegistrationGuard $registrationGuard
) {
$this->eventRepository = $eventRepository;
$this->eventStatisticsCalculator = $eventStatisticsCalculator;
$this->registrationGuard = $registrationGuard;
}

/**
Expand All @@ -40,6 +51,10 @@ public function archiveAction(): ResponseInterface
public function outlookAction(): ResponseInterface
{
$events = $this->eventRepository->findUpcoming();
foreach ($events as $event) {
$this->eventStatisticsCalculator->enrichWithStatistics($event);
}
$this->registrationGuard->setRegistrationPossibleByDateForEvents($events);

$this->view->assign('events', $events);

Expand Down
6 changes: 4 additions & 2 deletions Classes/Service/RegistrationGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ public function isRegistrationPossibleByDate(EventDateInterface $event): bool
}

/**
* @param array<EventDateInterface> $events
* @param array<Event> $events
*/
public function setRegistrationPossibleByDateForEvents(array $events): void
{
foreach ($events as $event) {
$event->setRegistrationPossibleByDate($this->isRegistrationPossibleByDate($event));
if ($event instanceof EventDateInterface) {
$event->setRegistrationPossibleByDate($this->isRegistrationPossibleByDate($event));
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion Configuration/FlexForms/EventOutlook.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<renderType>selectCheckBox</renderType>
<minitems>1</minitems>
<maxitems>99</maxitems>
<default>date,topic,city</default>
<default>date,topic,city,vacancies</default>
<items type="array">
<numIndex index="0" type="array">
<numIndex index="0">
Expand Down Expand Up @@ -127,6 +127,12 @@
</numIndex>
<numIndex index="1">venue</numIndex>
</numIndex>
<numIndex index="5" type="array">
<numIndex index="0">
LLL:EXT:seminars/Resources/Private/Language/locallang.xlf:plugin.eventOutlook.settings.displayOptions.columns.vacancies
</numIndex>
<numIndex index="1">vacancies</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
Expand Down
3 changes: 3 additions & 0 deletions Configuration/TypoScript/PluginSettings.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ plugin.tx_seminars.settings {
decimals = {$plugin.tx_seminars.settings.currency.decimals}
useDash = {$plugin.tx_seminars.settings.currency.useDash}
}

# show "enough" instead of the exact number if there are at last this many vacancies
enoughVacanciesThreshold = {$plugin.tx_seminars.settings.enoughVacanciesThreshold}
}
3 changes: 3 additions & 0 deletions Configuration/TypoScript/constants.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ plugin {
# cat=plugin.tx_seminars.settings.currency//; type=boolean; label=Use the dash instead of decimal 00
useDash = 0
}

# cat=plugin.tx_seminars.settings//; type=int[1-999]; label=Show "enough" instead of the exact number if there are at last this many vacancies
enoughVacanciesThreshold = 5
}
}
12 changes: 12 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,9 @@ This event now has been confirmed.</source>
<trans-unit id="plugin.eventOutlook.settings.displayOptions.columns.venue">
<source>venue</source>
</trans-unit>
<trans-unit id="plugin.eventOutlook.settings.displayOptions.columns.vacancies">
<source>vacancies</source>
</trans-unit>
<trans-unit id="plugin.eventOutlook.message.noEventsFound">
<source>No events found.</source>
</trans-unit>
Expand All @@ -1704,6 +1707,15 @@ This event now has been confirmed.</source>
<trans-unit id="plugin.eventOutlook.events.property.venue">
<source>Venue</source>
</trans-unit>
<trans-unit id="plugin.eventOutlook.events.property.vacancies">
<source>Vacancies</source>
</trans-unit>
<trans-unit id="plugin.eventOutlook.events.property.vacancies.enough">
<source>enough</source>
</trans-unit>
<trans-unit id="plugin.eventOutlook.events.property.vacancies.fullyBooked">
<source>fully booked</source>
</trans-unit>
<trans-unit id="plugin.eventSingleView">
<source>Event single view</source>
</trans-unit>
Expand Down
10 changes: 10 additions & 0 deletions Resources/Private/Partials/Event/OutlookList.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<f:translate key="plugin.eventOutlook.events.property.venue"/>
</th>
</oelib:isFieldEnabled>
<oelib:isFieldEnabled fieldName="vacancies">
<th scope="col">
<f:translate key="plugin.eventOutlook.events.property.vacancies"/>
</th>
</oelib:isFieldEnabled>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -69,6 +74,11 @@
</f:for>
</td>
</oelib:isFieldEnabled>
<oelib:isFieldEnabled fieldName="vacancies">
<td class="text-end">
<f:render partial="Event/Vacancies" arguments="{event: event}"/>
</td>
</oelib:isFieldEnabled>
</tr>
</f:for>
</tbody>
Expand Down
18 changes: 18 additions & 0 deletions Resources/Private/Partials/Event/Vacancies.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:variable name="statistics" value="{event.statistics}"/>
<f:if condition="({event.registrationRequired} && {event.registrationPossibleByDate})">
<f:if condition="({event.unlimitedSeats} || ({statistics.vacancies} >= {settings.enoughVacanciesThreshold}))">
<f:then>
<f:translate key="plugin.eventOutlook.events.property.vacancies.enough"/>
🟢
</f:then>
<f:else if="{statistics.fullyBooked}">
<f:translate key="plugin.eventOutlook.events.property.vacancies.fullyBooked"/>
🔴
</f:else>
<f:else>
{statistics.vacancies} 🟡
</f:else>
</f:if>
</f:if>
</html>
147 changes: 147 additions & 0 deletions Tests/Functional/Controller/EventControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,153 @@ public function outlookActionRendersEventType(): void
self::assertStringContainsString('workshop', $html);
}

/**
* @test
*/
public function outlookActionForEventWithUnlimitedSeatsRendersEnoughVacancies(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/EventController/outlookAction/EventOutlookContentElement.csv');
$this->importCSVDataSet(__DIR__ . '/Fixtures/EventController/outlookAction/FutureEventWithUnlimitedSeats.csv');

$request = (new InternalRequest())->withPageId(1);

$html = (string)$this->executeFrontendSubRequest($request)->getBody();

$enough = LocalizationUtility::translate('plugin.eventOutlook.events.property.vacancies.enough', 'seminars');
self::assertIsString($enough);
self::assertStringContainsString($enough, $html);
self::assertStringContainsString('🟢', $html);
}

/**
* @test
*/
public function outlookActionForEventWithMoreThanEnoughVacanciesRendersEnoughVacancies(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/EventController/outlookAction/EventOutlookContentElement.csv');
$this->importCSVDataSet(
__DIR__ . '/Fixtures/EventController/outlookAction/FutureEventWithMoreThanEnoughVacancies.csv'
);

$request = (new InternalRequest())->withPageId(1);

$html = (string)$this->executeFrontendSubRequest($request)->getBody();

$enough = LocalizationUtility::translate('plugin.eventOutlook.events.property.vacancies.enough', 'seminars');
self::assertIsString($enough);
self::assertStringContainsString($enough, $html);
self::assertStringContainsString('🟢', $html);
}

/**
* @test
*/
public function outlookActionForEventWithExactlyEnoughVacanciesRendersEnoughVacancies(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/EventController/outlookAction/EventOutlookContentElement.csv');
$this->importCSVDataSet(
__DIR__ . '/Fixtures/EventController/outlookAction/FutureEventWithExactlyEnoughVacancies.csv'
);

$request = (new InternalRequest())->withPageId(1);

$html = (string)$this->executeFrontendSubRequest($request)->getBody();

$enough = LocalizationUtility::translate('plugin.eventOutlook.events.property.vacancies.enough', 'seminars');
self::assertIsString($enough);
self::assertStringContainsString($enough, $html);
self::assertStringContainsString('🟢', $html);
}

/**
* @test
*/
public function outlookActionForEventWithLessThanEnoughVacanciesRendersExactVacancies(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/EventController/outlookAction/EventOutlookContentElement.csv');
$this->importCSVDataSet(
__DIR__ . '/Fixtures/EventController/outlookAction/FutureEventWithLessThanEnoughVacancies.csv'
);

$request = (new InternalRequest())->withPageId(1);

$html = (string)$this->executeFrontendSubRequest($request)->getBody();

self::assertStringContainsString('4 🟡', $html);
}

/**
* @test
*/
public function outlookActionForEventWithOneVacancyRendersExactVacancies(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/EventController/outlookAction/EventOutlookContentElement.csv');
$this->importCSVDataSet(__DIR__ . '/Fixtures/EventController/outlookAction/FutureEventWithOneVacancy.csv');

$request = (new InternalRequest())->withPageId(1);

$html = (string)$this->executeFrontendSubRequest($request)->getBody();

self::assertStringContainsString('1 🟡', $html);
}

/**
* @test
*/
public function outlookActionForEventWithNoVacancyRendersFullyBooked(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/EventController/outlookAction/EventOutlookContentElement.csv');
$this->importCSVDataSet(__DIR__ . '/Fixtures/EventController/outlookAction/FutureEventWithNoVacancies.csv');

$request = (new InternalRequest())->withPageId(1);

$html = (string)$this->executeFrontendSubRequest($request)->getBody();

$fullyBooked = LocalizationUtility::translate(
'plugin.eventOutlook.events.property.vacancies.fullyBooked',
'seminars'
);
self::assertIsString($fullyBooked);
self::assertStringContainsString($fullyBooked, $html);
self::assertStringContainsString('🔴', $html);
}

/**
* @test
*/
public function outlookActionForEventWithMoreThanEnoughVacanciesButDeadlineOverRendersNoVacancies(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/EventController/outlookAction/EventOutlookContentElement.csv');
$this->importCSVDataSet(
__DIR__ . '/Fixtures/EventController/outlookAction/FutureEventWithEnoughVacanciesButDeadlineOver.csv'
);

$request = (new InternalRequest())->withPageId(1);

$html = (string)$this->executeFrontendSubRequest($request)->getBody();

$enough = LocalizationUtility::translate('plugin.eventOutlook.events.property.vacancies.enough', 'seminars');
self::assertIsString($enough);
self::assertStringNotContainsString($enough, $html);
}

/**
* @test
*/
public function outlookActionForEventWithoutRegistrationRendersNoVacancies(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/EventController/outlookAction/EventOutlookContentElement.csv');
$this->importCSVDataSet(__DIR__ . '/Fixtures/EventController/outlookAction/FutureEventWithoutRegistration.csv');

$request = (new InternalRequest())->withPageId(1);

$html = (string)$this->executeFrontendSubRequest($request)->getBody();

$enough = LocalizationUtility::translate('plugin.eventOutlook.events.property.vacancies.enough', 'seminars');
self::assertIsString($enough);
self::assertStringNotContainsString($enough, $html);
}

/**
* @test
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<sheet index=""displayOptions"">
<language index=""lDEF"">
<field index=""settings.fieldsToShow"">
<value index=""vDEF"">date,eventType,topic,city,venue</value>
<value index=""vDEF"">date,eventType,topic,city,venue,vacancies</value>
</field>
</language>
</sheet>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"tx_seminars_seminars"
,"uid","pid","title","begin_date","end_date","deadline_registration","needs_registration","attendees_max","offline_attendees",
,1,2,"Extension Development with Extbase and Fluid",2524604400,2524604401,1,1,20,5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"tx_seminars_seminars"
,"uid","pid","title","begin_date","end_date","needs_registration","attendees_max","offline_attendees"
,1,2,"Extension Development with Extbase and Fluid",2524604400,2524604401,1,10,5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"tx_seminars_seminars"
,"uid","pid","title","begin_date","end_date","needs_registration","attendees_max","offline_attendees"
,1,2,"Extension Development with Extbase and Fluid",2524604400,2524604401,1,10,6
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"tx_seminars_seminars"
,"uid","pid","title","begin_date","end_date","needs_registration","attendees_max","offline_attendees",
,1,2,"Extension Development with Extbase and Fluid",2524604400,2524604401,1,20,14
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"tx_seminars_seminars"
,"uid","pid","title","begin_date","end_date","needs_registration","attendees_max","offline_attendees"
,1,2,"Extension Development with Extbase and Fluid",2524604400,2524604401,1,20,20
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"tx_seminars_seminars"
,"uid","pid","title","begin_date","end_date","needs_registration","attendees_max","offline_attendees"
,1,2,"Extension Development with Extbase and Fluid",2524604400,2524604401,1,20,19
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"tx_seminars_seminars"
,"uid","pid","title","begin_date","end_date","needs_registration","attendees_max"
,1,2,"Extension Development with Extbase and Fluid",2524604400,2524604401,1,0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"tx_seminars_seminars"
,"uid","pid","title","begin_date","end_date","needs_registration","attendees_max"
,1,2,"Extension Development with Extbase and Fluid",2524604400,2524604401,0,0
12 changes: 10 additions & 2 deletions Tests/Unit/Controller/EventControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use OliverKlee\Seminars\Controller\EventController;
use OliverKlee\Seminars\Domain\Repository\Event\EventRepository;
use OliverKlee\Seminars\Service\EventStatisticsCalculator;
use OliverKlee\Seminars\Service\RegistrationGuard;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

Expand All @@ -21,8 +23,14 @@ protected function setUp(): void
parent::setUp();

$eventRepositoryStub = $this->createStub(EventRepository::class);

$this->subject = new EventController($eventRepositoryStub);
$eventStatisticsCalculatorStub = $this->createStub(EventStatisticsCalculator::class);
$registrationGuardStub = $this->createStub(RegistrationGuard::class);

$this->subject = new EventController(
$eventRepositoryStub,
$eventStatisticsCalculatorStub,
$registrationGuardStub
);
}

/**
Expand Down