Skip to content
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

Totalausfall: Stornierung optional #1347

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
17 changes: 16 additions & 1 deletion includes/OptionsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,23 @@
)

)
)
),
/* field group email templates end */
/* field group restriction settings start */
'restrictionsettings' => array(
'title' => commonsbooking_sanitizeHTML( __( 'Restriction settings', 'commonsbooking' ) ),
'id' => 'restrictionsettings',
'desc' => commonsbooking_sanitizeHTML( __( 'Settings for restrictions.<br><a href="https://commonsbooking.org/?p=1762" target="_blank">More Information in the documentation</a>', 'commonsbooking' ) ),
'fields' => array(
array(
'name' => commonsbooking_sanitizeHTML( __( 'Do not cancel bookings on total breakdown', 'commonsbooking' ) ),
'id' => 'restrictions-no-cancel-on-total-breakdown',
'type' => 'checkbox',
'desc' => commonsbooking_sanitizeHTML( __( 'If checked, bookings will not be cancelled if the item has broken down. The user will be notified and once the item becomes available again, the old bookings are still valid.', 'commonsbooking' ) ),
)
)
)
/* field group restriction settings end */
)
),
/* Tab: restrictions end*/
Expand Down
29 changes: 29 additions & 0 deletions src/Model/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,35 @@ public function getEmailSignature(): string {
);
}

/**
* Will return if a booking is affected by a total breakdown ( the booked item is not usable ).
* Because since #866 not all total breakdowns are cancelled, we need a way to make sure that the user
* will not be notified about their upcoming bookings or asked to give feedback because they might not have used the item.
* @return bool true if booking is affected by a total breakdown
*/
public function hasTotalBreakdown(): bool {
$itemID = $this->getItem()->ID;
$locationID = $this->getLocation()->ID;
$restrictions = \CommonsBooking\Repository\Restriction::get(
[$locationID],
[$itemID],
null,
true
);
foreach ( $restrictions as $restriction ) {
if (
$restriction->getType() == Restriction::TYPE_REPAIR && $restriction->isActive()) {
$bookings = \CommonsBooking\Repository\Booking::getByRestriction( $restriction );
foreach ( $bookings as $booking ) {
if ( $booking->ID == $this->ID ) {
return true;
}
}
}
}
return false;
}

/**
* Returns formatted user info based on the template field in settings -> templates
*
Expand Down
3 changes: 2 additions & 1 deletion src/Model/Restriction.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,9 @@ public function apply() {
// send restriction mails to all affected bookings
$this->sendRestrictionMails( $bookings );

$cancelPreventionSetting = \CommonsBooking\Settings\Settings::getOption( 'commonsbooking_options_restrictions', 'restrictions-no-cancel-on-total-breakdown' ) == 'on';
// cancel all affected booking
if ( $this->isActive() && $this->getType() == self::TYPE_REPAIR ) {
if ( ! $cancelPreventionSetting && $this->isActive() && $this->getType() == self::TYPE_REPAIR ) {
$this->cancelBookings( $bookings );
}

Expand Down
3 changes: 3 additions & 0 deletions src/Service/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ private static function sendMessagesForDay ( int $tsDate, bool $onStartDate, Mes
}
if ( count( $bookings ) ) {
foreach ( $bookings as $booking ) {
if ( $booking->hasTotalBreakdown() ) {
continue;
}
$message = new $message( $booking->getPost()->ID, $message->getAction() );
$message->triggerMail();
}
Expand Down
14 changes: 14 additions & 0 deletions tests/php/Model/BookingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,20 @@ public function testCanCancelBaseCase() {
$this->assertTrue( commonsbooking_isCurrentUserAdmin() );
}

public function testHasTotalBreakdown() {
$testBooking = new Booking( $this->createConfirmedBookingStartingToday() );
$this->assertFalse( $this->testBookingTomorrow->hasTotalBreakdown() );
//create a total breakdown
$totalBreakdown = $this->createRestriction(
\CommonsBooking\Model\Restriction::TYPE_REPAIR,
$this->locationId,
$this->itemId,
strtotime( self::CURRENT_DATE ),
strtotime( '+1 day', strtotime( self::CURRENT_DATE ) )
);
$this->assertTrue( $testBooking->hasTotalBreakdown() );
}

/**
* This tests the distinctions of CB Managers when they have been assigned an item or not.
* Generally speaking, CB Managers should be able to only cancel bookings of items / locations they manage.
Expand Down