Skip to content

Commit

Permalink
[FEATURE] Allow time slots with open end
Browse files Browse the repository at this point in the history
Remove requirement of period.end date and show "Open end" if it's empty

Fixes #61 - Thanks to @Hobokens for this feature request
  • Loading branch information
pascal20997 committed Jan 27, 2021
1 parent 26ea89d commit b009b72
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public function getCancelableUntil()
*/
public function canBeBooked(): bool
{
$numberOfParticipants = $this->getParticipants()->count() + 1;
$numberOfParticipants = $this->getParticipants()->count();
return $numberOfParticipants <= $this->getBookedPeriod()->getMaxParticipantsPerOrder();
}

Expand Down
8 changes: 4 additions & 4 deletions Classes/Domain/Model/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Period extends AbstractEntity
protected $begin;

/**
* @var \DateTime
* @var \DateTime|null
*/
protected $end;

Expand Down Expand Up @@ -163,11 +163,11 @@ public function setBegin(\DateTime $begin)
}

/**
* @return \DateTime
* @return \DateTime|null
*/
public function getEnd(): \DateTime
public function getEnd(): ?\DateTime
{
if ($this->end->getTimezone() !== 'UTC') {
if ($this->end && $this->end->getTimezone() !== 'UTC') {
$this->end->setTimezone(new \DateTimeZone('UTC'));
}
return $this->end;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Reservation.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function getIsCurrentlyValid(): bool
if (
$period->getDate()->getTimestamp() === $currentDate
&& $period->getBegin()->getTimestamp() <= $currentTime
&& $period->getEnd()->getTimestamp() > $currentTime
&& ($period->getEnd() === null || $period->getEnd()->getTimestamp() > $currentTime)
) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Utility/QrCodeUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public static function generateQrCode(Reservation $reservation): QrCode
$qrCode
->setLabel(
sprintf(
'%s %s %s - %s',
'%s %s %s %s',
$reservation->getCustomerOrder()->getBookedPeriod()->getFacility()->getShortName()
?: $reservation->getCustomerOrder()->getBookedPeriod()->getFacility()->getName(),
strftime(
LocalizationUtility::translate('date_format', 'reserve'),
$reservation->getCustomerOrder()->getBookedPeriod()->getDate()->getTimestamp()
),
$reservation->getCustomerOrder()->getBookedPeriod()->getBegin()->format('H:i'),
$reservation->getCustomerOrder()->getBookedPeriod()->getEnd()->format('H:i')
$reservation->getCustomerOrder()->getBookedPeriod()->getEnd() ? (' - ' . $reservation->getCustomerOrder()->getBookedPeriod()->getEnd()->format('H:i')) : ''
),
16,
ExtensionManagementUtility::extPath('reserve') . 'Resources/Private/Fonts/noto_sans.otf',
Expand Down
2 changes: 1 addition & 1 deletion Configuration/TCA/tx_reserve_domain_model_period.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
'type' => 'input',
'size' => 30,
'renderType' => 'inputDateTime',
'eval' => 'time,int,required',
'eval' => 'time,int',
],
],
'max_participants' => [
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@
<trans-unit id="datatables.languageFile">
<target>EXT:reserve/Resources/Public/JavaScript/datatables/de.json</target>
</trans-unit>

<trans-unit id="period.openEnd">
<target>Offenes Ende</target>
</trans-unit>
</body>
</file>
</xliff>
4 changes: 4 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@
<trans-unit id="datatables.languageFile">
<source></source>
</trans-unit>

<trans-unit id="period.openEnd">
<source>Open end</source>
</trans-unit>
</body>
</file>
</xliff>
2 changes: 1 addition & 1 deletion Resources/Private/Partials/Mail/ReservationDetails.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

<ul>
<li><f:translate extensionName="reserve" key="mail.facility" />: {order.bookedPeriod.facility.name}</li>
<li><f:translate extensionName="reserve" key="mail.period" />: <f:format.date format="{f:translate(key: 'date_format', extensionName: 'reserve')}">{order.bookedPeriod.date}</f:format.date> <f:format.date format="H:i">{order.bookedPeriod.begin}</f:format.date> - <f:format.date format="H:i">{order.bookedPeriod.end}</f:format.date></li>
<li><f:translate extensionName="reserve" key="mail.period" />: <f:format.date format="{f:translate(key: 'date_format', extensionName: 'reserve')}">{order.bookedPeriod.date}</f:format.date> <f:format.date format="H:i">{order.bookedPeriod.begin}</f:format.date> - <f:if condition="{order.bookedPeriod.end}"><f:then><f:format.date format="H:i">{order.bookedPeriod.end}</f:format.date></f:then><f:else><f:translate key="period.openEnd" /></f:else></f:if></li>
</ul>
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Checkout/Form.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h2>
<f:translate key="form.order.header" arguments="{0: order.bookedPeriod.facility.name}"/>
</h2>
<p>
<f:translate key="form.order.description" arguments="{0: '{f:format.date(date: order.bookedPeriod.date, format: \'{f:translate(key: \\\'date_format\\\')}\')}', 1: '{f:format.date(date: order.bookedPeriod.begin, format: \'H:i\')}', 2: '{f:format.date(date: order.bookedPeriod.end, format: \'H:i\')}'}"/>
<f:translate key="form.order.description" arguments="{0: '{f:format.date(date: order.bookedPeriod.date, format: \'{f:translate(key: \\\'date_format\\\')}\')}', 1: '{f:format.date(date: order.bookedPeriod.begin, format: \'H:i\')}', 2: '{f:if(condition: order.bookedPeriod.end, then: \'{f:format.date(date: order.bookedPeriod.end, format: \\\'H:i\\\')}\', else: \'{f:translate(key: \\\'period.openEnd\\\')}\')}'}"/>
</p>

<f:form.hidden property="bookedPeriod"/>
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Checkout/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2>{facility.name}</h2>
<tr>
<td data-order="{period.date.timestamp}"><f:format.date format="{f:translate(key: 'date_format')}">{period.date}</f:format.date></td>
<td><f:format.date format="H:i">{period.begin}</f:format.date></td>
<td><f:format.date format="H:i">{period.end}</f:format.date></td>
<td><f:if condition="{period.end}"><f:then><f:format.date format="H:i">{period.end}</f:format.date></f:then><f:else><f:translate key="period.openEnd" /></f:else></f:if></td>
<td>{period.remainingParticipants}</td>
<td>
<f:if condition="{period.isBookable}">
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Management/Overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<tr>
<td data-sort="{period.date.timestamp}"><f:format.date format="{f:translate(key: 'date_format')}">{period.date}</f:format.date></td>
<td><f:format.date format="H:i">{period.begin}</f:format.date></td>
<td><f:format.date format="H:i">{period.end}</f:format.date></td>
<td><f:if condition="{period.end}"><f:then><f:format.date format="H:i">{period.end}</f:format.date></f:then><f:else><f:translate key="period.openEnd" /></f:else></f:if></td>
<td>{period.countActiveReservations} <f:translate key="of" /> {period.maxParticipants}</td>
<f:if condition="{period.countActiveReservations}">
<f:then>
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Management/Period.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Management" />
<f:section name="Main">
<h2><f:format.date format="{f:translate(key: 'date_format')}">{period.date}</f:format.date> <f:format.date format="H:i">{period.begin}</f:format.date> - <f:format.date format="H:i">{period.end}</f:format.date></h2>
<h2><f:format.date format="{f:translate(key: 'date_format')}">{period.date}</f:format.date> <f:format.date format="H:i">{period.begin}</f:format.date> - <f:if condition="{period.end}"><f:then><f:format.date format="H:i">{period.end}</f:format.date></f:then><f:else><f:translate key="period.openEnd" /></f:else></f:if></h2>
<f:render partial="Reservations" arguments="{reservations: period.activeReservationsOrderedByCode}" />
</f:section>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<f:layout name="Management" />
<f:section name="Main">
<f:for each="{periods}" as="period" >
<h2><f:format.date format="{f:translate(key: 'date_format')}">{period.date}</f:format.date> <f:format.date format="H:i">{period.begin}</f:format.date> - <f:format.date format="H:i">{period.end}</f:format.date></h2>
<h2><f:format.date format="{f:translate(key: 'date_format')}">{period.date}</f:format.date> <f:format.date format="H:i">{period.begin}</f:format.date> - <f:if condition="{period.end}"><f:then><f:format.date format="H:i">{period.end}</f:format.date></f:then><f:else><f:translate key="period.openEnd" /></f:else></f:if></h2>
<f:render partial="Reservations" arguments="{reservations: period.activeReservationsOrderedByCode}" />
</f:for>
</f:section>
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Management/Scanner.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Management" />
<f:section name="Main">
<h2><f:format.date format="{f:translate(key: 'date_format')}">{period.date}</f:format.date> <f:format.date format="H:i">{period.begin}</f:format.date> - <f:format.date format="H:i">{period.end}</f:format.date></h2>
<h2><f:format.date format="{f:translate(key: 'date_format')}">{period.date}</f:format.date> <f:format.date format="H:i">{period.begin}</f:format.date> - <f:if condition="{period.end}"><f:then><f:format.date format="H:i">{period.end}</f:format.date></f:then><f:else><f:translate key="period.openEnd" /></f:else></f:if></h2>
<div style="float: right">
<p><span id="remainingParticipants">{period.remainingParticipants}</span> {f:translate(key: 'list.free_slots')}</p>
<p><span id="usedReservations">{period.usedReservations -> f:count()}</span> {f:translate(key: 'redeemed')}</p>
Expand Down

0 comments on commit b009b72

Please sign in to comment.