| 1 |
<?php |
| 2 |
/** |
| 3 |
* Appointment Services inline and bulk field definitions. |
| 4 |
* |
| 5 |
* @package Booking Calendar |
| 6 |
* @since 11.6.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Produce current Service editing fields without owning mutations. |
| 15 |
* |
| 16 |
* Field availability follows the current edition and authorized selection; |
| 17 |
* preview and apply services rebuild this contract before accepting values. |
| 18 |
* |
| 19 |
* @since 11.6.0 |
| 20 |
*/ |
| 21 |
final class WPBC_Appointment_Services_Catalog_Inline_Fields implements WPBC_UI_Catalog_Inline_Fields { |
| 22 |
|
| 23 |
/** |
| 24 |
* Return inline-safe fields for one authorized Service. |
| 25 |
* |
| 26 |
* @param array<string,mixed> $record Current authorized Service. |
| 27 |
* @return array<int,array<string,mixed>> Browser-safe field definitions. |
| 28 |
*/ |
| 29 |
public function get_inline_fields( $record ) { |
| 30 |
$fields = array( |
| 31 |
array( 'key' => 'title', 'column' => 'service', 'label' => __( 'Title', 'booking' ), 'type' => 'text', 'value' => isset( $record['title'] ) ? (string) $record['title'] : '', 'maxlength' => 200 ), |
| 32 |
array( 'key' => 'description', 'column' => 'service', 'label' => __( 'Description', 'booking' ), 'type' => 'textarea', 'value' => isset( $record['description'] ) ? (string) $record['description'] : '', 'maxlength' => 2000 ), |
| 33 |
array( 'key' => 'duration_minutes', 'column' => 'duration', 'label' => __( 'Duration', 'booking' ), 'type' => 'number', 'value' => isset( $record['duration_minutes'] ) ? (string) absint( $record['duration_minutes'] ) : '', 'min' => 1, 'max' => 1440, 'step' => 1 ), |
| 34 |
); |
| 35 |
if ( wpbc_appointment_services_is_pricing_available() ) { |
| 36 |
$fields[] = array( 'key' => 'base_cost', 'column' => 'price', 'label' => __( 'Price', 'booking' ), 'type' => 'number', 'value' => isset( $record['base_cost'] ) ? (string) $record['base_cost'] : '', 'min' => 0, 'max' => 1000, 'step' => 1 ); |
| 37 |
} |
| 38 |
|
| 39 |
return WPBC_UI_Catalog_Inline_Field_Schema::normalize_fields( $fields ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Return fields safely shared by every authorized Service. |
| 44 |
* |
| 45 |
* @param array<int,array<string,mixed>> $records Authorized Services. |
| 46 |
* @return array<int,array<string,mixed>> Common browser-safe fields. |
| 47 |
*/ |
| 48 |
public function get_bulk_fields( $records ) { |
| 49 |
$fields = array( |
| 50 |
array( 'key' => 'duration_minutes', 'label' => __( 'Duration', 'booking' ), 'type' => 'number', 'min' => 1, 'max' => 1440, 'step' => 1, 'default_value' => 30 ), |
| 51 |
array( 'key' => 'buffer_before_minutes', 'label' => __( 'Buffer before', 'booking' ), 'type' => 'number', 'min' => 0, 'max' => 1440, 'step' => 1, 'default_value' => 0 ), |
| 52 |
array( 'key' => 'buffer_after_minutes', 'label' => __( 'Buffer after', 'booking' ), 'type' => 'number', 'min' => 0, 'max' => 1440, 'step' => 1, 'default_value' => 0 ), |
| 53 |
array( |
| 54 |
'key' => 'status', |
| 55 |
'label' => __( 'Status', 'booking' ), |
| 56 |
'type' => 'select', |
| 57 |
'options' => array( |
| 58 |
array( 'value' => 'active', 'label' => __( 'Active', 'booking' ) ), |
| 59 |
array( 'value' => 'inactive', 'label' => __( 'Draft', 'booking' ) ), |
| 60 |
array( 'value' => 'archived', 'label' => __( 'Archived', 'booking' ) ), |
| 61 |
), |
| 62 |
), |
| 63 |
); |
| 64 |
if ( wpbc_appointment_services_is_pricing_available() ) { |
| 65 |
array_splice( $fields, 3, 0, array( array( 'key' => 'base_cost', 'label' => __( 'Price', 'booking' ), 'type' => 'number', 'min' => 0, 'max' => 1000, 'step' => 1, 'default_value' => 0 ) ) ); |
| 66 |
} |
| 67 |
$owner_ids = array_values( array_unique( array_map( 'absint', wp_list_pluck( $records, 'owner_user_id' ) ) ) ); |
| 68 |
if ( ! wpbc_appointment_services_can_view_all_owners() && 2 > count( $owner_ids ) ) { |
| 69 |
$form_options = array(); |
| 70 |
foreach ( wpbc_appointment_services_get_form_options() as $form_id => $form_label ) { |
| 71 |
$form_options[] = array( 'value' => (string) absint( $form_id ), 'label' => $form_label ); |
| 72 |
} |
| 73 |
array_splice( $fields, count( $fields ) - 1, 0, array( array( 'key' => 'booking_form_id', 'label' => __( 'Booking Form', 'booking' ), 'type' => 'select', 'options' => $form_options ) ) ); |
| 74 |
} |
| 75 |
|
| 76 |
return WPBC_UI_Catalog_Inline_Field_Schema::normalize_fields( $fields ); |
| 77 |
} |
| 78 |
} |
| 79 |
|