ameliabooking
/
src
/
Application
/
Commands
/
Booking
/
Event
/
UpdateEventVisibilityCommandHandler.php
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
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 |