ameliabooking
/
src
/
Application
/
Commands
/
Booking
/
Event
/
GetEventDeleteEffectCommandHandler.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
GetEventDeleteEffectCommandHandler.php
59 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Application\Commands\Booking\Event; |
| 4 | |
| 5 | use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException; |
| 6 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 7 | use AmeliaBooking\Domain\Entity\Booking\Event\Event; |
| 8 | use AmeliaBooking\Domain\Entity\Entities; |
| 9 | use AmeliaBooking\Application\Commands\CommandResult; |
| 10 | use AmeliaBooking\Application\Commands\CommandHandler; |
| 11 | use AmeliaBooking\Domain\ValueObjects\String\BookingStatus; |
| 12 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 13 | use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventRepository; |
| 14 | use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings; |
| 15 | |
| 16 | /** |
| 17 | * Class GetEventDeleteEffectCommandHandler |
| 18 | * |
| 19 | * @package AmeliaBooking\Application\Commands\Booking\Event |
| 20 | */ |
| 21 | class GetEventDeleteEffectCommandHandler extends CommandHandler |
| 22 | { |
| 23 | /** |
| 24 | * @param GetEventDeleteEffectCommand $command |
| 25 | * |
| 26 | * @return CommandResult |
| 27 | * @throws \Slim\Exception\ContainerValueNotFoundException |
| 28 | * @throws AccessDeniedException |
| 29 | * @throws InvalidArgumentException |
| 30 | * @throws QueryExecutionException |
| 31 | */ |
| 32 | public function handle(GetEventDeleteEffectCommand $command) |
| 33 | { |
| 34 | // TODO - Redesign: Remove command handler since user will have possibility to Cancel and Delete at once and status will be checked on frontend |
| 35 | if (!$command->getPermissionService()->currentUserCanWrite(Entities::EVENTS)) { |
| 36 | throw new AccessDeniedException('You are not allowed to write events'); |
| 37 | } |
| 38 | |
| 39 | $result = new CommandResult(); |
| 40 | |
| 41 | /** @var EventRepository $eventRepository */ |
| 42 | $eventRepository = $this->container->get('domain.booking.event.repository'); |
| 43 | |
| 44 | /** @var Event $event */ |
| 45 | $event = $eventRepository->getById((int)$command->getArg('id')); |
| 46 | |
| 47 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 48 | $result->setMessage('Successfully retrieved message.'); |
| 49 | $result->setData( |
| 50 | [ |
| 51 | 'valid' => $event->getStatus()->getValue() === BookingStatus::REJECTED, |
| 52 | 'message' => $event->getStatus()->getValue() === BookingStatus::REJECTED ? '' : BackendStrings::get('event_cancel_before_delete') |
| 53 | ] |
| 54 | ); |
| 55 | |
| 56 | return $result; |
| 57 | } |
| 58 | } |
| 59 |