abstract-booking-ability.php
5 months ago
approve-booking.php
5 months ago
cancel-booking.php
5 months ago
change-booking-status.php
5 months ago
create-booking.php
5 months ago
delete-booking.php
5 months ago
get-booking-stats.php
5 months ago
get-booking-statuses.php
5 months ago
get-booking.php
5 months ago
get-bookings-for-date.php
5 months ago
get-bookings-per-day.php
5 months ago
get-upcoming-bookings.php
5 months ago
list-bookings.php
5 months ago
reschedule-booking.php
5 months ago
update-booking.php
5 months ago
get-bookings-per-day.php
81 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; } |
| 4 | |
| 5 | class LatePointAbilityGetBookingsPerDay extends LatePointAbstractBookingAbility { |
| 6 | |
| 7 | protected function configure(): void { |
| 8 | $this->id = 'latepoint/get-bookings-per-day'; |
| 9 | $this->label = __( 'Get bookings per day', 'latepoint' ); |
| 10 | $this->description = __( 'Returns daily booking counts for a date range (histogram data).', 'latepoint' ); |
| 11 | $this->permission = 'booking__view'; |
| 12 | $this->read_only = true; |
| 13 | } |
| 14 | |
| 15 | public function get_input_schema(): array { |
| 16 | return [ |
| 17 | 'type' => 'object', |
| 18 | 'properties' => [ |
| 19 | 'date_from' => [ |
| 20 | 'type' => 'string', |
| 21 | 'format' => 'date', |
| 22 | 'description' => __( 'Period start (Y-m-d).', 'latepoint' ), |
| 23 | ], |
| 24 | 'date_to' => [ |
| 25 | 'type' => 'string', |
| 26 | 'format' => 'date', |
| 27 | 'description' => __( 'Period end (Y-m-d).', 'latepoint' ), |
| 28 | ], |
| 29 | 'agent_id' => [ 'type' => 'integer' ], |
| 30 | 'service_id' => [ 'type' => 'integer' ], |
| 31 | 'location_id' => [ 'type' => 'integer' ], |
| 32 | ], |
| 33 | 'required' => [ 'date_from', 'date_to' ], |
| 34 | ]; |
| 35 | } |
| 36 | |
| 37 | public function get_output_schema(): array { |
| 38 | return [ |
| 39 | 'type' => 'object', |
| 40 | 'properties' => [ |
| 41 | 'days' => [ |
| 42 | 'type' => 'array', |
| 43 | 'items' => [ |
| 44 | 'type' => 'object', |
| 45 | 'properties' => [ |
| 46 | 'date' => [ |
| 47 | 'type' => 'string', |
| 48 | 'format' => 'date', |
| 49 | ], |
| 50 | 'count' => [ 'type' => 'integer' ], |
| 51 | ], |
| 52 | ], |
| 53 | ], |
| 54 | ], |
| 55 | ]; |
| 56 | } |
| 57 | |
| 58 | public function execute( array $args ) { |
| 59 | $filter = new \LatePoint\Misc\Filter(); |
| 60 | $filter->agent_id = ! empty( $args['agent_id'] ) ? (int) $args['agent_id'] : 0; |
| 61 | $filter->service_id = ! empty( $args['service_id'] ) ? (int) $args['service_id'] : 0; |
| 62 | $filter->location_id = ! empty( $args['location_id'] ) ? (int) $args['location_id'] : 0; |
| 63 | |
| 64 | $rows = OsBookingHelper::get_total_bookings_per_day_for_period( |
| 65 | sanitize_text_field( $args['date_from'] ), |
| 66 | sanitize_text_field( $args['date_to'] ), |
| 67 | $filter |
| 68 | ); |
| 69 | |
| 70 | $days = array_map( |
| 71 | fn( $row ) => [ |
| 72 | 'date' => is_array( $row ) ? $row['start_date'] : $row->start_date, |
| 73 | 'count' => (int) ( is_array( $row ) ? $row['bookings_per_day'] : $row->bookings_per_day ), |
| 74 | ], |
| 75 | $rows |
| 76 | ); |
| 77 | |
| 78 | return [ 'days' => $days ]; |
| 79 | } |
| 80 | } |
| 81 |