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-fixed-time-slots / class-wpbc-setup-wizard-fixed-time-slots-save-handler.php

class-wpbc-setup-wizard-fixed-time-slots-save-handler.php in Booking Calendar 11.9, at includes/page-setup-wizard/step-fixed-time-slots/class-wpbc-setup-wizard-fixed-time-slots-save-handler.php

99 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Progressive save handler for Setup Wizard Fixed Time Slots.
4 *
5 * @package Booking Calendar
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Save validated Form Builder-compatible fixed slots to the checkpoint.
14 */
15 final class WPBC_Setup_Wizard_Fixed_Time_Slots_Save_Handler implements WPBC_Setup_Wizard_Step_Save_Handler {
16
17 /** @var WPBC_Setup_Wizard_Fixed_Time_Slots */
18 private $fixed_time_slots;
19
20 /**
21 * Build the handler around the reusable validator.
22 *
23 * @param WPBC_Setup_Wizard_Fixed_Time_Slots|null $fixed_time_slots Optional service for tests.
24 */
25 public function __construct( $fixed_time_slots = null ) {
26 $this->fixed_time_slots = $fixed_time_slots instanceof WPBC_Setup_Wizard_Fixed_Time_Slots
27 ? $fixed_time_slots
28 : new WPBC_Setup_Wizard_Fixed_Time_Slots();
29 }
30
31 /**
32 * Return the owned step identifier.
33 *
34 * @return string Stable step ID.
35 */
36 public function get_step_id() {
37 return 'fixed_time_slots';
38 }
39
40 /**
41 * Return the explicit action label.
42 *
43 * @param array<string,mixed> $checkpoint Current checkpoint.
44 * @param array<string,mixed> $step_context Authorized presentation context.
45 *
46 * @return string Translated action label.
47 */
48 public function get_primary_action_label( array $checkpoint, array $step_context = array() ) {
49 unset( $checkpoint, $step_context );
50
51 return __( 'Save & continue', 'booking' );
52 }
53
54 /**
55 * Revalidate and record the fixed-slot operation result.
56 *
57 * @param array<string,mixed> $validated_fields Validated current-step fields.
58 * @param array<string,mixed> $checkpoint Current checkpoint.
59 * @param array<string,mixed> $operation_context Stable operation metadata.
60 *
61 * @return array<string,mixed>|WP_Error Verified result or an error.
62 */
63 public function save( array $validated_fields, array $checkpoint, array $operation_context ) {
64 unset( $operation_context );
65
66 $journey_id = isset( $checkpoint['values']['customer_journey']['customer_journey'] )
67 ? sanitize_key( (string) $checkpoint['values']['customer_journey']['customer_journey'] )
68 : '';
69 if ( ! WPBC_Setup_Wizard_Customer_Journey_Policy::uses_fixed_time_slots_configuration( $journey_id ) ) {
70 return new WP_Error( 'wpbc_setup_wizard_fixed_time_slots_journey_invalid', __( 'Fixed time slots cannot be saved for the selected customer journey.', 'booking' ) );
71 }
72
73 $time_slots = isset( $validated_fields['fixed_time_slots'] ) ? $validated_fields['fixed_time_slots'] : array();
74 $time_slots = $this->fixed_time_slots->validate_fixed_time_slots( $time_slots, true );
75 if ( is_wp_error( $time_slots ) ) {
76 return $time_slots;
77 }
78
79 return array(
80 'status' => 'saved',
81 'summary' => __( 'Fixed time slots saved.', 'booking' ),
82 'canonical_fingerprint' => hash( 'sha256', wp_json_encode( $time_slots ) ),
83 'created_ids' => array(),
84 'updated_ids' => array(),
85 'warnings' => array(),
86 'writes_canonical_settings' => false,
87 );
88 }
89
90 /**
91 * Fixed slots do not complete the setup route.
92 *
93 * @return bool False.
94 */
95 public function is_terminal() {
96 return false;
97 }
98 }
99