PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Application / Commands / Booking / Appointment / UpdateBookingStatusCommandHandler.php
ameliabooking / src / Application / Commands / Booking / Appointment Last commit date
AddAppointmentCommand.php 1 year ago AddAppointmentCommandHandler.php 2 months ago AddBookingCommand.php 1 year ago AddBookingCommandHandler.php 1 year ago ApproveBookingRemotelyCommand.php 1 year ago ApproveBookingRemotelyCommandHandler.php 2 months ago CancelBookingCommand.php 1 year ago CancelBookingCommandHandler.php 6 months ago CancelBookingRemotelyCommand.php 1 year ago CancelBookingRemotelyCommandHandler.php 1 month ago DeleteAppointmentCommand.php 1 year ago DeleteAppointmentCommandHandler.php 1 year ago DeleteBookingCommand.php 1 year ago DeleteBookingCommandHandler.php 10 months ago DeleteBookingRemotelyCommand.php 10 months ago DeleteBookingRemotelyCommandHandler.php 6 months ago GetAppointmentBookingsCommand.php 6 months ago GetAppointmentBookingsCommandHandler.php 2 months ago GetAppointmentCommand.php 7 years ago GetAppointmentCommandHandler.php 2 weeks ago GetAppointmentsCommand.php 1 year ago GetAppointmentsCommandHandler.php 2 weeks ago GetIcsCommand.php 6 months ago GetIcsCommandHandler.php 4 years ago GetTimeSlotsCommand.php 1 year ago GetTimeSlotsCommandHandler.php 1 month ago ReassignBookingCommand.php 1 year ago ReassignBookingCommandHandler.php 3 months ago RejectBookingRemotelyCommand.php 1 year ago RejectBookingRemotelyCommandHandler.php 4 months ago SuccessfulBookingCommand.php 1 year ago SuccessfulBookingCommandHandler.php 1 year ago UpdateAppointmentCommand.php 1 year ago UpdateAppointmentCommandHandler.php 3 months ago UpdateAppointmentNoteCommand.php 3 months ago UpdateAppointmentNoteCommandHandler.php 3 months ago UpdateAppointmentStatusCommand.php 1 year ago UpdateAppointmentStatusCommandHandler.php 2 months ago UpdateAppointmentTimeCommand.php 1 year ago UpdateAppointmentTimeCommandHandler.php 1 month ago UpdateBookingStatusCommand.php 1 year ago UpdateBookingStatusCommandHandler.php 5 months ago
UpdateBookingStatusCommandHandler.php
125 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\Booking\Appointment;
4
5 use AmeliaBooking\Application\Commands\CommandHandler;
6 use AmeliaBooking\Application\Commands\CommandResult;
7 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
8 use AmeliaBooking\Domain\Common\Exceptions\BookingCancellationException;
9 use AmeliaBooking\Domain\Common\Exceptions\BookingUnavailableException;
10 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
11 use AmeliaBooking\Domain\Entity\Booking\Appointment\CustomerBooking;
12 use AmeliaBooking\Domain\Entity\Entities;
13 use AmeliaBooking\Domain\Services\Reservation\ReservationServiceInterface;
14 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
15 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
16 use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\CustomerBookingRepository;
17 use AmeliaBooking\Infrastructure\Repository\User\ProviderRepository;
18 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
19
20 /**
21 * Class UpdateBookingStatusCommandHandler
22 *
23 * @package AmeliaBooking\Application\Commands\Booking\Appointment
24 */
25 class UpdateBookingStatusCommandHandler extends CommandHandler
26 {
27 /**
28 * @param UpdateBookingStatusCommand $command
29 *
30 * @return CommandResult
31 *
32 * @throws AccessDeniedException
33 * @throws InvalidArgumentException
34 * @throws NotFoundException
35 * @throws QueryExecutionException
36 */
37 public function handle(UpdateBookingStatusCommand $command)
38 {
39 $result = new CommandResult();
40
41 /** @var CustomerBookingRepository $bookingRepository */
42 $bookingRepository = $this->container->get('domain.booking.customerBooking.repository');
43
44 /** @var CustomerBooking $booking */
45 $booking = $bookingRepository->getById((int)$command->getArg('id'));
46
47 $type = $booking->getAppointmentId() ? Entities::APPOINTMENT : Entities::EVENT;
48
49 /** @var ReservationServiceInterface $reservationService */
50 $reservationService = $this->container->get('application.reservation.service')->get($type);
51
52 if (
53 ($type === Entities::APPOINTMENT && !$command->getPermissionService()->currentUserCanWrite(Entities::APPOINTMENTS)) ||
54 ($type === Entities::EVENT && !$command->getPermissionService()->currentUserCanWrite(Entities::EVENTS))
55 ) {
56 throw new AccessDeniedException('You are not allowed to update booking status');
57 }
58
59 do_action('amelia_before_booking_' . $command->getField('status'), $booking->toArray());
60
61 $oldStatus = $booking->getStatus()->getValue();
62
63 try {
64 $bookingData = $reservationService->updateStatus($booking, $command->getField('status'), false);
65 } catch (BookingCancellationException $e) {
66 $result->setResult(CommandResult::RESULT_ERROR);
67 $result->setMessage('You are not allowed to update booking status');
68 $result->setData(
69 [
70 'updateBookingUnavailable' => true
71 ]
72 );
73
74 return $result;
75 } catch (BookingUnavailableException $e) {
76 $result->setResult(CommandResult::RESULT_ERROR);
77 $result->setMessage('Maximum capacity reached');
78 $result->setData(
79 [
80 'updateBookingUnavailable' => true,
81 'oldStatus' => $oldStatus,
82 'message' =>
83 BackendStrings::get('maximum_capacity_reached')
84 ]
85 );
86
87 return $result;
88 }
89
90 // Ensure provider's zoomUserId is included for Zoom integration
91 if ($type === Entities::APPOINTMENT && isset($bookingData[Entities::APPOINTMENT])) {
92 $appointment = &$bookingData[Entities::APPOINTMENT];
93
94 if (isset($appointment['providerId']) && empty($appointment['provider']['zoomUserId'])) {
95 /** @var ProviderRepository $providerRepository */
96 $providerRepository = $this->container->get('domain.users.providers.repository');
97
98 $provider = $providerRepository->getById($appointment['providerId']);
99
100 if ($provider && $provider->getZoomUserId()) {
101 $appointment['provider']['zoomUserId'] = $provider->getZoomUserId()->getValue();
102 }
103 }
104 }
105
106 $result->setResult(CommandResult::RESULT_SUCCESS);
107 $result->setMessage('Successfully updated booking status');
108 $result->setData(
109 array_merge(
110 $bookingData,
111 [
112 'type' => $type,
113 'status' => $command->getField('status'),
114 'message' =>
115 BackendStrings::get('booking_status_changed')
116 ]
117 )
118 );
119
120 do_action('amelia_after_booking_' . $command->getField('status'), $bookingData);
121
122 return $result;
123 }
124 }
125