PATH:
home
/
ediuae
/
petalwellnessspa.com
/
wp-content
/
plugins
/
simply-schedule-appointments
/
includes
<?php /** * Simply Schedule Appointments Block Booking. * * @since 2.4.0 * @package Simply_Schedule_Appointments */ /** * Simply Schedule Appointments Block Booking. * * @since 2.4.0 */ class SSA_Block_Booking { /** * Parent plugin class. * * @since 2.4.0 * * @var Simply_Schedule_Appointments */ protected $plugin = null; /** * Constructor. * * @since 2.4.0 * * @param Simply_Schedule_Appointments $plugin Main plugin object. */ public function __construct( $plugin ) { $this->plugin = $plugin; $this->hooks(); } /** * Initiate our hooks. * * @since 2.4.0 */ public function hooks() { add_action( 'init', array( $this, 'maybe_register_booking_block' ) ); } public function maybe_register_booking_block() { if( ssa_doing_async() ) { return; } if ( wp_doing_cron() ) { return; } if( ssa_is_json_request() ) { return; } if( ssa_is_file_request() ) { return; } if ( ! function_exists( 'register_block_type' ) ) { return; } return $this->register_booking_block(); } public function register_booking_block() { wp_register_script( 'ssa-booking-block-js', $this->plugin->url( 'assets/js/block-booking.js' ), array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-editor' ) ); wp_register_style( 'ssa-booking-block-css', $this->plugin->url( 'assets/css/block-booking.css' ) ); $appointment_types = $this->plugin->appointment_type_model->query( array( 'status' => 'publish', ) ); $ssa_appointment_key_values = wp_list_pluck( $appointment_types, 'title', 'slug' ); asort( $ssa_appointment_key_values ); wp_localize_script( 'ssa-booking-block-js', 'ssaAppointmentTypes', $ssa_appointment_key_values ); $appointment_type_labels = $this->plugin->appointment_type_label_model->query(); $ssa_appointment_label_key_values = wp_list_pluck( $appointment_type_labels, 'name', 'id' ); asort( $ssa_appointment_label_key_values ); wp_localize_script( 'ssa-booking-block-js', 'ssaAppointmentTypeLabels', $ssa_appointment_label_key_values ); /* Booking flow */ if ( ssa_should_render_booking_flow() ) { $booking_flow_options = array( 'main_booking_flow' => array( array( 'value' => 'appt_type_settings', 'label' => __('Use default settings from appointment type', 'simply-schedule-appointments'), ), array( 'value' => 'expanded', 'label' => __('Expanded', 'simply-schedule-appointments'), ), array( 'value' => 'express', 'label' => __('Express', 'simply-schedule-appointments'), ), array( 'value' => 'first_available', 'label' => __('First available', 'simply-schedule-appointments'), ), ), 'suggest_first_available' => array( 'duration' => array( 'value' => 0, 'label' => __('Duration', 'simply-schedule-appointments'), ), 'duration_unit' => array( array( 'value' => 'minutes', 'label' => __('Minutes', 'simply-schedule-appointments'), ), array( 'value' => 'hours', 'label' => __('Hours', 'simply-schedule-appointments'), ), array( 'value' => 'days', 'label' => __('Days', 'simply-schedule-appointments'), ), array( 'value' => 'weeks', 'label' => __('Weeks', 'simply-schedule-appointments'), ), ), ), 'fallback_flow' => array( array( 'value' => 'expanded', 'label' => __('Expanded', 'simply-schedule-appointments'), ), array( 'value' => 'express', 'label' => __('Express', 'simply-schedule-appointments'), ), ), 'date_view' => array( array( 'value' => 'week', 'label' => __('Weekly', 'simply-schedule-appointments'), ), array( 'value' => 'month', 'label' => __('Monthly', 'simply-schedule-appointments'), ), array( 'value' => 'only_available', 'label' => __('Only available dates', 'simply-schedule-appointments'), ), ), 'time_view' => array( array( 'value' => 'time_of_day_columns', 'label' => __('Time of day columns', 'simply-schedule-appointments'), ), array( 'value' => 'single_column', 'label' => __('Single column', 'simply-schedule-appointments'), ), ) ); wp_localize_script( 'ssa-booking-block-js', 'ssaBookingFlowOptions', $booking_flow_options ); } /* End booking flow */ /* Appointment types view */ $appointment_types_views_options = array( array( 'value' => 'cardList', 'label' => __('List', 'simply-schedule-appointments'), ), array( 'value' => 'cardGrid', 'label' => __('Grid', 'simply-schedule-appointments'), ), array( 'value' => 'cardColumns', 'label' => __('Two Columns', 'simply-schedule-appointments'), ), ); wp_localize_script( 'ssa-booking-block-js', 'ssaAppointmentTypesViewOptions', $appointment_types_views_options ); /* End appointment types view */ register_block_type( 'ssa/booking', array( 'editor_script' => 'ssa-booking-block-js', 'editor_style' => 'ssa-booking-block-css', 'keywords' => array( 'ssa', 'appointments', 'simply', 'booking' ), 'attributes' => array ( 'filter' => array ( 'type' => 'string', 'default' => '', ), 'type' => array ( 'type' => 'string', 'default' => '' , ), 'types' => array ( 'type' => 'array', 'default' => [] , ), 'label' => array ( 'type' => 'string', 'default' => '', ), /* Appointment type config */ 'appointment_types_view' => array( 'type' => 'string', 'default' => 'cardList', ), /* End appointment type config */ /* Booking flow config */ 'suggest_first_available' => array ( 'type' => 'string', 'default' => '', ), 'suggest_first_available_duration' => array ( 'type' => 'number', 'default' => 1, ), 'suggest_first_available_duration_unit' => array( 'type' => 'string', 'default' => 'week', ), 'flow' => array ( 'type' => 'string', 'default' => 'appt_type_settings', ), 'fallback_flow' => array ( 'type' => 'string', 'default' => 'expanded', ), 'time_view' => array ( 'type' => 'string', 'default' => 'time_of_day_columns', ), 'date_view' => array ( 'type' => 'string', 'default' => 'week', ), /* End booking flow config */ 'accent_color' => array ( 'type' => 'string', 'default' => '', ), 'background' => array ( 'type' => 'string', 'default' => '', ), 'padding' => array ( 'type' => 'number', 'default' => 0, ), 'padding_unit' => array ( 'type' => 'string', 'default' => '', ), ), 'render_callback' => array( $this, 'render' ), ) ); } function convertDurationToMinutes($duration, $unit) { // Validate if the duration is an integer $duration = filter_var($duration, FILTER_VALIDATE_INT); // If duration is not a valid integer, null, zero, or a negative integer return an error or null if ($duration === false || $duration <= 0) { return null; } switch ($unit) { case 'minutes': return $duration; case 'hours': return $duration * 60; case 'days': return $duration * 60 * 24; case 'weeks': return $duration * 60 * 24 * 7; default: return null; } } public function render( $settings ) { $attrs = array(); if ( $settings['filter'] === 'types' ) { $settings['label'] = ''; } elseif ( $settings['filter'] === 'label' ) { $settings['types'] = []; } if ( ! empty( $settings['types'] ) ) { if( in_array( 'All', $settings['types'] ) ) { $settings['types'] = []; $attrs['types'] = ''; } else { $attrs['types'] = implode( ",", $settings['types'] ); } } if ( ! empty( $settings['label'] ) ) { $attrs['types'] = ''; if( $settings['label'] !== 'All' ) { $attrs['label'] = $settings['label']; } } // After introducing the new checkboxes for appointmnent types // We still wanna check for the old settings['type'] if set; not to break the existing/old shortcodes // If found convert type to types and clear out type if( $settings['type'] && $settings['type'] !== '' ) { $attrs['types'] = $settings['type']; $settings['type'] = ''; } if( $settings['accent_color'] && $settings['accent_color'] !== '' ) { $attrs['accent_color'] = ltrim( $settings['accent_color'], '#'); } if( $settings['background'] && $settings['background'] !== '' ) { $attrs['background'] = ltrim( $settings['background'], '#' ); } if( $settings['padding'] && $settings['padding'] !== '' ) { // using '%' on the dropdown value causes a "malformed URI" issue on Gutenberg renderer, so this is // necessary $settings['padding_unit'] = $settings['padding_unit'] === 'percent' ? '%' : $settings['padding_unit']; $attrs['padding'] = $settings['padding'] . $settings['padding_unit']; } /* Appointment types view */ if ( $settings['appointment_types_view'] && $settings['appointment_types_view'] !== '' ) { $attrs['appointment_types_view'] = $settings['appointment_types_view']; } /* Booking Flow */ if ( ssa_should_render_booking_flow() ) { if ( $settings['flow'] !== 'appt_type_settings' && ! empty( $settings['flow'] ) ) { if ( $settings['flow'] === 'expanded' ) { $attrs['flow'] = $settings['flow']; $attrs['date_view'] = $settings['date_view']; $attrs['time_view'] = $settings['time_view']; } else if ( $settings['flow'] === 'express' ) { $attrs['flow'] = $settings['flow']; $attrs['time_view'] = $settings['time_view']; } else if ( $settings['flow'] === 'first_available' ) { $attrs['flow'] = $settings['flow']; $attrs['suggest_first_available'] = true; // Only available within $attrs['suggest_first_available_within_minutes'] = $this->convertDurationToMinutes( $settings['suggest_first_available_duration'], $settings['suggest_first_available_duration_unit'] ); // Fallback flow if ( $settings['fallback_flow'] === 'expanded' ) { $attrs['fallback_flow'] = $settings['fallback_flow']; $attrs['date_view'] = $settings['date_view']; $attrs['time_view'] = $settings['time_view']; } else if ( $settings['fallback_flow'] === 'express' ) { $attrs['fallback_flow'] = $settings['fallback_flow']; $attrs['time_view'] = $settings['time_view']; } } } } return $this->plugin->shortcodes->ssa_booking( $attrs ); } }
[-] class-settings.php
[edit]
[-] class-hooks.php
[edit]
[-] class-availability-query.php
[edit]
[-] class-appointment-model.php
[edit]
[-] class-beaver-builder.php
[edit]
[-] class-web-meetings.php
[edit]
[-] class-availability-model.php
[edit]
[-] class-recipient-admin.php
[edit]
[-] class-recipient-customer.php
[edit]
[-] class-constants.php
[edit]
[-] class-async-action-model.php
[edit]
[-] class-support.php
[edit]
[-] class-google-calendar-client.php
[edit]
[+]
..
[-] class-capabilities.php
[edit]
[-] class-encryption.php
[edit]
[-] class-availability-cache-invalidation.php
[edit]
[-] class-calendar-events-settings.php
[edit]
[-] class-settings-global.php
[edit]
[-] class-translation.php
[edit]
[-] class-cli.php
[edit]
[-] class-missing.php
[edit]
[-] class-action-scheduler.php
[edit]
[-] class-templates-api.php
[edit]
[-] class-blackout-dates.php
[edit]
[-] class-calendar-events-object.php
[edit]
[-] class-divi.php
[edit]
[-] class-templates.php
[edit]
[-] class-wp-admin.php
[edit]
[-] class-appointment-factory.php
[edit]
[-] class-scheduling-max-per-day.php
[edit]
[-] class-notifications-api.php
[edit]
[-] class-shortcodes.php
[edit]
[-] class-validation.php
[edit]
[-] class-resource-group-object-factory.php
[edit]
[-] class-payment-object.php
[edit]
[-] class-locale.php
[edit]
[-] class-ics-exporter.php
[edit]
[-] class-filesystem.php
[edit]
[-] class-recipient-shared.php
[edit]
[-] class-availability-schedule.php
[edit]
[-] class-block-upcoming-appointments.php
[edit]
[-] class-elementor.php
[edit]
[-] class-appointment-meta-model.php
[edit]
[-] class-revision-meta-model.php
[edit]
[+]
divi
[-] class-notifications.php
[edit]
[-] class-upgrade.php
[edit]
[-] class-utils.php
[edit]
[-] class-availability-functions.php
[edit]
[-] class-external-calendar-api.php
[edit]
[-] class-csv-exporter.php
[edit]
[-] class-external-google-calendar-api.php
[edit]
[-] class-twig-extension.php
[edit]
[-] class-bootstrap.php
[edit]
[-] class-notices.php
[edit]
[-] class-availability-schedule-factory.php
[edit]
[-] class-blackout-dates-settings.php
[edit]
[-] class-support-status.php
[edit]
[-] class-block-booking.php
[edit]
[-] class-advanced-scheduling-availability.php
[edit]
[-] class-exception.php
[edit]
[-] class-styles-settings.php
[edit]
[-] class-forms.php
[edit]
[-] class-recipient-staff.php
[edit]
[+]
beaver-builder
[-] class-users.php
[edit]
[-] class-sequence-factory.php
[edit]
[+]
third-party
[-] class-locales.php
[edit]
[-] class-db-model.php
[edit]
[-] class-db.php
[edit]
[-] class-availability-default.php
[edit]
[-] class-staff-settings.php
[edit]
[-] class-notification-model.php
[edit]
[-] class-settings-installed.php
[edit]
[-] class-appointment-object.php
[edit]
[-] class-notices-api.php
[edit]
[-] class-translation-settings.php
[edit]
[-] class-support-status-api.php
[edit]
[-] class-notices-data.php
[edit]
[-] class-appointment-type-object.php
[edit]
[-] class-appointment-type-object-factory.php
[edit]
[-] class-availability-block-factory.php
[edit]
[-] class-recipient.php
[edit]
[-] class-revision-model.php
[edit]
[-] class-customers.php
[edit]
[-] class-settings-api.php
[edit]
[-] class-cache.php
[edit]
[-] class-availability-detective-case.php
[edit]
[-] class-styles.php
[edit]
[-] class-capacity-settings.php
[edit]
[-] class-gcal-exporter.php
[edit]
[-] class-advanced-scheduling-settings.php
[edit]
[-] class-appointment-type-model.php
[edit]
[-] class-notifications-settings.php
[edit]
[-] class-period.php
[edit]
[-] class-external-api.php
[edit]
[-] class-error-notices.php
[edit]
[-] class-availability-cache.php
[edit]
[-] class-developer-settings.php
[edit]
[-] class-dashboard-upcoming-appointments-widget.php
[edit]
[-] class-availability-external-model.php
[edit]
[-] class-availability-block.php
[edit]
[-] class-customer-information.php
[edit]
[+]
elementor
[-] class-appointment-type-label-model.php
[edit]
[-] class-embed-booking-app-api.php
[edit]
[+]
lib
[-] class-sequence.php
[edit]
[-] class-debug.php
[edit]
[-] class-appointment-types-db.php
[edit]