WPBC_JS_IN_FOOTER ) ); wp_localize_script( 'wpbc-availability-timeslots-page', 'wpbc_availability_timeslots_page', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'wpbc_availability_timeslots_ajax_nonce' ), 'i18n' => array( 'select_slots_first' => __( 'Select one or more time ranges first.', 'booking' ), 'block_success' => __( 'Selected time ranges have been blocked.', 'booking' ), 'unblock_success' => __( 'Selected time ranges have been unblocked.', 'booking' ), 'save_error' => __( 'Unable to save time-slot availability.', 'booking' ), 'loading' => __( 'Loading', 'booking' ), 'open_booking' => __( 'Open booking in Booking Listing', 'booking' ), 'open_availability_rule' => __( 'Open availability settings', 'booking' ), 'select_one_slot_for_booking' => __( 'Select one time range on one date first.', 'booking' ), 'add_booking_modal_missing' => __( 'Add Booking popup is not available on this page.', 'booking' ), 'saving' => __( 'Saving', 'booking' ), ), ) ); } add_action( 'wpbc_enqueue_js_files', 'wpbc_availability_timeslots_enqueue_js_files', 66 ); /** * Get resource options for the Time Slots Availability component. * * @return array */ function wpbc_availability_timeslots__get_resources() { $resources = array(); if ( function_exists( 'wpbc_ajx_get_sorted_booking_resources_arr' ) && function_exists( 'wpbc_ajx_get_all_booking_resources_arr' ) ) { $resource_rows = wpbc_ajx_get_sorted_booking_resources_arr( wpbc_ajx_get_all_booking_resources_arr() ); foreach ( $resource_rows as $resource ) { $resources[] = array( 'id' => isset( $resource['booking_type_id'] ) ? (int) $resource['booking_type_id'] : 1, 'title' => isset( $resource['title'] ) ? $resource['title'] : __( 'Booking resource', 'booking' ), ); } } if ( empty( $resources ) ) { $resources[] = array( 'id' => wpbc_get_default_resource(), 'title' => '---', //__( 'Default Resource', 'booking' ), ); } return $resources; } /** * Get initial timeline rows. Real booked and blocked bars are loaded by AJAX. * * @param int $start_ts Start timestamp. * @param int $days_count Number of days. * * @return array */ function wpbc_availability_timeslots__get_initial_rows( $start_ts, $days_count = 7 ) { $rows = array(); $days_count = max( 1, intval( $days_count ) ); for ( $i = 0; $i < $days_count; $i++ ) { $ts = strtotime( '+' . $i . ' days', $start_ts ); $rows[] = array( 'date' => wp_date( 'Y-m-d', $ts ), 'label' => wp_date( 'D M j', $ts ), ); } return $rows; } /** * Get selectable time options from 00:00 to 24:00. * * @param int $selected_minutes Selected minute value. * * @return string */ function wpbc_availability_timeslots__get_time_options( $selected_minutes ) { $html = ''; for ( $minutes = 0; $minutes <= 1440; $minutes += 60 ) { $hours = (int) floor( $minutes / 60 ); $mins = $minutes % 60; $label = sprintf( '%02d:%02d', $hours, $mins ); $html .= sprintf( '', (int) $minutes, selected( $selected_minutes, $minutes, false ), esc_html( $label ) ); } return $html; } /** * Print slot step options. * * @param int $selected_step Selected step. * * @return void */ function wpbc_availability_timeslots__render_slot_step_options( $selected_step = 15 ) { $steps = array( 5 => __( '5 min', 'booking' ), 10 => __( '10 min', 'booking' ), 15 => __( '15 min', 'booking' ), 30 => __( '30 min', 'booking' ), 60 => __( '1 hour', 'booking' ), ); foreach ( $steps as $step => $label ) { ?>
'wpbc_ts', 'wrap_class' => 'wrap wpbc_ts_page wpdevelop', 'resource_id' => wpbc_get_default_resource(), 'resources' => null, 'start_ts' => strtotime( wp_date( 'Y-m-d 00:00:00' ) ), 'days_count' => 7, 'visible_start_minutes' => 360, 'visible_end_minutes' => 1320, 'slot_step' => 15, 'show_toolbar' => true, 'show_toolbar_actions' => true, 'show_hint' => true, 'show_legend' => true, 'auto_init' => true, ); $args = wp_parse_args( $args, $defaults ); $id_prefix = sanitize_key( $args['id_prefix'] ); $resource_id = (int) $args['resource_id']; $resources = is_array( $args['resources'] ) ? $args['resources'] : wpbc_availability_timeslots__get_resources(); $start_ts = (int) $args['start_ts']; $days_count = max( 1, intval( $args['days_count'] ) ); $end_ts = strtotime( '+' . ( $days_count - 1 ) . ' days', $start_ts ); $rows = wpbc_availability_timeslots__get_initial_rows( $start_ts, $days_count ); $visible_start_minutes = (int) $args['visible_start_minutes']; $visible_end_minutes = (int) $args['visible_end_minutes']; $slot_step = (int) $args['slot_step']; $ids = array( 'resource' => $id_prefix . '_resource', 'date_range' => $id_prefix . '_date_range', 'slot_step' => $id_prefix . '_slot_step', 'zoom' => $id_prefix . '_zoom', 'day_start' => $id_prefix . '_day_start', 'day_end' => $id_prefix . '_day_end', 'day_start_slider' => $id_prefix . '_day_start_slider', 'day_end_slider' => $id_prefix . '_day_end_slider', ); ?>