Version Description
(2020-02-18) = - Corrects issue in which all bookings were automatically confirming, even beyond the threshold set using the auto-confirm settings - Corrects issue that was causing the max reservations setting to inaccurately set which time slots should be blocked off
Download this release
Release Info
Developer | Rustaurius |
Plugin | Restaurant Reservations |
Version | 2.0.14 |
Comparing to | |
See all releases |
Code changes from version 2.0.13 to 2.0.14
- includes/Ajax.class.php +29 -22
- includes/Booking.class.php +36 -26
- readme.txt +4 -0
- restaurant-reservations.php +1 -1
includes/Ajax.class.php
CHANGED
@@ -42,28 +42,28 @@ class rtbAJAX {
|
|
42 |
|
43 |
$max_reservations_setting = $rtb_controller->settings->get_setting( 'rtb-max-tables-count' );
|
44 |
$max_reservations = substr( $max_reservations_setting, 0, strpos( $max_reservations_setting, '_' ) );
|
45 |
-
|
46 |
$this->year = sanitize_text_field( $_POST['year'] );
|
47 |
$this->month = sanitize_text_field( $_POST['month'] );
|
48 |
$this->day = sanitize_text_field( $_POST['day'] );
|
49 |
-
|
50 |
$dining_block_setting = $rtb_controller->settings->get_setting( 'rtb-dining-block-length' );
|
51 |
$dining_block = substr( $dining_block_setting, 0, strpos( $dining_block_setting, '_' ) );
|
52 |
$dining_block_seconds = ( $dining_block * 60 - 1 ); // Take 1 second off, to avoid bookings that start or end exactly at the beginning of a booking block
|
53 |
-
|
54 |
// Get opening/closing times for this particular day
|
55 |
$hours = $this->get_opening_hours();
|
56 |
-
|
57 |
// If the restaurant is closed that day, return false
|
58 |
if ( ! $hours ) { echo $hours; die(); }
|
59 |
-
|
60 |
$args = array(
|
61 |
-
'
|
62 |
'date_range' => 'dates',
|
63 |
'start_date' => $this->year . '-' . $this->month . '-' . $this->day,
|
64 |
'end_date' => $this->year . '-' . $this->month . '-' . $this->day
|
65 |
);
|
66 |
-
|
67 |
require_once( RTB_PLUGIN_DIR . '/includes/Query.class.php' );
|
68 |
$query = new rtbQuery( $args );
|
69 |
$query->prepare_args();
|
@@ -73,37 +73,44 @@ class rtbAJAX {
|
|
73 |
foreach ( $query->get_bookings() as $booking ) {
|
74 |
$times[] = strtotime( $booking->date );
|
75 |
}
|
76 |
-
|
77 |
sort( $times );
|
78 |
-
|
79 |
// Go through all current booking times and figure out when we're at or above the max
|
80 |
$blocked = false;
|
81 |
$blocked_times = array();
|
82 |
-
$current_times = array();
|
83 |
if ($max_reservations != 'undefined' and $max_reservations != 0) {
|
84 |
-
foreach ( $times as $time ) {
|
85 |
$current_times[] = $time;
|
86 |
|
87 |
-
while ( sizeOf( $current_times ) > 0 and reset( $current_times ) < $time - $dining_block_seconds ) {
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
}
|
93 |
|
94 |
// Check if we're at or above the maximum number of reservations
|
95 |
-
if ( sizeOf( $current_times ) >= $max_reservations ) {
|
96 |
$blocked = true;
|
97 |
$blocked_times[] = $time - $dining_block_seconds;
|
98 |
}
|
99 |
}
|
100 |
}
|
101 |
-
|
102 |
if ( $blocked ) { $blocked_times[] = end( $current_times ) + $dining_block_seconds; }
|
103 |
-
|
104 |
$combined_times = array_merge( $blocked_times, $hours );
|
105 |
sort( $combined_times );
|
106 |
-
|
107 |
//Go through all of times to determine when the restaurant is open and not blocked
|
108 |
$open = false;
|
109 |
$blocked = false;
|
@@ -132,9 +139,9 @@ class rtbAJAX {
|
|
132 |
}
|
133 |
}
|
134 |
}
|
135 |
-
|
136 |
echo json_encode( $valid_times );
|
137 |
-
|
138 |
die();
|
139 |
}
|
140 |
|
42 |
|
43 |
$max_reservations_setting = $rtb_controller->settings->get_setting( 'rtb-max-tables-count' );
|
44 |
$max_reservations = substr( $max_reservations_setting, 0, strpos( $max_reservations_setting, '_' ) );
|
45 |
+
|
46 |
$this->year = sanitize_text_field( $_POST['year'] );
|
47 |
$this->month = sanitize_text_field( $_POST['month'] );
|
48 |
$this->day = sanitize_text_field( $_POST['day'] );
|
49 |
+
|
50 |
$dining_block_setting = $rtb_controller->settings->get_setting( 'rtb-dining-block-length' );
|
51 |
$dining_block = substr( $dining_block_setting, 0, strpos( $dining_block_setting, '_' ) );
|
52 |
$dining_block_seconds = ( $dining_block * 60 - 1 ); // Take 1 second off, to avoid bookings that start or end exactly at the beginning of a booking block
|
53 |
+
|
54 |
// Get opening/closing times for this particular day
|
55 |
$hours = $this->get_opening_hours();
|
56 |
+
|
57 |
// If the restaurant is closed that day, return false
|
58 |
if ( ! $hours ) { echo $hours; die(); }
|
59 |
+
|
60 |
$args = array(
|
61 |
+
'posts_per_page' => -1,
|
62 |
'date_range' => 'dates',
|
63 |
'start_date' => $this->year . '-' . $this->month . '-' . $this->day,
|
64 |
'end_date' => $this->year . '-' . $this->month . '-' . $this->day
|
65 |
);
|
66 |
+
|
67 |
require_once( RTB_PLUGIN_DIR . '/includes/Query.class.php' );
|
68 |
$query = new rtbQuery( $args );
|
69 |
$query->prepare_args();
|
73 |
foreach ( $query->get_bookings() as $booking ) {
|
74 |
$times[] = strtotime( $booking->date );
|
75 |
}
|
76 |
+
|
77 |
sort( $times );
|
78 |
+
|
79 |
// Go through all current booking times and figure out when we're at or above the max
|
80 |
$blocked = false;
|
81 |
$blocked_times = array();
|
82 |
+
$current_times = array();
|
83 |
if ($max_reservations != 'undefined' and $max_reservations != 0) {
|
84 |
+
foreach ( $times as $key => $time ) {
|
85 |
$current_times[] = $time;
|
86 |
|
87 |
+
while ( sizeOf( $current_times ) > 0 and reset( $current_times ) < $time - $dining_block_seconds ) {
|
88 |
+
//save the time to know when the blocking potentially ends
|
89 |
+
$removed_time = reset( $current_times );
|
90 |
+
|
91 |
+
// remove the expired time
|
92 |
+
array_shift( $current_times );
|
93 |
+
|
94 |
+
// remove the block if we've dropped below the max reservation count
|
95 |
+
if ( $blocked and sizeOf( $current_times ) < $max_reservations ) {
|
96 |
+
$blocked = false;
|
97 |
+
$blocked_times[] = $removed_time + $dining_block_seconds;
|
98 |
+
}
|
99 |
}
|
100 |
|
101 |
// Check if we're at or above the maximum number of reservations
|
102 |
+
if ( ! $blocked and sizeOf( $current_times ) >= $max_reservations ) {
|
103 |
$blocked = true;
|
104 |
$blocked_times[] = $time - $dining_block_seconds;
|
105 |
}
|
106 |
}
|
107 |
}
|
108 |
+
|
109 |
if ( $blocked ) { $blocked_times[] = end( $current_times ) + $dining_block_seconds; }
|
110 |
+
|
111 |
$combined_times = array_merge( $blocked_times, $hours );
|
112 |
sort( $combined_times );
|
113 |
+
|
114 |
//Go through all of times to determine when the restaurant is open and not blocked
|
115 |
$open = false;
|
116 |
$blocked = false;
|
139 |
}
|
140 |
}
|
141 |
}
|
142 |
+
|
143 |
echo json_encode( $valid_times );
|
144 |
+
|
145 |
die();
|
146 |
}
|
147 |
|
includes/Booking.class.php
CHANGED
@@ -459,21 +459,7 @@ class rtbBooking {
|
|
459 |
$this->message = empty( $_POST['rtb-message'] ) ? '' : nl2br( wp_kses_post( stripslashes_deep( $_POST['rtb-message'] ) ) );
|
460 |
|
461 |
// Post Status (define a default post status if none passed)
|
462 |
-
|
463 |
-
$this->post_status = sanitize_text_field( stripslashes_deep( $_POST['rtb-post-status'] ) );
|
464 |
-
} elseif ( $this->party < $rtb_controller->settings->get_setting( 'auto-confirm-max-party-size' ) ) {
|
465 |
-
$this->post_status = 'confirmed';
|
466 |
-
} else {
|
467 |
-
$this->post_status = 'pending';
|
468 |
-
}
|
469 |
-
|
470 |
-
// Check if the post status should be changed to confirmed, based on the maximum number of reservations and/or seats for auto-confirmation
|
471 |
-
if ( $rtb_controller->settings->get_setting( 'auto-confirm-max-reservations' ) ) {
|
472 |
-
$this->post_status = $this->under_max_confirm_reservations() ? 'confirmed' : $this->post_status;
|
473 |
-
}
|
474 |
-
if ( $rtb_controller->settings->get_setting( 'auto-confirm-max-seats' ) ) {
|
475 |
-
$this->post_status = $this->under_max_confirm_seats() ? 'confirmed' : $this->post_status;
|
476 |
-
}
|
477 |
|
478 |
// Consent
|
479 |
$require_consent = $rtb_controller->settings->get_setting( 'require-consent' );
|
@@ -636,17 +622,17 @@ class rtbBooking {
|
|
636 |
$max_reservations_setting = $rtb_controller->settings->get_setting( 'auto-confirm-max-reservations' );
|
637 |
$max_reservations = substr( $max_reservations_setting, 0, strpos( $max_reservations_setting, '_' ) );
|
638 |
|
639 |
-
if ($max_reservations == 'undefined' or $max_reservations
|
640 |
|
641 |
$dining_block_setting = $rtb_controller->settings->get_setting( 'rtb-dining-block-length' );
|
642 |
$dining_block = substr( $dining_block_setting, 0, strpos( $dining_block_setting, '_' ) );
|
643 |
$dining_block_seconds = ( $dining_block * 60 - 1 ); // Take 1 second off, to avoid bookings that start or end exactly at the beginning of a booking block
|
644 |
|
645 |
-
$after_time = strtotime($this->date) - $dining_block_seconds;
|
646 |
-
$before_time = strtotime($this->date) + $dining_block_seconds;
|
647 |
|
648 |
$args = array(
|
649 |
-
'
|
650 |
'date_query' => array(
|
651 |
'before' => date( 'c', $before_time ),
|
652 |
'after' => date( 'c', $after_time )
|
@@ -655,20 +641,21 @@ class rtbBooking {
|
|
655 |
|
656 |
require_once( RTB_PLUGIN_DIR . '/includes/Query.class.php' );
|
657 |
$query = new rtbQuery( $args );
|
|
|
658 |
|
659 |
$times = array();
|
660 |
foreach ( $query->get_bookings() as $booking ) {
|
661 |
$times[] = strtotime( $booking->date );
|
662 |
}
|
663 |
-
|
664 |
sort( $times );
|
665 |
|
666 |
$auto_confirm = true;
|
667 |
$current_times = array();
|
668 |
foreach ( $times as $time ) {
|
669 |
$current_times[] = $time;
|
670 |
-
|
671 |
-
if ( reset( $current_times ) < $time - $dining_block_seconds ) { array_shift( $current_times ); }
|
672 |
|
673 |
// Check if we've reached 1 below the max confirmation number, since adding the current booking will put us at the threshold
|
674 |
if ( sizeOf( $current_times ) + 1 >= $max_reservations ) { $auto_confirm = false; break; }
|
@@ -689,17 +676,17 @@ class rtbBooking {
|
|
689 |
$max_seats_setting = $rtb_controller->settings->get_setting( 'auto-confirm-max-seats' );
|
690 |
$max_seats = substr( $max_seats_setting, 0, strpos( $max_seats_setting, '_' ) );
|
691 |
|
692 |
-
if ($max_seats == 'undefined' or $max_seats
|
693 |
|
694 |
$dining_block_setting = $rtb_controller->settings->get_setting( 'rtb-dining-block-length' );
|
695 |
$dining_block = substr( $dining_block_setting, 0, strpos( $dining_block_setting, '_' ) );
|
696 |
$dining_block_seconds = ( $dining_block * 60 - 1 ); // Take 1 second off, to avoid bookings that start or end exactly at the beginning of a booking block
|
697 |
|
698 |
-
$after_time = strtotime($this->date) - $dining_block_seconds;
|
699 |
-
$before_time = strtotime($this->date) + $dining_block_seconds;
|
700 |
|
701 |
$args = array(
|
702 |
-
'
|
703 |
'date_query' => array(
|
704 |
'before' => date( 'c', $before_time ),
|
705 |
'after' => date( 'c', $after_time )
|
@@ -734,6 +721,29 @@ class rtbBooking {
|
|
734 |
return $auto_confirm;
|
735 |
}
|
736 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
737 |
/**
|
738 |
* Add a log entry to the booking
|
739 |
*
|
459 |
$this->message = empty( $_POST['rtb-message'] ) ? '' : nl2br( wp_kses_post( stripslashes_deep( $_POST['rtb-message'] ) ) );
|
460 |
|
461 |
// Post Status (define a default post status if none passed)
|
462 |
+
$this->determine_status();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
463 |
|
464 |
// Consent
|
465 |
$require_consent = $rtb_controller->settings->get_setting( 'require-consent' );
|
622 |
$max_reservations_setting = $rtb_controller->settings->get_setting( 'auto-confirm-max-reservations' );
|
623 |
$max_reservations = substr( $max_reservations_setting, 0, strpos( $max_reservations_setting, '_' ) );
|
624 |
|
625 |
+
if ($max_reservations == 'undefined' or $max_reservations <= 1) { return false; }
|
626 |
|
627 |
$dining_block_setting = $rtb_controller->settings->get_setting( 'rtb-dining-block-length' );
|
628 |
$dining_block = substr( $dining_block_setting, 0, strpos( $dining_block_setting, '_' ) );
|
629 |
$dining_block_seconds = ( $dining_block * 60 - 1 ); // Take 1 second off, to avoid bookings that start or end exactly at the beginning of a booking block
|
630 |
|
631 |
+
$after_time = strtotime($this->date) - $dining_block_seconds - (3600 * get_option( 'gmt_offset' ) );
|
632 |
+
$before_time = strtotime($this->date) + $dining_block_seconds - (3600 * get_option( 'gmt_offset' ) );
|
633 |
|
634 |
$args = array(
|
635 |
+
'posts_per_page' => -1,
|
636 |
'date_query' => array(
|
637 |
'before' => date( 'c', $before_time ),
|
638 |
'after' => date( 'c', $after_time )
|
641 |
|
642 |
require_once( RTB_PLUGIN_DIR . '/includes/Query.class.php' );
|
643 |
$query = new rtbQuery( $args );
|
644 |
+
$query->prepare_args();
|
645 |
|
646 |
$times = array();
|
647 |
foreach ( $query->get_bookings() as $booking ) {
|
648 |
$times[] = strtotime( $booking->date );
|
649 |
}
|
650 |
+
|
651 |
sort( $times );
|
652 |
|
653 |
$auto_confirm = true;
|
654 |
$current_times = array();
|
655 |
foreach ( $times as $time ) {
|
656 |
$current_times[] = $time;
|
657 |
+
//update_option("EWD_Debugging", reset( $current_times ) . " - " . ($time - $dining_block_seconds) . " - " . $dining_block_seconds);
|
658 |
+
if ( reset( $current_times ) < ($time - $dining_block_seconds) ) { array_shift( $current_times ); }
|
659 |
|
660 |
// Check if we've reached 1 below the max confirmation number, since adding the current booking will put us at the threshold
|
661 |
if ( sizeOf( $current_times ) + 1 >= $max_reservations ) { $auto_confirm = false; break; }
|
676 |
$max_seats_setting = $rtb_controller->settings->get_setting( 'auto-confirm-max-seats' );
|
677 |
$max_seats = substr( $max_seats_setting, 0, strpos( $max_seats_setting, '_' ) );
|
678 |
|
679 |
+
if ($max_seats == 'undefined' or $max_seats <= 1 or $this->party >= $max_seats) { return false; }
|
680 |
|
681 |
$dining_block_setting = $rtb_controller->settings->get_setting( 'rtb-dining-block-length' );
|
682 |
$dining_block = substr( $dining_block_setting, 0, strpos( $dining_block_setting, '_' ) );
|
683 |
$dining_block_seconds = ( $dining_block * 60 - 1 ); // Take 1 second off, to avoid bookings that start or end exactly at the beginning of a booking block
|
684 |
|
685 |
+
$after_time = strtotime($this->date) - $dining_block_seconds - (3600 * get_option( 'gmt_offset' ) );
|
686 |
+
$before_time = strtotime($this->date) + $dining_block_seconds - (3600 * get_option( 'gmt_offset' ) );
|
687 |
|
688 |
$args = array(
|
689 |
+
'posts_per_page' => -1,
|
690 |
'date_query' => array(
|
691 |
'before' => date( 'c', $before_time ),
|
692 |
'after' => date( 'c', $after_time )
|
721 |
return $auto_confirm;
|
722 |
}
|
723 |
|
724 |
+
/**
|
725 |
+
* Determine what status a booking should have
|
726 |
+
*
|
727 |
+
* @since 2.1.0
|
728 |
+
*/
|
729 |
+
public function determine_status( $payment_made = false ) {
|
730 |
+
global $rtb_controller;
|
731 |
+
|
732 |
+
if ( !empty( $_POST['rtb-post-status'] ) && array_key_exists( $_POST['rtb-post-status'], $rtb_controller->cpts->booking_statuses ) ) {
|
733 |
+
$this->post_status = sanitize_text_field( stripslashes_deep( $_POST['rtb-post-status'] ) );
|
734 |
+
} elseif ( $rtb_controller->settings->get_setting( 'require-deposit' ) and ! $payment_made ) {
|
735 |
+
$this->post_status = 'draft';
|
736 |
+
} elseif ( $this->party < $rtb_controller->settings->get_setting( 'auto-confirm-max-party-size' ) ) {
|
737 |
+
$this->post_status = 'confirmed';
|
738 |
+
} elseif ($rtb_controller->settings->get_setting( 'auto-confirm-max-reservations' ) and $this->under_max_confirm_reservations() ) {
|
739 |
+
$this->post_status = 'confirmed';
|
740 |
+
} elseif ( $rtb_controller->settings->get_setting( 'auto-confirm-max-seats' ) and $this->under_max_confirm_seats() ) {
|
741 |
+
$this->post_status = 'confirmed';
|
742 |
+
} else {
|
743 |
+
$this->post_status = 'pending';
|
744 |
+
}
|
745 |
+
}
|
746 |
+
|
747 |
/**
|
748 |
* Add a log entry to the booking
|
749 |
*
|
readme.txt
CHANGED
@@ -184,6 +184,10 @@ Find answers to even more questions in the [FAQ](http://doc.fivestarplugins.com/
|
|
184 |
|
185 |
== Changelog ==
|
186 |
|
|
|
|
|
|
|
|
|
187 |
= 2.0.13 (2020-02-14) =
|
188 |
- Adding in a separate success message option for automatically-confirmed bookings
|
189 |
- Updating the mPDF library
|
184 |
|
185 |
== Changelog ==
|
186 |
|
187 |
+
= 2.0.14 (2020-02-18) =
|
188 |
+
- Corrects issue in which all bookings were automatically confirming, even beyond the threshold set using the auto-confirm settings
|
189 |
+
- Corrects issue that was causing the max reservations setting to inaccurately set which time slots should be blocked off
|
190 |
+
|
191 |
= 2.0.13 (2020-02-14) =
|
192 |
- Adding in a separate success message option for automatically-confirmed bookings
|
193 |
- Updating the mPDF library
|
restaurant-reservations.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Five Star Restaurant Reservations
|
4 |
* Plugin URI: http://www.fivestarplugins.com/plugins/five-star-restaurant-reservations/
|
5 |
* Description: Restaurant reservations made easy. Accept bookings online. Quickly confirm or reject reservations, send email notifications, set booking times and more.
|
6 |
-
* Version: 2.0.
|
7 |
* Author: FiveStarPlugins
|
8 |
* Author URI: https://profiles.wordpress.org/fivestarplugins/
|
9 |
* Text Domain: restaurant-reservations
|
3 |
* Plugin Name: Five Star Restaurant Reservations
|
4 |
* Plugin URI: http://www.fivestarplugins.com/plugins/five-star-restaurant-reservations/
|
5 |
* Description: Restaurant reservations made easy. Accept bookings online. Quickly confirm or reject reservations, send email notifications, set booking times and more.
|
6 |
+
* Version: 2.0.14
|
7 |
* Author: FiveStarPlugins
|
8 |
* Author URI: https://profiles.wordpress.org/fivestarplugins/
|
9 |
* Text Domain: restaurant-reservations
|