PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 / DeleteBookingCommandHandler.php
ameliabooking / src / Application / Commands / Booking / Appointment Last commit date
AddAppointmentCommand.php 7 years ago AddAppointmentCommandHandler.php 1 year ago AddBookingCommand.php 7 years ago AddBookingCommandHandler.php 1 year ago ApproveBookingRemotelyCommand.php 2 years ago ApproveBookingRemotelyCommandHandler.php 1 year ago CancelBookingCommand.php 7 years ago CancelBookingCommandHandler.php 2 years ago CancelBookingRemotelyCommand.php 7 years ago CancelBookingRemotelyCommandHandler.php 2 years ago DeleteAppointmentCommand.php 7 years ago DeleteAppointmentCommandHandler.php 2 years ago DeleteBookingCommand.php 4 years ago DeleteBookingCommandHandler.php 2 years ago GetAppointmentCommand.php 7 years ago GetAppointmentCommandHandler.php 1 year ago GetAppointmentsCommand.php 7 years ago GetAppointmentsCommandHandler.php 1 year ago GetIcsCommand.php 5 years ago GetIcsCommandHandler.php 4 years ago GetPackageAppointmentsCommand.php 1 year ago GetPackageAppointmentsCommandHandler.php 1 year ago GetTimeSlotsCommand.php 7 years ago GetTimeSlotsCommandHandler.php 1 year ago ReassignBookingCommand.php 5 years ago ReassignBookingCommandHandler.php 1 year ago RejectBookingRemotelyCommand.php 2 years ago RejectBookingRemotelyCommandHandler.php 1 year ago SuccessfulBookingCommand.php 7 years ago SuccessfulBookingCommandHandler.php 1 year ago UpdateAppointmentCommand.php 7 years ago UpdateAppointmentCommandHandler.php 1 year ago UpdateAppointmentStatusCommand.php 7 years ago UpdateAppointmentStatusCommandHandler.php 1 year ago UpdateAppointmentTimeCommand.php 7 years ago UpdateAppointmentTimeCommandHandler.php 1 year ago UpdateBookingStatusCommand.php 1 year ago UpdateBookingStatusCommandHandler.php 1 year ago
DeleteBookingCommandHandler.php
111 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\Application\Services\Booking\BookingApplicationService;
9 use AmeliaBooking\Application\Services\Booking\AppointmentApplicationService;
10 use AmeliaBooking\Domain\Entity\Booking\Appointment\Appointment;
11 use AmeliaBooking\Domain\Entity\Booking\Appointment\CustomerBooking;
12 use AmeliaBooking\Domain\Entity\Entities;
13 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
14 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
15 use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\AppointmentRepository;
16 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
17 use Slim\Exception\ContainerValueNotFoundException;
18 use Interop\Container\Exception\ContainerException;
19
20 /**
21 * Class DeleteBookingCommandHandler
22 *
23 * @package AmeliaBooking\Application\Commands\Booking\Appointment
24 */
25 class DeleteBookingCommandHandler extends CommandHandler
26 {
27 /**
28 * @param DeleteBookingCommand $command
29 *
30 * @return CommandResult
31 * @throws InvalidArgumentException
32 * @throws ContainerValueNotFoundException
33 * @throws AccessDeniedException
34 * @throws QueryExecutionException
35 * @throws ContainerException
36 * @throws NotFoundException
37 */
38 public function handle(DeleteBookingCommand $command)
39 {
40 if (!$command->getPermissionService()->currentUserCanDelete(Entities::APPOINTMENTS)) {
41 throw new AccessDeniedException('You are not allowed to delete appointment');
42 }
43
44 $result = new CommandResult();
45
46 /** @var BookingApplicationService $bookingApplicationService */
47 $bookingApplicationService = $this->container->get('application.booking.booking.service');
48
49 /** @var AppointmentApplicationService $appointmentApplicationService */
50 $appointmentApplicationService = $this->container->get('application.booking.appointment.service');
51
52 /** @var AppointmentRepository $appointmentRepository */
53 $appointmentRepository = $this->container->get('domain.booking.appointment.repository');
54
55
56 /** @var Appointment $appointment */
57 $appointment = $appointmentRepository->getByBookingId($command->getArg('id'));
58
59 /** @var CustomerBooking $removedBooking */
60 $removedBooking = $appointment->getBookings()->getItem($command->getArg('id'));
61
62 $appointmentRepository->beginTransaction();
63
64 $hasMultipleBookings = $appointment->getBookings()->length() > 1;
65
66 do_action('amelia_before_package_booking_deleted', $appointment ? $appointment->toArray() : null, $removedBooking ? $removedBooking->toArray() : null);
67
68
69 if ($appointment->getBookings()->length() === 1) {
70 $resultData = $appointmentApplicationService->removeBookingFromNonGroupAppointment(
71 $appointment,
72 $removedBooking
73 );
74 } else {
75 $resultData = $appointmentApplicationService->removeBookingFromGroupAppointment(
76 $appointment,
77 $removedBooking
78 );
79 }
80
81 $isSuccess = true;
82
83 if ($hasMultipleBookings) {
84 if (!$bookingApplicationService->delete($removedBooking)) {
85 $isSuccess = false;
86 }
87 } else if (!$appointmentApplicationService->delete($appointment)) {
88 $isSuccess = false;
89 }
90
91 if (!$isSuccess) {
92 $appointmentRepository->rollback();
93
94 $result->setResult(CommandResult::RESULT_ERROR);
95 $result->setMessage('Could not delete booking');
96
97 return $result;
98 }
99
100 $appointmentRepository->commit();
101
102 $result->setResult(CommandResult::RESULT_SUCCESS);
103 $result->setMessage('Successfully deleted booking');
104 $result->setData($resultData);
105
106 do_action('amelia_after_package_booking_deleted', $appointment ? $appointment->toArray() : null, $removedBooking ? $removedBooking->toArray() : null);
107
108 return $result;
109 }
110 }
111