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
get-bookings-for-date.php
62 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; } |
| 4 | |
| 5 | class LatePointAbilityGetBookingsForDate extends LatePointAbstractBookingAbility { |
| 6 | |
| 7 | protected function configure(): void { |
| 8 | $this->id = 'latepoint/get-bookings-for-date'; |
| 9 | $this->label = __( 'Get bookings for date', 'latepoint' ); |
| 10 | $this->description = __( 'Returns all bookings on a specific calendar date.', 'latepoint' ); |
| 11 | $this->permission = 'booking__view'; |
| 12 | $this->read_only = true; |
| 13 | } |
| 14 | |
| 15 | public function get_input_schema(): array { |
| 16 | $filters = $this->booking_filters_schema(); |
| 17 | return [ |
| 18 | 'type' => 'object', |
| 19 | 'properties' => array_merge( |
| 20 | [ |
| 21 | 'date' => [ |
| 22 | 'type' => 'string', |
| 23 | 'format' => 'date', |
| 24 | 'description' => __( 'Calendar date (Y-m-d).', 'latepoint' ), |
| 25 | ], |
| 26 | ], |
| 27 | array_intersect_key( $filters, array_flip( [ 'agent_id', 'service_id', 'location_id', 'status' ] ) ) |
| 28 | ), |
| 29 | 'required' => [ 'date' ], |
| 30 | ]; |
| 31 | } |
| 32 | |
| 33 | public function get_output_schema(): array { |
| 34 | return [ |
| 35 | 'type' => 'object', |
| 36 | 'properties' => [ |
| 37 | 'bookings' => [ |
| 38 | 'type' => 'array', |
| 39 | 'items' => $this->booking_output_schema(), |
| 40 | ], |
| 41 | 'total' => [ 'type' => 'integer' ], |
| 42 | ], |
| 43 | ]; |
| 44 | } |
| 45 | |
| 46 | public function execute( array $args ) { |
| 47 | $date = sanitize_text_field( $args['date'] ); |
| 48 | $query = new OsBookingModel(); |
| 49 | $query->where( [ 'start_date' => $date ] ); |
| 50 | $query = $this->apply_filters( $query, array_diff_key( $args, [ 'date' => '' ] ) ); |
| 51 | $query->order_by( 'start_time ASC' ); |
| 52 | |
| 53 | $bookings = $query->get_results_as_models(); |
| 54 | $bookings = is_array( $bookings ) ? $bookings : ( $bookings ? [ $bookings ] : [] ); |
| 55 | |
| 56 | return [ |
| 57 | 'bookings' => array_map( [ $this, 'serialize_booking' ], $bookings ), |
| 58 | 'total' => count( $bookings ), |
| 59 | ]; |
| 60 | } |
| 61 | } |
| 62 |