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
GetEventCommandHandler.php
141 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\Application\Services\User\CustomerApplicationService; |
| 10 | use AmeliaBooking\Application\Services\User\UserApplicationService; |
| 11 | use AmeliaBooking\Domain\Collection\Collection; |
| 12 | use AmeliaBooking\Domain\Common\Exceptions\AuthorizationException; |
| 13 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 14 | use AmeliaBooking\Domain\Entity\Booking\Event\Event; |
| 15 | use AmeliaBooking\Domain\Entity\Booking\Event\EventPeriod; |
| 16 | use AmeliaBooking\Domain\Entity\Entities; |
| 17 | use AmeliaBooking\Domain\Entity\User\AbstractUser; |
| 18 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 19 | use Exception; |
| 20 | use Slim\Exception\ContainerValueNotFoundException; |
| 21 | |
| 22 | /** |
| 23 | * Class GetEventCommandHandler |
| 24 | * |
| 25 | * @package AmeliaBooking\Application\Commands\Booking\Event |
| 26 | */ |
| 27 | class GetEventCommandHandler extends CommandHandler |
| 28 | { |
| 29 | /** |
| 30 | * @param GetEventCommand $command |
| 31 | * |
| 32 | * @return CommandResult |
| 33 | * @throws ContainerValueNotFoundException |
| 34 | * @throws AccessDeniedException |
| 35 | * @throws QueryExecutionException |
| 36 | * @throws InvalidArgumentException |
| 37 | * @throws Exception |
| 38 | */ |
| 39 | public function handle(GetEventCommand $command) |
| 40 | { |
| 41 | $result = new CommandResult(); |
| 42 | |
| 43 | try { |
| 44 | /** @var AbstractUser $user */ |
| 45 | $user = $command->getUserApplicationService()->authorization( |
| 46 | $command->getPage() === 'cabinet' ? $command->getToken() : null, |
| 47 | $command->getCabinetType() |
| 48 | ); |
| 49 | } catch (AuthorizationException $e) { |
| 50 | $result->setResult(CommandResult::RESULT_ERROR); |
| 51 | $result->setData( |
| 52 | [ |
| 53 | 'reauthorize' => true |
| 54 | ] |
| 55 | ); |
| 56 | |
| 57 | return $result; |
| 58 | } |
| 59 | |
| 60 | if ($user === null) { |
| 61 | throw new AccessDeniedException('You are not allowed to read events'); |
| 62 | } |
| 63 | |
| 64 | /** @var EventApplicationService $eventApplicationService */ |
| 65 | $eventApplicationService = $this->container->get('application.booking.event.service'); |
| 66 | |
| 67 | /** @var Event $event */ |
| 68 | $event = $eventApplicationService->getEventById( |
| 69 | (int)$command->getField('id'), |
| 70 | [ |
| 71 | 'fetchEventsPeriods' => true, |
| 72 | 'fetchEventsTickets' => true, |
| 73 | 'fetchEventsTags' => true, |
| 74 | 'fetchEventsProviders' => true, |
| 75 | 'fetchEventsImages' => true, |
| 76 | 'fetchBookings' => true, |
| 77 | 'fetchBookingsTickets' => true, |
| 78 | 'fetchBookingsUsers' => true, |
| 79 | 'fetchBookingsPayments' => true, |
| 80 | 'fetchBookingsCoupons' => true, |
| 81 | ] |
| 82 | ); |
| 83 | |
| 84 | if (!$event) { |
| 85 | $result->setResult(CommandResult::RESULT_ERROR); |
| 86 | $result->setMessage('Could not retrieve event'); |
| 87 | $result->setData( |
| 88 | [ |
| 89 | Entities::EVENT => [] |
| 90 | ] |
| 91 | ); |
| 92 | |
| 93 | return $result; |
| 94 | } |
| 95 | |
| 96 | // set tickets price by dateRange |
| 97 | if ($event->getCustomTickets()->getItems()) { |
| 98 | /** @var EventApplicationService $eventAS */ |
| 99 | $eventAS = $this->container->get('application.booking.event.service'); |
| 100 | |
| 101 | $event->setCustomTickets($eventAS->getTicketsPriceByDateRange($event->getCustomTickets())); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | if (!empty($command->getField('params')['timeZone'])) { |
| 106 | /** @var EventPeriod $period */ |
| 107 | foreach ($event->getPeriods()->getItems() as $period) { |
| 108 | $period->getPeriodStart()->getValue()->setTimezone( |
| 109 | new \DateTimeZone($command->getField('params')['timeZone']) |
| 110 | ); |
| 111 | |
| 112 | $period->getPeriodEnd()->getValue()->setTimezone( |
| 113 | new \DateTimeZone($command->getField('params')['timeZone']) |
| 114 | ); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /** @var CustomerApplicationService $customerAS */ |
| 119 | $customerAS = $this->container->get('application.user.customer.service'); |
| 120 | |
| 121 | $customerAS->removeBookingsForOtherCustomers($user, new Collection([$event])); |
| 122 | |
| 123 | $eventArray = $event->toArray(); |
| 124 | |
| 125 | $eventArray = apply_filters('amelia_get_event_filter', $eventArray); |
| 126 | |
| 127 | do_action('amelia_get_event', $eventArray); |
| 128 | |
| 129 | |
| 130 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 131 | $result->setMessage('Successfully retrieved event'); |
| 132 | $result->setData( |
| 133 | [ |
| 134 | Entities::EVENT => $eventArray |
| 135 | ] |
| 136 | ); |
| 137 | |
| 138 | return $result; |
| 139 | } |
| 140 | } |
| 141 |