PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 All 205 releases
booking / includes / page-setup-wizard / step-days-off / class-wpbc-setup-wizard-days-off-module.php

class-wpbc-setup-wizard-days-off-module.php in Booking Calendar 11.9, at includes/page-setup-wizard/step-days-off/class-wpbc-setup-wizard-days-off-module.php

191 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Reusable module adapter for the Days Off setup editor.
4 *
5 * @package Booking Calendar
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Expose canonical date availability through the common setup-module contract.
14 */
15 final class WPBC_Setup_Wizard_Days_Off_Module implements WPBC_Setup_Wizard_Step_Module, WPBC_Setup_Wizard_Current_Values_Module {
16
17 /** @var WPBC_Setup_Wizard_Days_Off */
18 private $days_off;
19
20 /**
21 * Build the adapter around the Days Off domain service.
22 *
23 * @param WPBC_Setup_Wizard_Days_Off|null $days_off Optional service for composition.
24 */
25 public function __construct( $days_off = null ) {
26 $this->days_off = $days_off instanceof WPBC_Setup_Wizard_Days_Off ? $days_off : new WPBC_Setup_Wizard_Days_Off();
27 }
28
29 /**
30 * Return the stable step identifier used by the route and module registries.
31 *
32 * @return string Stable module identifier.
33 */
34 public function get_step_id() {
35 return 'days_off';
36 }
37
38 /**
39 * Define the registered page label, allow-listed template, and footer note.
40 *
41 * @return array<string,string> Step definition.
42 */
43 public function get_step_definition() {
44 return array(
45 'id' => $this->get_step_id(),
46 'label' => __( 'Days off and date availability', 'booking' ),
47 'template' => 'step-days-off',
48 'footer_note' => __( 'Add or remove dates here, then use Save & continue to update Days Availability.', 'booking' ),
49 );
50 }
51
52 /**
53 * Return the domain-owned template accepted by the shared template loader.
54 *
55 * @return string Absolute allow-listed template path.
56 */
57 public function get_template_path() {
58 return __DIR__ . '/template.php';
59 }
60
61 /**
62 * Return the staged Days Off transport field.
63 *
64 * @return string[] Staged transport field list.
65 */
66 public function get_field_names() {
67 return array( 'days_off' );
68 }
69
70 /**
71 * Require one complete staged availability snapshot.
72 *
73 * @return string[] Required staged transport field list.
74 */
75 public function get_required_fields() {
76 return array( 'days_off' );
77 }
78
79 /**
80 * Return canonical Availability as the initial staged proposal.
81 *
82 * @return array<string,mixed> Initial complete Availability proposal.
83 */
84 public function get_initial_values() {
85 return array( 'days_off' => $this->days_off->get_initial_staged_values() );
86 }
87
88 /**
89 * Refresh unavailable dates from current canonical Availability state.
90 *
91 * @return string[] Current-value field identifiers.
92 */
93 public function get_current_value_field_names() {
94 return $this->get_field_names();
95 }
96
97 /**
98 * Return no draft dependencies; authorization and canonical state are server-owned.
99 *
100 * @return string[] Empty dependency list.
101 */
102 public function get_context_dependencies() {
103 return array();
104 }
105
106 /**
107 * Return current canonical state for the domain-owned template.
108 *
109 * @param array<string,mixed> $field_values Validated staged Availability values.
110 * @param array<string,mixed> $consumer_context Unused consumer context.
111 *
112 * @return array<string,mixed> Authorized editor state.
113 */
114 public function get_context( array $field_values, array $consumer_context = array() ) {
115 unset( $consumer_context );
116
117 return $this->days_off->get_staged_state( isset( $field_values['days_off'] ) ? $field_values['days_off'] : $this->days_off->get_initial_staged_values() );
118 }
119
120 /**
121 * Validate the staged complete Availability proposal.
122 *
123 * @param string $field_id Field identifier.
124 * @param mixed $raw_value Submitted staged proposal.
125 * @param bool $is_required Whether the field was marked required.
126 *
127 * @return array<string,mixed>|WP_Error Normalized proposal or error.
128 */
129 public function validate_field( $field_id, $raw_value, $is_required ) {
130 if ( 'days_off' !== $field_id ) {
131 return new WP_Error( 'wpbc_setup_wizard_days_off_field_unknown', __( 'The Days Off editor received an unsupported field.', 'booking' ) );
132 }
133
134 return $this->days_off->validate_staged_values( $raw_value, $is_required );
135 }
136
137 /**
138 * Enqueue compiled module assets and the standard WPBC date picker.
139 *
140 * @param string $module_url Setup Wizard module URL.
141 * @param string|false $asset_version Plugin asset version.
142 * @param string $shared_style_handle Shared wizard style.
143 * @param string $shared_script_handle Shared wizard script.
144 *
145 * @return void
146 */
147 public function enqueue_assets( $module_url, $asset_version, $shared_style_handle, $shared_script_handle ) {
148 $module_url = trailingslashit( $module_url );
149 $script_dependencies = array( $shared_script_handle, 'wpbc-datepick' );
150
151 wp_enqueue_style( 'wpbc-calendar' );
152 wp_enqueue_script( 'wpbc-datepick' );
153 if ( wp_script_is( 'wpbc-datepick-localize', 'registered' ) ) {
154 wp_enqueue_script( 'wpbc-datepick-localize' );
155 $script_dependencies[] = 'wpbc-datepick-localize';
156 }
157 wp_enqueue_style( 'wpbc-setup-wizard-days-off', $module_url . 'step-days-off/_out/step-days-off.css', array( $shared_style_handle, 'wpbc-calendar' ), $asset_version );
158 wp_enqueue_script( 'wpbc-setup-wizard-days-off', $module_url . 'step-days-off/_out/step-days-off.js', $script_dependencies, $asset_version, true );
159 wp_localize_script(
160 'wpbc-setup-wizard-days-off',
161 'wpbc_setup_wizard_days_off',
162 array(
163 'ajax_url' => admin_url( 'admin-ajax.php' ),
164 'load_action' => WPBC_Setup_Wizard_Days_Off_Ajax::ACTION_LOAD,
165 'nonce' => wp_create_nonce( WPBC_Setup_Wizard_Ajax::NONCE_ACTION ),
166 'locale' => sanitize_text_field( determine_locale() ),
167 'i18n' => array(
168 'added' => __( 'The unavailable date range is staged. Save & continue to apply it.', 'booking' ),
169 'removed' => __( 'The unavailable date range removal is staged. Save & continue to apply it.', 'booking' ),
170 'error' => __( 'Date availability could not be loaded. Try again.', 'booking' ),
171 'range_invalid' => __( 'Select a valid unavailable date range.', 'booking' ),
172 'calendar_unavailable' => __( 'The date selector could not be loaded. Reload the page and try again.', 'booking' ),
173 'empty' => __( 'No upcoming unavailable dates.', 'booking' ),
174 'remove_range' => __( 'Remove unavailable date range', 'booking' ),
175 'all_booking_items' => __( 'All booking items', 'booking' ),
176 'one_unavailable_day' => __( '1 unavailable day', 'booking' ),
177 'unavailable' => __( 'Unavailable', 'booking' ),
178 'some_resources_unavailable' => __( 'Some booking items unavailable', 'booking' ),
179 'resources_have_bookings' => __( 'Bookings exist for one or more booking items', 'booking' ),
180 'approved_booking' => __( 'Approved booking', 'booking' ),
181 'pending_booking' => __( 'Pending booking', 'booking' ),
182 'partially_booked' => __( 'Partially booked', 'booking' ),
183 'partially_booked_pending' => __( 'Partially booked; pending booking', 'booking' ),
184 /* translators: %s: Number of unavailable days. */
185 'many_unavailable_days' => __( '%s unavailable days', 'booking' ),
186 ),
187 )
188 );
189 }
190 }
191