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

fix #1229 (Vergangene Buchungen in Buchungsübersicht) #1554

Merged
merged 1 commit into from
Sep 3, 2024
Merged
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
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
Loading