create-booking.php
3 weeks ago
delete-booking.php
3 weeks ago
get-booking-details.php
3 weeks ago
list-bookings.php
3 weeks ago
update-booking-status.php
3 weeks ago
delete-booking.php
114 lines
| 1 | <?php |
| 2 | /** |
| 3 | * DeleteBooking. |
| 4 | * php version 5.6 |
| 5 | * |
| 6 | * @category DeleteBooking |
| 7 | * @package SureTriggers |
| 8 | * @author BSF <username@example.com> |
| 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 10 | * @link https://www.brainstormforce.com/ |
| 11 | * @since 1.0.0 |
| 12 | */ |
| 13 | |
| 14 | namespace SureTriggers\Integrations\JetBooking\Actions; |
| 15 | |
| 16 | use SureTriggers\Integrations\AutomateAction; |
| 17 | use SureTriggers\Traits\SingletonLoader; |
| 18 | use SureTriggers\Integrations\JetBooking\JetBooking; |
| 19 | use JET_ABAF\Plugin; |
| 20 | |
| 21 | /** |
| 22 | * DeleteBooking |
| 23 | * |
| 24 | * @category DeleteBooking |
| 25 | * @package SureTriggers |
| 26 | * @author BSF <username@example.com> |
| 27 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 28 | * @link https://www.brainstormforce.com/ |
| 29 | * @since 1.0.0 |
| 30 | */ |
| 31 | class DeleteBooking extends AutomateAction { |
| 32 | |
| 33 | /** |
| 34 | * Integration type. |
| 35 | * |
| 36 | * @var string |
| 37 | */ |
| 38 | public $integration = 'JetBooking'; |
| 39 | |
| 40 | /** |
| 41 | * Action name. |
| 42 | * |
| 43 | * @var string |
| 44 | */ |
| 45 | public $action = 'jet_delete_booking'; |
| 46 | |
| 47 | use SingletonLoader; |
| 48 | |
| 49 | /** |
| 50 | * Register a action. |
| 51 | * |
| 52 | * @param array $actions actions. |
| 53 | * @return array |
| 54 | */ |
| 55 | public function register( $actions ) { |
| 56 | $actions[ $this->integration ][ $this->action ] = [ |
| 57 | 'label' => __( 'Delete Booking', 'suretriggers' ), |
| 58 | 'action' => 'jet_delete_booking', |
| 59 | 'function' => [ $this, 'action_listener' ], |
| 60 | ]; |
| 61 | |
| 62 | return $actions; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Action listener. |
| 67 | * |
| 68 | * @param int $user_id user_id. |
| 69 | * @param int $automation_id automation_id. |
| 70 | * @param array $fields fields. |
| 71 | * @param array $selected_options selectedOptions. |
| 72 | * |
| 73 | * @return array |
| 74 | */ |
| 75 | public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) { |
| 76 | |
| 77 | if ( ! class_exists( '\JET_ABAF\Plugin' ) ) { |
| 78 | return [ |
| 79 | 'status' => 'error', |
| 80 | 'message' => __( 'JetBooking plugin is not installed or active.', 'suretriggers' ), |
| 81 | ]; |
| 82 | } |
| 83 | |
| 84 | $booking_id = isset( $selected_options['booking_id'] ) ? absint( $selected_options['booking_id'] ) : 0; |
| 85 | |
| 86 | if ( empty( $booking_id ) ) { |
| 87 | return [ |
| 88 | 'status' => 'error', |
| 89 | 'message' => __( 'Booking ID is required.', 'suretriggers' ), |
| 90 | ]; |
| 91 | } |
| 92 | |
| 93 | $booking = JetBooking::get_booking( $booking_id ); |
| 94 | |
| 95 | if ( empty( $booking ) ) { |
| 96 | return [ |
| 97 | 'status' => 'error', |
| 98 | 'message' => sprintf( __( 'Booking not found with ID: %d', 'suretriggers' ), $booking_id ), |
| 99 | ]; |
| 100 | } |
| 101 | |
| 102 | Plugin::instance()->db->delete_booking( [ 'booking_id' => $booking_id ] ); |
| 103 | |
| 104 | return [ |
| 105 | 'success' => true, |
| 106 | 'booking_id' => $booking_id, |
| 107 | 'deleted_data' => $booking, |
| 108 | 'message' => sprintf( __( 'Booking with ID %d has been successfully deleted.', 'suretriggers' ), $booking_id ), |
| 109 | ]; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | DeleteBooking::get_instance(); |
| 114 |