Skip to content

Commit

Permalink
fix #1229
Browse files Browse the repository at this point in the history
  • Loading branch information
hansmorb committed Mar 14, 2024
1 parent af6c19a commit 71ebf85
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/View/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public static function getBookingListData( int $postsPerPage = 6, \WP_User $user
$order = sanitize_text_field( $_POST['order'] );
}

// Upon initial load, start date is not configured
$startDateDefined = false;
if ( array_key_exists( 'startDate', $_POST ) ) {
$startDateDefined = true;
}

$filters = [
'location' => false,
'item' => false,
Expand Down Expand Up @@ -109,7 +115,29 @@ public static function getBookingListData( int $postsPerPage = 6, \WP_User $user
);

if ( ! $posts ) {
return false;
// Because upon initial load the form stays empty when we just have bookings in the past
// With an empty form, the user can't change the start date so we look for bookings in the past
if ( ! $startDateDefined ) {
//Don't fetch all bookings so that admins are not overwhelmed with all bookings of all time
for ( $year = 1; $year <= 3; $year++) {
$currentTime = strtotime( '-' . $year . ' year' );
$posts = \CommonsBooking\Repository\Booking::getForUser(
$user,
true,
$currentTime
);
if ( $posts ) {
$filters['startDate'] = $currentTime;
break;
}
}
if ( ! $posts ) {
return false;
}
}
else {
return false;
}
}

// Prepare Templatedata and remove invalid posts
Expand Down

0 comments on commit 71ebf85

Please sign in to comment.