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 / UpdateEventStatusCommandHandler.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
UpdateEventStatusCommandHandler.php
101 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\Collection\Collection;
10 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
11 use AmeliaBooking\Domain\Entity\Booking\Event\Event;
12 use AmeliaBooking\Domain\Entity\Entities;
13 use AmeliaBooking\Domain\ValueObjects\String\BookingStatus;
14 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
15 use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventRepository;
16 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
17
18 /**
19 * Class UpdateEventStatusCommandHandler
20 *
21 * @package AmeliaBooking\Application\Commands\Booking\Event
22 */
23 class UpdateEventStatusCommandHandler extends CommandHandler
24 {
25 /**
26 * @var array
27 */
28 public $mandatoryFields = [
29 'status',
30 'applyGlobally'
31 ];
32
33 /**
34 * @param UpdateEventStatusCommand $command
35 *
36 * @return CommandResult
37 * @throws \Slim\Exception\ContainerException
38 * @throws \InvalidArgumentException
39 * @throws \Slim\Exception\ContainerValueNotFoundException
40 * @throws QueryExecutionException
41 * @throws InvalidArgumentException
42 * @throws AccessDeniedException
43 */
44 public function handle(UpdateEventStatusCommand $command)
45 {
46 if (!$command->getPermissionService()->currentUserCanWriteStatus(Entities::EVENTS)) {
47 throw new AccessDeniedException('You are not allowed to update event status');
48 }
49
50 $result = new CommandResult();
51
52 $this->checkMandatoryFields($command);
53
54 /** @var EventApplicationService $eventApplicationService */
55 $eventApplicationService = $this->container->get('application.booking.event.service');
56
57 /** @var EventRepository $eventRepository */
58 $eventRepository = $this->container->get('domain.booking.event.repository');
59
60 $requestedStatus = $command->getField('status');
61
62 /** @var Event $event */
63 $event = $eventRepository->getById((int)$command->getArg('id'));
64
65 $eventRepository->beginTransaction();
66
67 do_action('amelia_before_event_status_updated', $event ? $event->toArray() : null, $requestedStatus, $command->getField('applyGlobally'));
68
69 try {
70 $events = new Collection();
71 $events->addItem($event, $event->getId()->getValue());
72
73 /** @var Collection $updatedEvents */
74 $updatedEvents = $eventApplicationService->updateStatus(
75 $events,
76 $requestedStatus,
77 $command->getField('applyGlobally')
78 );
79 } catch (QueryExecutionException $e) {
80 $eventRepository->rollback();
81 throw $e;
82 }
83
84 $eventRepository->commit();
85
86 do_action('amelia_after_event_status_updated', $event ? $event->toArray() : null, $requestedStatus, $command->getField('applyGlobally'));
87
88 $result->setResult(CommandResult::RESULT_SUCCESS);
89 $result->setMessage('Successfully updated event status');
90 $result->setData(
91 [
92 'status' => $requestedStatus,
93 'message' => BackendStrings::get('event_status_changed') . $requestedStatus,
94 Entities::EVENTS => $updatedEvents->toArray(),
95 ]
96 );
97
98 return $result;
99 }
100 }
101