PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.31
Booking for Appointments and Events Calendar – Amelia v1.2.31
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 / AddEventCommandHandler.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 2 years ago GetCalendarEventsCommand.php 1 year 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 1 year ago GetEventDeleteEffectCommandHandler.php 1 year ago GetEventsCommand.php 1 year ago GetEventsCommandHandler.php 1 year ago UpdateEventBookingCommand.php 7 years ago UpdateEventBookingCommandHandler.php 1 year ago UpdateEventCommand.php 1 year ago UpdateEventCommandHandler.php 1 year ago UpdateEventStatusCommand.php 1 year ago UpdateEventStatusCommandHandler.php 1 year ago
AddEventCommandHandler.php
132 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\Entity\EntityApplicationService;
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\Entities;
16 use AmeliaBooking\Domain\Entity\User\AbstractUser;
17 use AmeliaBooking\Domain\Services\Settings\SettingsService;
18 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
19 use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventRepository;
20 use Exception;
21 use Interop\Container\Exception\ContainerException;
22 use Slim\Exception\ContainerValueNotFoundException;
23
24 /**
25 * Class AddEventCommandHandler
26 *
27 * @package AmeliaBooking\Application\Commands\Booking\Event
28 */
29 class AddEventCommandHandler extends CommandHandler
30 {
31 /**
32 * @var array
33 */
34 public $mandatoryFields = [
35 'name',
36 'periods'
37 ];
38
39 /**
40 * @param AddEventCommand $command
41 *
42 * @return CommandResult
43 * @throws QueryExecutionException
44 * @throws ContainerValueNotFoundException
45 * @throws InvalidArgumentException
46 * @throws ContainerException
47 * @throws Exception
48 */
49 public function handle(AddEventCommand $command)
50 {
51 $result = new CommandResult();
52
53 $this->checkMandatoryFields($command);
54
55 $eventData = $command->getFields();
56
57 /** @var EventRepository $eventRepository */
58 $eventRepository = $this->container->get('domain.booking.event.repository');
59 /** @var EventApplicationService $eventApplicationService */
60 $eventApplicationService = $this->container->get('application.booking.event.service');
61 /** @var UserApplicationService $userAS */
62 $userAS = $this->getContainer()->get('application.user.service');
63 /** @var SettingsService $settingsDS */
64 $settingsDS = $this->container->get('domain.settings.service');
65 /** @var EntityApplicationService $entityService */
66 $entityService = $this->container->get('application.entity.service');
67
68 try {
69 /** @var AbstractUser $user */
70 $user = $command->getUserApplicationService()->authorization(
71 $command->getPage() === 'cabinet' ? $command->getToken() : null,
72 $command->getCabinetType()
73 );
74 } catch (AuthorizationException $e) {
75 $result->setResult(CommandResult::RESULT_ERROR);
76 $result->setData(
77 ['reauthorize' => true]
78 );
79
80 return $result;
81 }
82
83 if (
84 $userAS->isCustomer($user) ||
85 ($userAS->isProvider($user) && !$settingsDS->getSetting('roles', 'allowWriteEvents'))
86 ) {
87 throw new AccessDeniedException('You are not allowed to add an event');
88 }
89
90 $entityService->removeMissingEntitiesForEvent($eventData);
91
92 $eventRepository->beginTransaction();
93
94 $eventData = apply_filters('amelia_before_event_added_filter', $eventData);
95
96 do_action('amelia_before_event_added', $eventData);
97
98 try {
99 /** @var Event $event */
100 $event = $eventApplicationService->build($eventData);
101 } catch (Exception $e) {
102 $result->setResult(CommandResult::RESULT_ERROR);
103 $result->setMessage($e->getMessage());
104 $result->setData(['message' => $e->getMessage()]);
105 return $result;
106 }
107
108
109 try {
110 /** @var Collection $events */
111 $events = $eventApplicationService->add($event);
112 } catch (QueryExecutionException $e) {
113 $eventRepository->rollback();
114 throw $e;
115 }
116
117 $eventRepository->commit();
118
119 do_action('amelia_after_event_added', $event ? $event->toArray() : null);
120
121 $result->setResult(CommandResult::RESULT_SUCCESS);
122 $result->setMessage('Successfully added new event.');
123 $result->setData(
124 [
125 Entities::EVENTS => $events->toArray(),
126 ]
127 );
128
129 return $result;
130 }
131 }
132