booking
/
includes
/
page-setup-wizard
/
step-start-end-times
/
class-wpbc-setup-wizard-start-end-times-save-handler.php
class-wpbc-setup-wizard-start-end-times-save-handler.php in Booking Calendar 11.9, at includes/page-setup-wizard/step-start-end-times/class-wpbc-setup-wizard-start-end-times-save-handler.php
| 1 | <?php |
| 2 | /** |
| 3 | * Progressive save handler for Setup Wizard Start and End Times. |
| 4 | * |
| 5 | * @package Booking Calendar |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Save validated Form Builder-compatible time choices to the checkpoint. |
| 14 | * |
| 15 | * This handler intentionally records wizard metadata only. Applying the lists |
| 16 | * to `starttime` and `endtime` fields belongs to the later Booking Form step, |
| 17 | * which owns the selected template and canonical form mutation. |
| 18 | */ |
| 19 | final class WPBC_Setup_Wizard_Start_End_Times_Save_Handler implements WPBC_Setup_Wizard_Step_Save_Handler { |
| 20 | |
| 21 | /** @var WPBC_Setup_Wizard_Start_End_Times */ |
| 22 | private $start_end_times; |
| 23 | |
| 24 | /** |
| 25 | * Build the handler around the reusable validator. |
| 26 | * |
| 27 | * @param WPBC_Setup_Wizard_Start_End_Times|null $start_end_times Optional service for tests. |
| 28 | */ |
| 29 | public function __construct( $start_end_times = null ) { |
| 30 | $this->start_end_times = $start_end_times instanceof WPBC_Setup_Wizard_Start_End_Times |
| 31 | ? $start_end_times |
| 32 | : new WPBC_Setup_Wizard_Start_End_Times(); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Return the owned step identifier. |
| 37 | * |
| 38 | * @return string Stable step ID. |
| 39 | */ |
| 40 | public function get_step_id() { |
| 41 | return 'start_end_times'; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Return the explicit action label. |
| 46 | * |
| 47 | * @param array<string,mixed> $checkpoint Current checkpoint. |
| 48 | * @param array<string,mixed> $step_context Authorized presentation context. |
| 49 | * |
| 50 | * @return string Translated action label. |
| 51 | */ |
| 52 | public function get_primary_action_label( array $checkpoint, array $step_context = array() ) { |
| 53 | unset( $checkpoint, $step_context ); |
| 54 | |
| 55 | return __( 'Save & continue', 'booking' ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Revalidate and record the time-choice operation result. |
| 60 | * |
| 61 | * @param array<string,mixed> $validated_fields Validated current-step fields. |
| 62 | * @param array<string,mixed> $checkpoint Current checkpoint. |
| 63 | * @param array<string,mixed> $operation_context Stable operation metadata. |
| 64 | * |
| 65 | * @return array<string,mixed>|WP_Error Verified result or an error. |
| 66 | */ |
| 67 | public function save( array $validated_fields, array $checkpoint, array $operation_context ) { |
| 68 | unset( $operation_context ); |
| 69 | |
| 70 | $journey_id = isset( $checkpoint['values']['customer_journey']['customer_journey'] ) |
| 71 | ? sanitize_key( (string) $checkpoint['values']['customer_journey']['customer_journey'] ) |
| 72 | : ''; |
| 73 | if ( ! WPBC_Setup_Wizard_Customer_Journey_Policy::uses_start_end_configuration( $journey_id ) ) { |
| 74 | return new WP_Error( 'wpbc_setup_wizard_start_end_times_journey_invalid', __( 'Start and End Times cannot be saved for the selected customer journey.', 'booking' ) ); |
| 75 | } |
| 76 | |
| 77 | $time_choices = isset( $validated_fields['start_end_times'] ) ? $validated_fields['start_end_times'] : array(); |
| 78 | $time_choices = $this->start_end_times->validate_start_end_times( $time_choices, true ); |
| 79 | if ( is_wp_error( $time_choices ) ) { |
| 80 | return $time_choices; |
| 81 | } |
| 82 | |
| 83 | return array( |
| 84 | 'status' => 'saved', |
| 85 | 'summary' => __( 'Start and End Time choices saved.', 'booking' ), |
| 86 | 'canonical_fingerprint' => hash( 'sha256', wp_json_encode( $time_choices ) ), |
| 87 | 'created_ids' => array(), |
| 88 | 'updated_ids' => array(), |
| 89 | 'warnings' => array(), |
| 90 | 'writes_canonical_settings' => false, |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Time choices do not complete the setup route. |
| 96 | * |
| 97 | * @return bool False. |
| 98 | */ |
| 99 | public function is_terminal() { |
| 100 | return false; |
| 101 | } |
| 102 | } |
| 103 |