| @@ -554,8 +554,9 @@ | ||
| 554 | 554 | 'as_single_resource' => false, // get dates as for 'single resource' or 'parent' resource including bookings in all 'child booking resources'. |
| 555 | 555 | 'max_days_count' => wpbc_get_max_visible_days_in_calendar(), // 365. |
| 556 | 556 | 'timeslots_to_check_intersect' => array(), // arr: '12:20 - 12:55', '13:00 - 14:00' ) // TODO: ? do we really need it, because below we get it from function. |
| 557 | 557 | 'request_uri' => ( ( ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) ) ? $server_http_referer_uri : $server_request_uri ), // front-end: $server_request_uri | ajax: $server_http_referer_uri // It different in Ajax requests. It's used for change-over days to detect for exception at specific pages. |
| 558 | + 'allow_past' => false, | |
| 558 | 559 | 'custom_form' => '', // Required for checking all available time-slots and compare with booked time slots. |
| 559 | 560 | 'force_check_from_today_unavailable' => false, // Optional admin tools can force relative availability checks inside explicit date ranges. |
| 560 | 561 | ); |
| 561 | 562 | |
| @@ -562,8 +563,9 @@ | ||
| 562 | 563 | $params = wp_parse_args( $params, $defaults ); |
| 563 | 564 | |
| 564 | 565 | // FixIn: 10.7.1.2. //FixIn: 10.10.3.2. |
| 565 | 566 | if ( |
| 567 | + ( ! empty( $params['allow_past'] ) ) || | |
| 566 | 568 | ( false !== strpos( $params['request_uri'], 'allow_past' ) ) || |
| 567 | 569 | ( |
| 568 | 570 | wpbc_is_new_booking_page_url( $params['request_uri'] ) && |
| 569 | 571 | ( false !== strpos( $params['request_uri'], 'booking_hash' ) ) |
| @@ -691,9 +693,9 @@ | ||
| 691 | 693 | $is_this_hash_page = ( false !== strpos( $params['request_uri'], 'booking_hash' ) ) ? true : false; // Set it to TRUE for adding booking in past at Booking > Add booking page |
| 692 | 694 | |
| 693 | 695 | // FixIn: 10.7.1.2. |
| 694 | 696 | if ( ! $is_this_hash_page ) { |
| 695 | - $is_this_hash_page = ( false !== strpos( $params['request_uri'], 'allow_past' ) ) ? true : false; | |
| 697 | + $is_this_hash_page = ( ( ! empty( $params['allow_past'] ) ) || ( false !== strpos( $params['request_uri'], 'allow_past' ) ) ) ? true : false; | |
| 696 | 698 | } |
| 697 | 699 | |
| 698 | 700 | if ( ( $is_this_bap_page ) && ( $is_this_hash_page ) ) { // Start days in calendar from = PAST |
| 699 | 701 | $params['dates_to_check'] = 'ALL'; |
| @@ -722,12 +724,12 @@ | ||
| 722 | 724 | } else if ( is_array( $params['dates_to_check'] ) ) { |
| 723 | 725 | |
| 724 | 726 | $start_day_number = 1; |
| 725 | 727 | |
| 726 | - $today_inix_timestamp = strtotime( $params['dates_to_check'][0] . ' 00:00:00' ); // '2023-09-03 00:00:00' | |
| 728 | + $today_inix_timestamp = strtotime( $params['dates_to_check'][0] . ' 00:00:00 UTC' ); // '2023-09-03 00:00:00' | |
| 727 | 729 | |
| 728 | - $dif_in_days = strtotime( $params['dates_to_check'][ ( count( $params['dates_to_check'] ) - 1 ) ] . ' 00:00:00' ) | |
| 729 | - - strtotime( $params['dates_to_check'][0] . ' 00:00:00' ); | |
| 730 | + $dif_in_days = strtotime( $params['dates_to_check'][ ( count( $params['dates_to_check'] ) - 1 ) ] . ' 00:00:00 UTC' ) | |
| 731 | + - strtotime( $params['dates_to_check'][0] . ' 00:00:00 UTC' ); | |
| 730 | 732 | |
| 731 | 733 | $dif_in_days = $dif_in_days / ( 24 * 60 * 60 ); |
| 732 | 734 | $params['max_days_count'] = ceil( $dif_in_days ) + 1; |
| 733 | 735 | } |
| @@ -957,11 +959,20 @@ | ||
| 957 | 959 | |
| 958 | 960 | // ===================================================================================================== |
| 959 | 961 | // Change over days = |
| 960 | 962 | // ===================================================================================================== |
| 963 | + $is_booking_used_check_in_out_time = null; | |
| 964 | + if ( function_exists( 'wpbc_settings_calendar__preview_is_changeover_enabled' ) ) { | |
| 965 | + $is_booking_used_check_in_out_time = wpbc_settings_calendar__preview_is_changeover_enabled( $resource_id, $params['request_uri'] ); | |
| 966 | + } | |
| 967 | + if ( null === $is_booking_used_check_in_out_time ) { | |
| 968 | + $is_booking_used_check_in_out_time = ( | |
| 969 | + ( function_exists( 'wpbc_is_booking_used_check_in_out_time' ) ) | |
| 970 | + && ( wpbc_is_booking_used_check_in_out_time( $params['request_uri'], $resource_id ) ) | |
| 971 | + ); | |
| 972 | + } | |
| 961 | 973 | if ( |
| 962 | - ( function_exists( 'wpbc_is_booking_used_check_in_out_time' ) ) | |
| 963 | - && ( wpbc_is_booking_used_check_in_out_time( $params[ 'request_uri' ], $resource_id ) ) | |
| 974 | + $is_booking_used_check_in_out_time | |
| 964 | 975 | && ( ! $availability_per_day[ $my_day_tag ][ $resource_id ]->is_day_unavailable ) // And this date still free false |
| 965 | 976 | ) { |
| 966 | 977 | |
| 967 | 978 | /** |
| @@ -1046,8 +1057,36 @@ | ||
| 1046 | 1057 | } |
| 1047 | 1058 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 1048 | 1059 | // B O O K I N G S - E n d |
| 1049 | 1060 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 1061 | + // Working Time applies only to time-based booking forms: rangetime, start/end, or start/duration. | |
| 1062 | + $working_time__timeslots_to_check_intersect = $as_seconds_timeslots_arr__to_check_intersect; | |
| 1063 | + if ( empty( $working_time__timeslots_to_check_intersect ) && ! empty( $params['timeslots_to_check_intersect'] ) ) { | |
| 1064 | + if ( ! is_array( $params['timeslots_to_check_intersect'] ) ) { | |
| 1065 | + $params['timeslots_to_check_intersect'] = array( $params['timeslots_to_check_intersect'] ); | |
| 1066 | + } | |
| 1067 | + $working_time__timeslots_to_check_intersect = array(); | |
| 1068 | + foreach ( $params['timeslots_to_check_intersect'] as $time_slot_readable ) { | |
| 1069 | + $working_time__timeslots_to_check_intersect[] = wpbc_convert__readable_time_slot__to__time_range_in_seconds( $time_slot_readable ); | |
| 1070 | + } | |
| 1071 | + } | |
| 1072 | + | |
| 1073 | + if ( | |
| 1074 | + ! empty( $working_time__timeslots_to_check_intersect ) | |
| 1075 | + && function_exists( 'wpbc_working_time__get_non_working_intervals_for_date' ) | |
| 1076 | + && function_exists( 'wpbc_availability_timeslots__apply_blocks_to_availability_obj' ) | |
| 1077 | + ) { | |
| 1078 | + $working_time__blocked_intervals = wpbc_working_time__get_non_working_intervals_for_date( $resource_id, $my_day_tag ); | |
| 1079 | + | |
| 1080 | + if ( ! empty( $working_time__blocked_intervals ) ) { | |
| 1081 | + $availability_per_day[ $my_day_tag ][ $resource_id ] = wpbc_availability_timeslots__apply_blocks_to_availability_obj( | |
| 1082 | + $availability_per_day[ $my_day_tag ][ $resource_id ], | |
| 1083 | + $working_time__blocked_intervals, | |
| 1084 | + $working_time__timeslots_to_check_intersect | |
| 1085 | + ); | |
| 1086 | + } | |
| 1087 | + } | |
| 1088 | + | |
| 1050 | 1089 | // FixIn: 10.16.1. |
| 1051 | 1090 | if ( |
| 1052 | 1091 | function_exists( 'wpbc_availability_timeslots__apply_blocks_to_availability_obj' ) |
| 1053 | 1092 | && isset( $availability_timeslots__in_dates[ $my_day_tag ][ $resource_id ] ) |
| @@ -1218,8 +1257,9 @@ | ||
| 1218 | 1257 | $temp_status[] = $bookings_status_element; |
| 1219 | 1258 | } |
| 1220 | 1259 | } |
| 1221 | 1260 | $temp_status = array_filter( $temp_status ); // All entries of array equal to FALSE (0, '', '0' ) will be removed. |
| 1261 | + $temp_status_counts = array_count_values( $temp_status ); | |
| 1222 | 1262 | $temp_status = array_unique( $temp_status ); // Erase duplicates |
| 1223 | 1263 | $availability_per_this_day['summary']['status_for_day'] = $temp_status; |
| 1224 | 1264 | |
| 1225 | 1265 | /** |
| @@ -1244,10 +1284,34 @@ | ||
| 1244 | 1284 | // Priority: available > time_slots_booking > full_day_booking |
| 1245 | 1285 | // > season_filter > resource_availability |
| 1246 | 1286 | // > weekday_unavailable > from_today_unavailable > limit_available_from_today |
| 1247 | 1287 | |
| 1248 | - // if at least one booking "available" then day has this status | |
| 1288 | + // Capacity resources can be available even when every child has a check-in/out or full-day status. | |
| 1289 | + $max_capacity = isset( $availability_per_this_day['max_capacity'] ) ? intval( $availability_per_this_day['max_capacity'] ) : 1; | |
| 1290 | + $blocking_statuses = array( | |
| 1291 | + 'full_day_booking', | |
| 1292 | + 'season_filter', | |
| 1293 | + 'resource_availability', | |
| 1294 | + 'weekday_unavailable', | |
| 1295 | + 'from_today_unavailable', | |
| 1296 | + 'limit_available_from_today', | |
| 1297 | + 'change_over', | |
| 1298 | + ); | |
| 1299 | + $blocked_capacity = 0; | |
| 1300 | + foreach ( $blocking_statuses as $blocking_status ) { | |
| 1301 | + $blocked_capacity += isset( $temp_status_counts[ $blocking_status ] ) ? intval( $temp_status_counts[ $blocking_status ] ) : 0; | |
| 1302 | + } | |
| 1303 | + $booked_capacity__before_check_in = $blocked_capacity + ( isset( $temp_status_counts['check_out'] ) ? intval( $temp_status_counts['check_out'] ) : 0 ); | |
| 1304 | + $booked_capacity__after_check_in = $blocked_capacity + ( isset( $temp_status_counts['check_in'] ) ? intval( $temp_status_counts['check_in'] ) : 0 ); | |
| 1305 | + $is_capacity_available_during_change_over = ( | |
| 1306 | + ( $max_capacity > 1 ) | |
| 1307 | + && ( $max_capacity > max( $booked_capacity__before_check_in, $booked_capacity__after_check_in ) ) | |
| 1308 | + && ( ! in_array( 'time_slots_booking', $availability_per_this_day['summary']['status_for_day'] ) ) | |
| 1309 | + ); | |
| 1310 | + | |
| 1311 | + // if at least one resource is available then day has this status | |
| 1249 | 1312 | if ( in_array( 'available', $availability_per_this_day['summary']['status_for_day'] ) ) { $availability_per_this_day['summary']['status_for_day'] = 'available'; |
| 1313 | + } else if ( $is_capacity_available_during_change_over ) { $availability_per_this_day['summary']['status_for_day'] = 'available'; | |
| 1250 | 1314 | } else if ( in_array( 'time_slots_booking', $availability_per_this_day['summary']['status_for_day'] ) ) { $availability_per_this_day['summary']['status_for_day'] = 'time_slots_booking'; |
| 1251 | 1315 | } else if ( ( ! in_array( 'check_out', $availability_per_this_day['summary']['status_for_day'] ) ) |
| 1252 | 1316 | && ( in_array( 'check_in', $availability_per_this_day['summary']['status_for_day'] ) ) ) { $availability_per_this_day['summary']['status_for_day'] = 'check_in'; |
| 1253 | 1317 | } else if ( ( ! in_array( 'check_in', $availability_per_this_day['summary']['status_for_day'] ) ) |