PluginProbe
Booking Calendar / 11.6.1
Booking Calendar v11.6.1
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 10.11 All 204 releases
booking / includes / page-appointment-services / class-wpbc-catalog-inline-fields.php

class-wpbc-catalog-inline-fields.php in Booking Calendar 11.6.1, at includes/page-appointment-services/class-wpbc-catalog-inline-fields.php

79 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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