PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.5.0
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.5.0
5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / abilities / bookings / abstract-booking-ability.php
latepoint / lib / abilities / bookings Last commit date
abstract-booking-ability.php 4 months ago approve-booking.php 4 months ago cancel-booking.php 4 months ago change-booking-status.php 4 months ago create-booking.php 4 months ago delete-booking.php 4 months ago get-booking-stats.php 4 months ago get-booking-statuses.php 4 months ago get-booking.php 4 months ago get-bookings-for-date.php 4 months ago get-bookings-per-day.php 4 months ago get-upcoming-bookings.php 4 months ago list-bookings.php 4 months ago reschedule-booking.php 4 months ago update-booking.php 4 months ago
abstract-booking-ability.php
137 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 return $query;
57 }
58
59 protected function booking_output_schema(): array {
60 return [
61 'type' => 'object',
62 'properties' => [
63 'id' => [ 'type' => 'integer' ],
64 'status' => [ 'type' => 'string' ],
65 'customer_id' => [ 'type' => 'integer' ],
66 'agent_id' => [ 'type' => 'integer' ],
67 'service_id' => [ 'type' => 'integer' ],
68 'location_id' => [ 'type' => 'integer' ],
69 'start_date' => [
70 'type' => 'string',
71 'format' => 'date',
72 ],
73 'start_time' => [
74 'type' => 'integer',
75 'description' => __( 'Minutes from midnight.', 'latepoint' ),
76 ],
77 'end_time' => [
78 'type' => 'integer',
79 'description' => __( 'Minutes from midnight.', 'latepoint' ),
80 ],
81 'duration' => [
82 'type' => 'integer',
83 'description' => __( 'Duration in minutes.', 'latepoint' ),
84 ],
85 'customer_name' => [ 'type' => 'string' ],
86 'service_name' => [ 'type' => 'string' ],
87 'agent_name' => [ 'type' => 'string' ],
88 'notes' => [ 'type' => 'string' ],
89 'updated_at' => [
90 'type' => 'string',
91 'format' => 'date-time',
92 ],
93 'created_at' => [
94 'type' => 'string',
95 'format' => 'date-time',
96 ],
97 ],
98 ];
99 }
100
101 protected function booking_filters_schema(): array {
102 return [
103 'status' => [
104 'type' => 'string',
105 'enum' => [ 'approved', 'pending', 'cancelled', 'no_show', 'completed' ],
106 'description' => __( 'Filter by booking status.', 'latepoint' ),
107 ],
108 'agent_id' => [
109 'type' => 'integer',
110 'description' => __( 'Filter by agent ID.', 'latepoint' ),
111 ],
112 'service_id' => [
113 'type' => 'integer',
114 'description' => __( 'Filter by service ID.', 'latepoint' ),
115 ],
116 'location_id' => [
117 'type' => 'integer',
118 'description' => __( 'Filter by location ID.', 'latepoint' ),
119 ],
120 'customer_id' => [
121 'type' => 'integer',
122 'description' => __( 'Filter by customer ID.', 'latepoint' ),
123 ],
124 'date_from' => [
125 'type' => 'string',
126 'format' => 'date',
127 'description' => __( 'Start date filter (Y-m-d).', 'latepoint' ),
128 ],
129 'date_to' => [
130 'type' => 'string',
131 'format' => 'date',
132 'description' => __( 'End date filter (Y-m-d).', 'latepoint' ),
133 ],
134 ];
135 }
136 }
137