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 / Event / DeleteEventCommandHandler.php
ameliabooking / src / Application / Commands / Booking / Event Last commit date
AddEventCommand.php 7 years ago AddEventCommandHandler.php 2 years ago DeleteEventBookingCommand.php 7 years ago DeleteEventBookingCommandHandler.php 1 year ago DeleteEventCommand.php 7 years ago DeleteEventCommandHandler.php 2 years ago GetCalendarEventsCommand.php 4 years ago GetCalendarEventsCommandHandler.php 1 year ago GetEventBookingsCommand.php 1 year ago GetEventBookingsCommandHandler.php 1 year ago GetEventCommand.php 7 years ago GetEventCommandHandler.php 1 year ago GetEventDeleteEffectCommand.php 7 years ago GetEventDeleteEffectCommandHandler.php 2 years ago GetEventsCommand.php 7 years ago GetEventsCommandHandler.php 1 year ago UpdateEventBookingCommand.php 7 years ago UpdateEventBookingCommandHandler.php 1 year ago UpdateEventCommand.php 7 years ago UpdateEventCommandHandler.php 1 year ago UpdateEventStatusCommand.php 7 years ago UpdateEventStatusCommandHandler.php 2 years ago
DeleteEventCommandHandler.php
85 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\EventApplicationService;
9 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
10 use AmeliaBooking\Domain\Entity\Booking\Event\Event;
11 use AmeliaBooking\Domain\Entity\Entities;
12 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
13 use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventRepository;
14
15 /**
16 * Class DeleteEventCommandHandler
17 *
18 * @package AmeliaBooking\Application\Commands\Booking\Event
19 */
20 class DeleteEventCommandHandler extends CommandHandler
21 {
22 /**
23 * @var array
24 */
25 public $mandatoryFields = [
26 'applyGlobally'
27 ];
28
29 /**
30 * @param DeleteEventCommand $command
31 *
32 * @return CommandResult
33 * @throws \Slim\Exception\ContainerValueNotFoundException
34 * @throws AccessDeniedException
35 * @throws InvalidArgumentException
36 * @throws QueryExecutionException
37 * @throws \Interop\Container\Exception\ContainerException
38 */
39 public function handle(DeleteEventCommand $command)
40 {
41 if (!$command->getPermissionService()->currentUserCanDelete(Entities::EVENTS)) {
42 throw new AccessDeniedException('You are not allowed to delete event');
43 }
44
45 $result = new CommandResult();
46
47 $this->checkMandatoryFields($command);
48
49 /** @var EventApplicationService $eventApplicationService */
50 $eventApplicationService = $this->container->get('application.booking.event.service');
51
52 /** @var EventRepository $eventRepository */
53 $eventRepository = $this->container->get('domain.booking.event.repository');
54
55 $event = $eventRepository->getById($command->getArg('id'));
56
57 $eventRepository->beginTransaction();
58
59
60 do_action('amelia_before_event_deleted', $event ? $event->toArray() : null);
61
62 try {
63 $deletedEvents = $eventApplicationService->delete($event, $command->getField('applyGlobally'));
64 } catch (QueryExecutionException $e) {
65 $eventRepository->rollback();
66 throw $e;
67 }
68
69 $eventRepository->commit();
70
71 do_action('amelia_after_event_deleted', $event ? $event->toArray() : null);
72
73 $result->setResult(CommandResult::RESULT_SUCCESS);
74 $result->setMessage('Successfully deleted event');
75 $result->setData(
76 [
77 Entities::EVENT => $event->toArray(),
78 'deletedEvents' => $deletedEvents
79 ]
80 );
81
82 return $result;
83 }
84 }
85