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-start-duration-times / class-wpbc-setup-wizard-start-duration-times-save-handler.php

class-wpbc-setup-wizard-start-duration-times-save-handler.php in Booking Calendar 11.9, at includes/page-setup-wizard/step-start-duration-times/class-wpbc-setup-wizard-start-duration-times-save-handler.php

99 lines 3.3 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 Start Time and Duration.
4 *
5 * @package Booking Calendar
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Save validated Form Builder-compatible choices to the checkpoint.
14 */
15 final class WPBC_Setup_Wizard_Start_Duration_Times_Save_Handler implements WPBC_Setup_Wizard_Step_Save_Handler {
16
17 /** @var WPBC_Setup_Wizard_Start_Duration_Times */
18 private $start_duration_times;
19
20 /**
21 * Build the handler around the reusable validator.
22 *
23 * @param WPBC_Setup_Wizard_Start_Duration_Times|null $start_duration_times Optional service for tests.
24 */
25 public function __construct( $start_duration_times = null ) {
26 $this->start_duration_times = $start_duration_times instanceof WPBC_Setup_Wizard_Start_Duration_Times
27 ? $start_duration_times
28 : new WPBC_Setup_Wizard_Start_Duration_Times();
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 'start_duration_times';
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 checkpoint-only proposal 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 Normalized save 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_start_duration_configuration( $journey_id ) ) {
70 return new WP_Error( 'wpbc_setup_wizard_start_duration_times_journey_invalid', __( 'Start Time and Duration choices cannot be saved for the selected customer journey.', 'booking' ) );
71 }
72
73 $time_choices = isset( $validated_fields['start_duration_times'] ) ? $validated_fields['start_duration_times'] : array();
74 $time_choices = $this->start_duration_times->validate_start_duration_times( $time_choices, true );
75 if ( is_wp_error( $time_choices ) ) {
76 return $time_choices;
77 }
78
79 return array(
80 'status' => 'saved',
81 'summary' => __( 'Start time and duration choices saved for the Booking Form step.', 'booking' ),
82 'canonical_fingerprint' => hash( 'sha256', wp_json_encode( $time_choices ) ),
83 'created_ids' => array(),
84 'updated_ids' => array(),
85 'warnings' => array(),
86 'writes_canonical_settings' => false,
87 );
88 }
89
90 /**
91 * Start Time and Duration choices do not complete the setup route.
92 *
93 * @return bool False.
94 */
95 public function is_terminal() {
96 return false;
97 }
98 }
99