PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 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 / UpdateEventVisibilityCommandHandler.php
ameliabooking / src / Application / Commands / Booking / Event Last commit date
Tag 4 months ago AddEventCommand.php 1 year ago AddEventCommandHandler.php 3 weeks ago DeleteEventBookingCommand.php 7 years ago DeleteEventBookingCommandHandler.php 3 weeks ago DeleteEventCommand.php 1 year ago DeleteEventCommandHandler.php 8 months ago DeleteEventsCommand.php 8 months ago DeleteEventsCommandHandler.php 4 months ago GenerateEventWpaCustomPostCommand.php 1 month ago GenerateEventWpaCustomPostCommandHandler.php 1 month ago GetCalendarEventsCommand.php 1 year ago GetCalendarEventsCommandHandler.php 3 weeks ago GetEventBookingCommand.php 8 months ago GetEventBookingCommandHandler.php 3 weeks ago GetEventBookingsCommand.php 1 year ago GetEventBookingsCommandHandler.php 3 weeks ago GetEventCommand.php 7 years ago GetEventCommandHandler.php 3 weeks ago GetEventsCommand.php 1 year ago GetEventsCommandHandler.php 3 weeks ago UpdateEventBookingCommand.php 7 years ago UpdateEventBookingCommandHandler.php 8 months ago UpdateEventCommand.php 1 year ago UpdateEventCommandHandler.php 3 weeks ago UpdateEventStatusCommand.php 1 year ago UpdateEventStatusCommandHandler.php 8 months ago UpdateEventVisibilityCommand.php 8 months ago UpdateEventVisibilityCommandHandler.php 8 months ago
UpdateEventVisibilityCommandHandler.php
83 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\Domain\Common\Exceptions\InvalidArgumentException;
9 use AmeliaBooking\Domain\Entity\Booking\Event\Event;
10 use AmeliaBooking\Domain\Entity\Entities;
11 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
12 use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventRepository;
13
14 /**
15 * Class UpdateEventVisibilityCommandHandler
16 *
17 * @package AmeliaBooking\Application\Commands\Booking\Event
18 */
19 class UpdateEventVisibilityCommandHandler extends CommandHandler
20 {
21 /**
22 * @var array
23 */
24 public $mandatoryFields = [
25 'status'
26 ];
27
28 /**
29 * @param UpdateEventVisibilityCommand $command
30 *
31 * @return CommandResult
32 * @throws \Slim\Exception\ContainerException
33 * @throws \InvalidArgumentException
34 * @throws \Slim\Exception\ContainerValueNotFoundException
35 * @throws QueryExecutionException
36 * @throws InvalidArgumentException
37 * @throws AccessDeniedException
38 * @throws \Interop\Container\Exception\ContainerException
39 */
40 public function handle(UpdateEventVisibilityCommand $command)
41 {
42 if (!$command->getPermissionService()->currentUserCanWriteStatus(Entities::EVENTS)) {
43 throw new AccessDeniedException('You are not allowed to update event status');
44 }
45
46 $result = new CommandResult();
47
48 $this->checkMandatoryFields($command);
49
50 /** @var EventRepository $eventRepository */
51 $eventRepository = $this->container->get('domain.booking.event.repository');
52
53 $requestedStatus = $command->getField('status');
54 $applyGlobally = $command->getField('applyGlobally');
55
56 $eventId = (int)$command->getArg('id');
57
58 /** @var Event $event */
59 $event = $eventRepository->getById($eventId);
60
61 $eventRepository->beginTransaction();
62
63 do_action('amelia_before_event_status_updated', $event ? $event->toArray() : null, $requestedStatus, $command->getField('applyGlobally'));
64
65 try {
66 $eventRepository->toggleEventVisibility($event, $requestedStatus === 'hidden' ? 0 : 1, $applyGlobally);
67 } catch (QueryExecutionException $e) {
68 $eventRepository->rollback();
69 throw $e;
70 }
71
72 $eventRepository->commit();
73
74 do_action('amelia_after_event_status_updated', $event ? $event->toArray() : null, $requestedStatus, $command->getField('applyGlobally'));
75
76 $result->setResult(CommandResult::RESULT_SUCCESS);
77 $result->setMessage('Successfully updated event visibility');
78 $result->setData(true);
79
80 return $result;
81 }
82 }
83