PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.6.10
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.6.10
5.6.10 5.6.9 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 / customers / get-customer-bookings.php
latepoint / lib / abilities / customers Last commit date
abstract-customer-ability.php 5 months ago connect-customer-to-wp-user.php 1 month ago create-customer.php 5 months ago delete-customer.php 1 month ago get-customer-bookings.php 1 month ago get-customer-by-email.php 1 month ago get-customer-orders.php 1 month ago get-customer.php 1 month ago get-total-customers-count.php 1 month ago list-customers.php 1 month ago search-customers.php 1 month ago update-customer.php 1 month ago
get-customer-bookings.php
100 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 class LatePointAbilityGetCustomerBookings extends LatePointAbstractCustomerAbility {
7
8 protected function configure(): void {
9 $this->id = 'latepoint/get-customer-bookings';
10 $this->label = __( 'Get customer bookings', 'latepoint' );
11 $this->description = __( 'Returns bookings for a specific customer, with optional future/past/status filter.', 'latepoint' );
12 $this->permission = 'customer__view';
13 $this->read_only = true;
14 }
15
16 public function get_input_schema(): array {
17 return [
18 'type' => 'object',
19 'properties' => array_merge(
20 self::pagination(),
21 [
22 'customer_id' => [
23 'type' => 'integer',
24 'description' => __( 'Customer ID.', 'latepoint' ),
25 ],
26 'status' => [
27 'type' => 'string',
28 'description' => __( 'Filter by booking status.', 'latepoint' ),
29 ],
30 'time_scope' => [
31 'type' => 'string',
32 'enum' => [ 'upcoming', 'past', 'all' ],
33 'default' => 'all',
34 'description' => __( 'Time scope filter.', 'latepoint' ),
35 ],
36 ]
37 ),
38 'required' => [ 'customer_id' ],
39 ];
40 }
41
42 public function get_output_schema(): array {
43 return [
44 'type' => 'object',
45 'properties' => [
46 'bookings' => [
47 'type' => 'array',
48 'items' => [ 'type' => 'object' ],
49 ],
50 'total' => [ 'type' => 'integer' ],
51 'page' => [ 'type' => 'integer' ],
52 'per_page' => [ 'type' => 'integer' ],
53 ],
54 ];
55 }
56
57 public function execute( array $args ) {
58 $customer = new OsCustomerModel( (int) $args['customer_id'] );
59 if ( $customer->is_new_record() ) {
60 return new WP_Error( 'not_found', __( 'Customer not found.', 'latepoint' ), [ 'status' => 404 ] );
61 }
62 $auth = $this->authorize_record( $customer, 'view' );
63 if ( is_wp_error( $auth ) ) {
64 return $auth;
65 }
66
67 $page = max( 1, (int) ( $args['page'] ?? 1 ) );
68 $per_page = min( 100, max( 1, (int) ( $args['per_page'] ?? 20 ) ) );
69 $offset = ( $page - 1 ) * $per_page;
70 $scope = $args['time_scope'] ?? 'all';
71
72 $query = ( new OsBookingModel() )->where( [ 'customer_id' => $customer->id ] );
73 $query->filter_allowed_records();
74
75 if ( ! empty( $args['status'] ) ) {
76 $query->where( [ 'status' => sanitize_text_field( $args['status'] ) ] );
77 }
78 if ( $scope === 'upcoming' ) {
79 $query->where( [ 'start_date >=' => wp_date( 'Y-m-d' ) ] );
80 } elseif ( $scope === 'past' ) {
81 $query->where( [ 'start_date <' => wp_date( 'Y-m-d' ) ] );
82 }
83
84 $bookings = ( clone $query )
85 ->order_by( 'start_date ASC, start_time ASC' )
86 ->set_limit( $per_page )
87 ->set_offset( $offset )
88 ->get_results_as_models();
89 $total = $query->count();
90
91 $booking_serializer = new LatePointAbilityListBookings();
92 return [
93 'bookings' => array_map( [ $booking_serializer, 'serialize_booking' ], $bookings ),
94 'total' => (int) $total,
95 'page' => $page,
96 'per_page' => $per_page,
97 ];
98 }
99 }
100