| 1 |
<?php |
| 2 |
/** |
| 3 |
* Reusable sortable time-choice setup editor presentation. |
| 4 |
* |
| 5 |
* @package Booking Calendar |
| 6 |
* @var array<string,mixed> $template_context Authorized step context. |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
$step_data = isset( $template_context['step_data'] ) && is_array( $template_context['step_data'] ) ? $template_context['step_data'] : array(); |
| 14 |
$draft_field_name = isset( $step_data['draft_field_name'] ) ? sanitize_key( (string) $step_data['draft_field_name'] ) : 'start_end_times'; |
| 15 |
$draft_values = isset( $step_data['draft_values'] ) && is_array( $step_data['draft_values'] ) ? $step_data['draft_values'] : array(); |
| 16 |
$editor_title = isset( $step_data['editor_title'] ) ? sanitize_text_field( (string) $step_data['editor_title'] ) : __( 'Set booking times', 'booking' ); |
| 17 |
$editor_description = isset( $step_data['editor_description'] ) ? sanitize_text_field( (string) $step_data['editor_description'] ) : __( 'Choose the time options customers can use when booking.', 'booking' ); |
| 18 |
$validation_rule = isset( $step_data['validation_rule'] ) ? sanitize_key( (string) $step_data['validation_rule'] ) : 'independent_lists'; |
| 19 |
$list_definitions = isset( $step_data['list_definitions'] ) && is_array( $step_data['list_definitions'] ) ? $step_data['list_definitions'] : array(); |
| 20 |
$copy_action = isset( $step_data['copy_action'] ) && is_array( $step_data['copy_action'] ) ? $step_data['copy_action'] : array(); |
| 21 |
$interval_options = isset( $step_data['interval_options'] ) && is_array( $step_data['interval_options'] ) ? $step_data['interval_options'] : array(); |
| 22 |
$max_times_per_list = isset( $step_data['max_times_per_list'] ) ? absint( $step_data['max_times_per_list'] ) : 288; |
| 23 |
$time_increment = isset( $step_data['time_increment'] ) ? absint( $step_data['time_increment'] ) : 5; |
| 24 |
$draft_values_json = wp_json_encode( $draft_values ); |
| 25 |
$draft_values_json = false === $draft_values_json ? '{}' : $draft_values_json; |
| 26 |
$field_error_id = 'wpbc-setup-wizard-' . str_replace( '_', '-', $draft_field_name ) . '-error'; |
| 27 |
?> |
| 28 |
<section class="wpbc_setup_wizard__step-content wpbc_setup_wizard__time-choices-step" aria-labelledby="wpbc-setup-wizard-step-title"> |
| 29 |
<header class="wpbc_setup_wizard__step-heading"> |
| 30 |
<h1 id="wpbc-setup-wizard-step-title"><?php echo esc_html( $editor_title ); ?></h1> |
| 31 |
<p class="wpbc_setup_wizard__lead"><?php echo esc_html( $editor_description ); ?></p> |
| 32 |
</header> |
| 33 |
<?php |
| 34 |
$template_context['templates']->render( |
| 35 |
'settings-hint', |
| 36 |
array( 'settings_hint' => $template_context['settings_hint'] ) |
| 37 |
); |
| 38 |
?> |
| 39 |
|
| 40 |
<form id="wpbc-setup-wizard-step-form" novalidate> |
| 41 |
<input |
| 42 |
type="hidden" |
| 43 |
name="<?php echo esc_attr( $draft_field_name ); ?>" |
| 44 |
value="<?php echo esc_attr( $draft_values_json ); ?>" |
| 45 |
required |
| 46 |
data-wpbc-setup-wizard-field |
| 47 |
data-wpbc-time-choices-draft |
| 48 |
data-max-times="<?php echo esc_attr( (string) $max_times_per_list ); ?>" |
| 49 |
data-time-increment="<?php echo esc_attr( (string) $time_increment ); ?>" |
| 50 |
aria-describedby="<?php echo esc_attr( $field_error_id ); ?>" |
| 51 |
> |
| 52 |
|
| 53 |
<div |
| 54 |
class="wpbc_setup_wizard__time-choices-editor" |
| 55 |
data-wpbc-time-choices-editor |
| 56 |
data-field-id="<?php echo esc_attr( $draft_field_name ); ?>" |
| 57 |
data-validation-rule="<?php echo esc_attr( $validation_rule ); ?>" |
| 58 |
> |
| 59 |
<?php foreach ( $list_definitions as $raw_list_id => $raw_list_definition ) : ?> |
| 60 |
<?php |
| 61 |
$list_id = sanitize_key( (string) $raw_list_id ); |
| 62 |
$list_definition = is_array( $raw_list_definition ) ? $raw_list_definition : array(); |
| 63 |
$options = isset( $list_definition['options'] ) && is_array( $list_definition['options'] ) ? $list_definition['options'] : array(); |
| 64 |
$current_values = isset( $draft_values[ $list_id ] ) && is_array( $draft_values[ $list_id ] ) ? array_values( $draft_values[ $list_id ] ) : array(); |
| 65 |
$first_value = ! empty( $current_values ) ? (string) reset( $current_values ) : ( isset( $options[0]['value'] ) ? (string) $options[0]['value'] : '' ); |
| 66 |
$last_value = ! empty( $current_values ) ? (string) end( $current_values ) : ( isset( $options[ count( $options ) - 1 ]['value'] ) ? (string) $options[ count( $options ) - 1 ]['value'] : '' ); |
| 67 |
$list_title = isset( $list_definition['title'] ) ? (string) $list_definition['title'] : $list_id; |
| 68 |
$list_label = isset( $list_definition['list_label'] ) ? (string) $list_definition['list_label'] : $list_title; |
| 69 |
$generator_interval = isset( $list_definition['generator_interval'] ) ? absint( $list_definition['generator_interval'] ) : 30; |
| 70 |
$list_title_id = 'wpbc-setup-wizard-' . str_replace( '_', '-', $list_id ) . '-title'; |
| 71 |
?> |
| 72 |
|
| 73 |
<?php if ( ! empty( $copy_action ) && $list_id === sanitize_key( isset( $copy_action['target'] ) ? (string) $copy_action['target'] : '' ) ) : ?> |
| 74 |
<div class="wpbc_setup_wizard__time-copy-row" aria-label="<?php echo esc_attr( isset( $copy_action['aria_label'] ) ? (string) $copy_action['aria_label'] : '' ); ?>"> |
| 75 |
<span aria-hidden="true"></span> |
| 76 |
<button |
| 77 |
type="button" |
| 78 |
class="button button-secondary wpbc_setup_wizard__copy-start-times" |
| 79 |
data-wpbc-copy-times |
| 80 |
data-source-list="<?php echo esc_attr( sanitize_key( isset( $copy_action['source'] ) ? (string) $copy_action['source'] : '' ) ); ?>" |
| 81 |
data-target-list="<?php echo esc_attr( $list_id ); ?>" |
| 82 |
data-status="<?php echo esc_attr( isset( $copy_action['status'] ) ? (string) $copy_action['status'] : '' ); ?>" |
| 83 |
> |
| 84 |
<i class="menu_icon icon-1x wpbc_icn_arrow_forward" aria-hidden="true"></i> |
| 85 |
<span><?php echo esc_html( isset( $copy_action['label'] ) ? (string) $copy_action['label'] : '' ); ?></span> |
| 86 |
</button> |
| 87 |
<span aria-hidden="true"></span> |
| 88 |
</div> |
| 89 |
<?php endif; ?> |
| 90 |
|
| 91 |
<section class="wpbc_setup_wizard__time-list-panel" aria-labelledby="<?php echo esc_attr( $list_title_id ); ?>" data-wpbc-time-list-panel="<?php echo esc_attr( $list_id ); ?>"> |
| 92 |
<div class="wpbc_setup_wizard__time-list-toolbar"> |
| 93 |
<div class="wpbc_setup_wizard__time-list-heading"> |
| 94 |
<h2 id="<?php echo esc_attr( $list_title_id ); ?>"><?php echo esc_html( $list_title ); ?></h2> |
| 95 |
<p><?php echo esc_html( isset( $list_definition['description'] ) ? (string) $list_definition['description'] : '' ); ?></p> |
| 96 |
</div> |
| 97 |
|
| 98 |
<div class="wpbc_setup_wizard__time-generator" data-wpbc-time-generator="<?php echo esc_attr( $list_id ); ?>"> |
| 99 |
<label> |
| 100 |
<span><?php esc_html_e( 'From', 'booking' ); ?></span> |
| 101 |
<select data-wpbc-generator-from> |
| 102 |
<?php foreach ( $options as $option ) : ?> |
| 103 |
<option value="<?php echo esc_attr( (string) $option['value'] ); ?>" <?php selected( $first_value, (string) $option['value'] ); ?>><?php echo esc_html( (string) $option['label'] ); ?></option> |
| 104 |
<?php endforeach; ?> |
| 105 |
</select> |
| 106 |
</label> |
| 107 |
<label> |
| 108 |
<span><?php echo esc_html_x( 'To', 'range end', 'booking' ); ?></span> |
| 109 |
<select data-wpbc-generator-to> |
| 110 |
<?php foreach ( $options as $option ) : ?> |
| 111 |
<option value="<?php echo esc_attr( (string) $option['value'] ); ?>" <?php selected( $last_value, (string) $option['value'] ); ?>><?php echo esc_html( (string) $option['label'] ); ?></option> |
| 112 |
<?php endforeach; ?> |
| 113 |
</select> |
| 114 |
</label> |
| 115 |
<label> |
| 116 |
<span><?php esc_html_e( 'Every', 'booking' ); ?></span> |
| 117 |
<select data-wpbc-generator-interval> |
| 118 |
<?php foreach ( $interval_options as $interval_option ) : ?> |
| 119 |
<option value="<?php echo esc_attr( (string) $interval_option['value'] ); ?>" <?php selected( $generator_interval, (int) $interval_option['value'] ); ?>><?php echo esc_html( (string) $interval_option['label'] ); ?></option> |
| 120 |
<?php endforeach; ?> |
| 121 |
</select> |
| 122 |
</label> |
| 123 |
<button type="button" class="button button-secondary wpbc_setup_wizard__generate-times" data-wpbc-generate-times> |
| 124 |
<i class="menu_icon icon-1x wpbc_icn_add" aria-hidden="true"></i> |
| 125 |
<span><?php esc_html_e( 'Generate times', 'booking' ); ?></span> |
| 126 |
</button> |
| 127 |
</div> |
| 128 |
</div> |
| 129 |
|
| 130 |
<div class="wpbc_setup_wizard__time-list-body"> |
| 131 |
<div |
| 132 |
class="wpbc_setup_wizard__time-choice-list" |
| 133 |
data-wpbc-time-choice-list="<?php echo esc_attr( $list_id ); ?>" |
| 134 |
data-list-label="<?php echo esc_attr( $list_label ); ?>" |
| 135 |
data-clear-status="<?php echo esc_attr( isset( $list_definition['clear_status'] ) ? (string) $list_definition['clear_status'] : '' ); ?>" |
| 136 |
aria-label="<?php echo esc_attr( $list_label ); ?>" |
| 137 |
></div> |
| 138 |
<div class="wpbc_setup_wizard__time-list-actions"> |
| 139 |
<button type="button" class="button button-secondary wpbc_setup_wizard__add-time" data-wpbc-add-time> |
| 140 |
<i class="menu_icon icon-1x wpbc_icn_add" aria-hidden="true"></i> |
| 141 |
<span><?php echo esc_html( isset( $list_definition['add_label'] ) ? (string) $list_definition['add_label'] : __( 'Add one choice', 'booking' ) ); ?></span> |
| 142 |
</button> |
| 143 |
<button |
| 144 |
type="button" |
| 145 |
class="button-link wpbc_setup_wizard__clear-times" |
| 146 |
data-wpbc-clear-times |
| 147 |
aria-label="<?php echo esc_attr( isset( $list_definition['clear_aria_label'] ) ? (string) $list_definition['clear_aria_label'] : '' ); ?>" |
| 148 |
> |
| 149 |
<?php esc_html_e( 'Clear times', 'booking' ); ?> |
| 150 |
</button> |
| 151 |
</div> |
| 152 |
</div> |
| 153 |
</section> |
| 154 |
|
| 155 |
<template data-wpbc-time-choice-template="<?php echo esc_attr( $list_id ); ?>"> |
| 156 |
<div class="wpbc_setup_wizard__time-choice"> |
| 157 |
<button type="button" class="wpbc_setup_wizard__time-choice-move" data-wpbc-move-time> |
| 158 |
<i class="menu_icon icon-1x wpbc_icn_drag_indicator" aria-hidden="true"></i> |
| 159 |
<span class="screen-reader-text"><?php esc_html_e( 'Move time choice', 'booking' ); ?></span> |
| 160 |
</button> |
| 161 |
<label class="screen-reader-text" data-wpbc-time-choice-label><?php esc_html_e( 'Time choice', 'booking' ); ?></label> |
| 162 |
<select data-wpbc-time-choice> |
| 163 |
<?php foreach ( $options as $option ) : ?> |
| 164 |
<option value="<?php echo esc_attr( (string) $option['value'] ); ?>"><?php echo esc_html( (string) $option['label'] ); ?></option> |
| 165 |
<?php endforeach; ?> |
| 166 |
</select> |
| 167 |
<button type="button" class="wpbc_setup_wizard__time-choice-remove" data-wpbc-remove-time> |
| 168 |
<i class="menu_icon icon-1x wpbc_icn_delete_outline" aria-hidden="true"></i> |
| 169 |
<span class="screen-reader-text"><?php esc_html_e( 'Remove time choice', 'booking' ); ?></span> |
| 170 |
</button> |
| 171 |
</div> |
| 172 |
</template> |
| 173 |
<?php endforeach; ?> |
| 174 |
</div> |
| 175 |
|
| 176 |
<span class="wpbc_setup_wizard__field-error wpbc_setup_wizard__field-error--group" id="<?php echo esc_attr( $field_error_id ); ?>" data-wpbc-setup-wizard-error-for="<?php echo esc_attr( $draft_field_name ); ?>"></span> |
| 177 |
</form> |
| 178 |
</section> |
| 179 |
|