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
change-booking-status.php
61 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; } |
| 4 | |
| 5 | class LatePointAbilityChangeBookingStatus extends LatePointAbstractBookingAbility { |
| 6 | |
| 7 | protected function configure(): void { |
| 8 | $this->id = 'latepoint/change-booking-status'; |
| 9 | $this->label = __( 'Change booking status', 'latepoint' ); |
| 10 | $this->description = __( 'Changes a booking to any valid status value. Use get-booking-statuses to see available statuses. May trigger status-change notifications.', 'latepoint' ); |
| 11 | $this->permission = 'booking__edit'; |
| 12 | $this->read_only = false; |
| 13 | $this->destructive = false; |
| 14 | $this->idempotent = true; |
| 15 | } |
| 16 | |
| 17 | public function get_input_schema(): array { |
| 18 | return [ |
| 19 | 'type' => 'object', |
| 20 | 'properties' => [ |
| 21 | 'id' => [ |
| 22 | 'type' => 'integer', |
| 23 | 'description' => __( 'Booking ID.', 'latepoint' ), |
| 24 | ], |
| 25 | 'status' => [ |
| 26 | 'type' => 'string', |
| 27 | 'enum' => [ 'approved', 'pending', 'cancelled', 'no_show', 'completed' ], |
| 28 | 'description' => __( 'New status.', 'latepoint' ), |
| 29 | ], |
| 30 | ], |
| 31 | 'required' => [ 'id', 'status' ], |
| 32 | ]; |
| 33 | } |
| 34 | |
| 35 | public function get_output_schema(): array { |
| 36 | return $this->booking_output_schema(); |
| 37 | } |
| 38 | |
| 39 | public function execute( array $args ) { |
| 40 | $booking = new OsBookingModel( (int) $args['id'] ); |
| 41 | if ( $booking->is_new_record() ) { |
| 42 | return new WP_Error( 'not_found', __( 'Booking not found.', 'latepoint' ), [ 'status' => 404 ] ); |
| 43 | } |
| 44 | $auth = $this->authorize_record( $booking, 'edit' ); |
| 45 | if ( is_wp_error( $auth ) ) { |
| 46 | return $auth; |
| 47 | } |
| 48 | |
| 49 | $booking->status = sanitize_text_field( $args['status'] ); |
| 50 | if ( ! $booking->save() ) { |
| 51 | return new WP_Error( |
| 52 | 'save_failed', |
| 53 | __( 'Failed to update booking status.', 'latepoint' ), |
| 54 | WP_DEBUG ? [ 'errors' => $booking->get_error_messages() ] : [ 'status' => 422 ] |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | return $this->serialize_booking( new OsBookingModel( $booking->id ) ); |
| 59 | } |
| 60 | } |
| 61 |