abstract-booking-ability.php
1 week ago
approve-booking.php
4 months ago
cancel-booking.php
4 months ago
change-booking-status.php
1 week ago
create-booking.php
4 months ago
delete-booking.php
1 week ago
get-booking-stats.php
1 week ago
get-booking-statuses.php
4 months ago
get-booking.php
1 week ago
get-bookings-for-date.php
4 months ago
get-bookings-per-day.php
1 week ago
get-upcoming-bookings.php
4 months ago
list-bookings.php
4 months ago
reschedule-booking.php
1 week ago
update-booking.php
1 week ago
abstract-booking-ability.php
138 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Abstract base for booking abilities — shared serialize & filter helpers. |
| 4 | * |
| 5 | * @package LatePoint\Abilities |
| 6 | * @since 5.3.0 |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | abstract class LatePointAbstractBookingAbility extends LatePointAbstractAbility { |
| 14 | |
| 15 | public function serialize_booking( OsBookingModel $b ): array { |
| 16 | return [ |
| 17 | 'id' => (int) $b->id, |
| 18 | 'status' => (string) $b->status, |
| 19 | 'customer_id' => (int) $b->customer_id, |
| 20 | 'agent_id' => (int) $b->agent_id, |
| 21 | 'service_id' => (int) $b->service_id, |
| 22 | 'location_id' => (int) $b->location_id, |
| 23 | 'start_date' => (string) $b->start_date, |
| 24 | 'start_time' => (int) $b->start_time, |
| 25 | 'end_time' => (int) $b->end_time, |
| 26 | 'duration' => (int) $b->duration, |
| 27 | 'customer_name' => $b->customer ? trim( $b->customer->first_name . ' ' . $b->customer->last_name ) : '', |
| 28 | 'service_name' => $b->service ? (string) $b->service->name : '', |
| 29 | 'agent_name' => $b->agent ? trim( $b->agent->first_name . ' ' . $b->agent->last_name ) : '', |
| 30 | 'notes' => $b->order ? (string) ( $b->order->customer_comment ?? '' ) : '', |
| 31 | ]; |
| 32 | } |
| 33 | |
| 34 | protected function apply_filters( OsBookingModel $query, array $input ): OsBookingModel { |
| 35 | if ( ! empty( $input['status'] ) ) { |
| 36 | $query->where( [ 'status' => $input['status'] ] ); |
| 37 | } |
| 38 | if ( ! empty( $input['agent_id'] ) ) { |
| 39 | $query->where( [ 'agent_id' => (int) $input['agent_id'] ] ); |
| 40 | } |
| 41 | if ( ! empty( $input['service_id'] ) ) { |
| 42 | $query->where( [ 'service_id' => (int) $input['service_id'] ] ); |
| 43 | } |
| 44 | if ( ! empty( $input['location_id'] ) ) { |
| 45 | $query->where( [ 'location_id' => (int) $input['location_id'] ] ); |
| 46 | } |
| 47 | if ( ! empty( $input['customer_id'] ) ) { |
| 48 | $query->where( [ 'customer_id' => (int) $input['customer_id'] ] ); |
| 49 | } |
| 50 | if ( ! empty( $input['date_from'] ) ) { |
| 51 | $query->where( [ 'start_date >=' => sanitize_text_field( $input['date_from'] ) ] ); |
| 52 | } |
| 53 | if ( ! empty( $input['date_to'] ) ) { |
| 54 | $query->where( [ 'start_date <=' => sanitize_text_field( $input['date_to'] ) ] ); |
| 55 | } |
| 56 | $query->filter_allowed_records(); |
| 57 | return $query; |
| 58 | } |
| 59 | |
| 60 | protected function booking_output_schema(): array { |
| 61 | return [ |
| 62 | 'type' => 'object', |
| 63 | 'properties' => [ |
| 64 | 'id' => [ 'type' => 'integer' ], |
| 65 | 'status' => [ 'type' => 'string' ], |
| 66 | 'customer_id' => [ 'type' => 'integer' ], |
| 67 | 'agent_id' => [ 'type' => 'integer' ], |
| 68 | 'service_id' => [ 'type' => 'integer' ], |
| 69 | 'location_id' => [ 'type' => 'integer' ], |
| 70 | 'start_date' => [ |
| 71 | 'type' => 'string', |
| 72 | 'format' => 'date', |
| 73 | ], |
| 74 | 'start_time' => [ |
| 75 | 'type' => 'integer', |
| 76 | 'description' => __( 'Minutes from midnight.', 'latepoint' ), |
| 77 | ], |
| 78 | 'end_time' => [ |
| 79 | 'type' => 'integer', |
| 80 | 'description' => __( 'Minutes from midnight.', 'latepoint' ), |
| 81 | ], |
| 82 | 'duration' => [ |
| 83 | 'type' => 'integer', |
| 84 | 'description' => __( 'Duration in minutes.', 'latepoint' ), |
| 85 | ], |
| 86 | 'customer_name' => [ 'type' => 'string' ], |
| 87 | 'service_name' => [ 'type' => 'string' ], |
| 88 | 'agent_name' => [ 'type' => 'string' ], |
| 89 | 'notes' => [ 'type' => 'string' ], |
| 90 | 'updated_at' => [ |
| 91 | 'type' => 'string', |
| 92 | 'format' => 'date-time', |
| 93 | ], |
| 94 | 'created_at' => [ |
| 95 | 'type' => 'string', |
| 96 | 'format' => 'date-time', |
| 97 | ], |
| 98 | ], |
| 99 | ]; |
| 100 | } |
| 101 | |
| 102 | protected function booking_filters_schema(): array { |
| 103 | return [ |
| 104 | 'status' => [ |
| 105 | 'type' => 'string', |
| 106 | 'enum' => [ 'approved', 'pending', 'cancelled', 'no_show', 'completed' ], |
| 107 | 'description' => __( 'Filter by booking status.', 'latepoint' ), |
| 108 | ], |
| 109 | 'agent_id' => [ |
| 110 | 'type' => 'integer', |
| 111 | 'description' => __( 'Filter by agent ID.', 'latepoint' ), |
| 112 | ], |
| 113 | 'service_id' => [ |
| 114 | 'type' => 'integer', |
| 115 | 'description' => __( 'Filter by service ID.', 'latepoint' ), |
| 116 | ], |
| 117 | 'location_id' => [ |
| 118 | 'type' => 'integer', |
| 119 | 'description' => __( 'Filter by location ID.', 'latepoint' ), |
| 120 | ], |
| 121 | 'customer_id' => [ |
| 122 | 'type' => 'integer', |
| 123 | 'description' => __( 'Filter by customer ID.', 'latepoint' ), |
| 124 | ], |
| 125 | 'date_from' => [ |
| 126 | 'type' => 'string', |
| 127 | 'format' => 'date', |
| 128 | 'description' => __( 'Start date filter (Y-m-d).', 'latepoint' ), |
| 129 | ], |
| 130 | 'date_to' => [ |
| 131 | 'type' => 'string', |
| 132 | 'format' => 'date', |
| 133 | 'description' => __( 'End date filter (Y-m-d).', 'latepoint' ), |
| 134 | ], |
| 135 | ]; |
| 136 | } |
| 137 | } |
| 138 |