PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.0.2
Booking for Appointments and Events Calendar – Amelia v2.0.2
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 / Event / DeleteEventBookingCommandHandler.php
ameliabooking / src / Application / Commands / Booking / Event Last commit date
AddEventCommand.php 1 year ago AddEventCommandHandler.php 1 year ago DeleteEventBookingCommand.php 7 years ago DeleteEventBookingCommandHandler.php 1 year ago DeleteEventCommand.php 1 year ago DeleteEventCommandHandler.php 6 months ago DeleteEventsCommand.php 6 months ago DeleteEventsCommandHandler.php 6 months ago GetCalendarEventsCommand.php 1 year ago GetCalendarEventsCommandHandler.php 1 year ago GetEventBookingCommand.php 6 months ago GetEventBookingCommandHandler.php 5 months ago GetEventBookingsCommand.php 1 year ago GetEventBookingsCommandHandler.php 6 months ago GetEventCommand.php 7 years ago GetEventCommandHandler.php 6 months ago GetEventDeleteEffectCommand.php 1 year ago GetEventDeleteEffectCommandHandler.php 6 months ago GetEventsCommand.php 1 year ago GetEventsCommandHandler.php 6 months ago UpdateEventBookingCommand.php 7 years ago UpdateEventBookingCommandHandler.php 6 months ago UpdateEventCommand.php 1 year ago UpdateEventCommandHandler.php 6 months ago UpdateEventStatusCommand.php 1 year ago UpdateEventStatusCommandHandler.php 6 months ago UpdateEventVisibilityCommand.php 6 months ago UpdateEventVisibilityCommandHandler.php 6 months ago
DeleteEventBookingCommandHandler.php
171 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\Booking\Event;
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\EventApplicationService;
10 use AmeliaBooking\Application\Services\User\UserApplicationService;
11 use AmeliaBooking\Domain\Collection\Collection;
12 use AmeliaBooking\Domain\Common\Exceptions\AuthorizationException;
13 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
14 use AmeliaBooking\Domain\Entity\Booking\Appointment\CustomerBooking;
15 use AmeliaBooking\Domain\Entity\Booking\Event\Event;
16 use AmeliaBooking\Domain\Entity\Entities;
17 use AmeliaBooking\Domain\Entity\User\AbstractUser;
18 use AmeliaBooking\Domain\Services\Settings\SettingsService;
19 use AmeliaBooking\Domain\ValueObjects\BooleanValueObject;
20 use AmeliaBooking\Domain\ValueObjects\String\BookingStatus;
21 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
22 use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\CustomerBookingRepository;
23 use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventRepository;
24 use Interop\Container\Exception\ContainerException;
25 use Slim\Exception\ContainerValueNotFoundException;
26
27 /**
28 * Class DeleteEventBookingCommandHandler
29 *
30 * @package AmeliaBooking\Application\Commands\Booking\Event
31 */
32 class DeleteEventBookingCommandHandler extends CommandHandler
33 {
34 /**
35 * @param DeleteEventBookingCommand $command
36 *
37 * @return CommandResult
38 * @throws ContainerValueNotFoundException
39 * @throws AccessDeniedException
40 * @throws QueryExecutionException
41 * @throws ContainerException
42 * @throws InvalidArgumentException
43 */
44 public function handle(DeleteEventBookingCommand $command)
45 {
46 $result = new CommandResult();
47
48 /** @var UserApplicationService $userAS */
49 $userAS = $this->container->get('application.user.service');
50
51 /** @var SettingsService $settingsDS */
52 $settingsDS = $this->container->get('domain.settings.service');
53
54
55 $user = null;
56 if (!$command->getPermissionService()->currentUserCanDelete(Entities::EVENTS)) {
57 try {
58 /** @var AbstractUser $user */
59 $user = $userAS->authorization(
60 $command->getToken(),
61 Entities::PROVIDER
62 );
63 } catch (AuthorizationException $e) {
64 $result = new CommandResult();
65
66 $result->setResult(CommandResult::RESULT_ERROR);
67 $result->setData(
68 [
69 'reauthorize' => true
70 ]
71 );
72
73 return $result;
74 }
75
76 if ($userAS->isCustomer($user)) {
77 throw new AccessDeniedException('You are not allowed to delete event bookings');
78 }
79 }
80
81 /** @var CustomerBookingRepository $customerBookingRepository */
82 $customerBookingRepository = $this->container->get('domain.booking.customerBooking.repository');
83
84 /** @var EventRepository $eventRepository */
85 $eventRepository = $this->container->get('domain.booking.event.repository');
86
87 /** @var EventApplicationService $eventApplicationService */
88 $eventApplicationService = $this->container->get('application.booking.event.service');
89
90 /** @var BookingApplicationService $bookingAS */
91 $bookingAS = $this->container->get('application.booking.booking.service');
92
93 /** @var CustomerBooking $customerBooking */
94 $customerBooking = $customerBookingRepository->getById((int)$command->getField('id'));
95
96 /** @var Event $event */
97 $event = $eventRepository->getByBookingId(
98 $customerBooking->getId()->getValue(),
99 [
100 'fetchEventsTags' => true,
101 'fetchEventsProviders' => true,
102 'fetchBookingsCoupons' => true,
103 'fetchBookingsPayments' => true,
104 'fetchBookingsUsers' => true,
105 ]
106 );
107
108 $event->getBookings()->addItem($customerBooking, $customerBooking->getId()->getValue());
109
110 if (
111 $user &&
112 $userAS->isProvider($user) &&
113 (
114 !$settingsDS->getSetting('roles', 'allowWriteEvents') ||
115 (!$event->getProviders()->keyExists($user->getId()->getValue()) &&
116 (!$event->getOrganizerId() || $event->getOrganizerId()->getValue() !== $user->getId()->getValue()))
117 )
118 ) {
119 throw new AccessDeniedException('You are not allowed to delete this booking');
120 }
121
122 $customerBookingRepository->beginTransaction();
123
124 do_action('amelia_before_event_booking_deleted', $customerBooking->toArray(), $event ? $event->toArray() : null);
125
126 if (!$eventApplicationService->deleteEventBooking($customerBooking)) {
127 $result->setResult(CommandResult::RESULT_ERROR);
128 $result->setMessage('Could not delete booking');
129
130 return $result;
131 }
132
133 $customerBookingRepository->commit();
134
135 $event->setNotifyParticipants(
136 $bookingAS->isBookingApprovedOrPending($customerBooking->getStatus()->getValue())
137 );
138
139 $customerBooking->setChangedStatus(
140 new BooleanValueObject(
141 $bookingAS->isBookingApprovedOrPending($customerBooking->getStatus()->getValue())
142 )
143 );
144
145 $customerBooking->setStatus(new BookingStatus(BookingStatus::REJECTED));
146
147 /** @var Collection $payments */
148 $payments = $event->getBookings()->getItem($event->getBookings()->keys()[0])->getPayments();
149
150 if ($payments && count($payments->getItems())) {
151 $customerBooking->setPayments($payments);
152 }
153
154
155 do_action('amelia_after_event_booking_deleted', $customerBooking->toArray(), $event->toArray());
156
157 $result->setResult(CommandResult::RESULT_SUCCESS);
158 $result->setMessage('Successfully deleted event booking');
159 $result->setData(
160 [
161 'type' => Entities::EVENT,
162 Entities::EVENT => $event->toArray(),
163 Entities::BOOKING => $customerBooking->toArray(),
164 'appointmentStatusChanged' => false
165 ]
166 );
167
168 return $result;
169 }
170 }
171