PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 / User / Provider / GetProviderCommandHandler.php
ameliabooking / src / Application / Commands / User / Provider Last commit date
AddProviderCommand.php 7 years ago AddProviderCommandHandler.php 2 years ago GetProviderCommand.php 7 years ago GetProviderCommandHandler.php 1 year ago GetProvidersCommand.php 7 years ago GetProvidersCommandHandler.php 1 year ago UpdateProviderCommand.php 7 years ago UpdateProviderCommandHandler.php 1 year ago UpdateProviderStatusCommand.php 7 years ago UpdateProviderStatusCommandHandler.php 2 years ago
GetProviderCommandHandler.php
150 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\User\Provider;
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\User\ProviderApplicationService;
9 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
10 use AmeliaBooking\Domain\Entity\Entities;
11 use AmeliaBooking\Domain\Entity\User\AbstractUser;
12 use AmeliaBooking\Domain\Entity\User\Provider;
13 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
14 use AmeliaBooking\Domain\Services\Settings\SettingsService;
15 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
16 use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\AppointmentRepository;
17 use AmeliaBooking\Infrastructure\Repository\User\ProviderRepository;
18 use AmeliaBooking\Infrastructure\Services\Google\AbstractGoogleCalendarService;
19 use AmeliaBooking\Infrastructure\Services\Outlook\AbstractOutlookCalendarService;
20 use Interop\Container\Exception\ContainerException;
21 use Slim\Exception\ContainerValueNotFoundException;
22
23 /**
24 * Class GetProviderCommandHandler
25 *
26 * @package AmeliaBooking\Application\Commands\User\Provider
27 */
28 class GetProviderCommandHandler extends CommandHandler
29 {
30 /**
31 * @param GetProviderCommand $command
32 *
33 * @return CommandResult
34 * @throws ContainerValueNotFoundException
35 * @throws AccessDeniedException
36 * @throws QueryExecutionException
37 * @throws ContainerException
38 * @throws InvalidArgumentException
39 */
40 public function handle(GetProviderCommand $command)
41 {
42 /** @var int $providerId */
43 $providerId = (int)$command->getField('id');
44
45 /** @var AbstractUser $currentUser */
46 $currentUser = $this->container->get('logged.in.user');
47
48 if (!$command->getPermissionService()->currentUserCanRead(Entities::EMPLOYEES) ||
49 (
50 !$command->getPermissionService()->currentUserCanReadOthers(Entities::EMPLOYEES) &&
51 $currentUser->getId()->getValue() !== $providerId
52 )
53 ) {
54 throw new AccessDeniedException('You are not allowed to read employee.');
55 }
56
57 $result = new CommandResult();
58
59 /** @var AppointmentRepository $appointmentRepository */
60 $appointmentRepository = $this->container->get('domain.booking.appointment.repository');
61 /** @var ProviderApplicationService $providerService */
62 $providerService = $this->container->get('application.user.provider.service');
63 /** @var SettingsService $settingsService */
64 $settingsService = $this->container->get('domain.settings.service');
65 /** @var AbstractGoogleCalendarService $googleCalService */
66 $googleCalService = $this->container->get('infrastructure.google.calendar.service');
67 /** @var AbstractOutlookCalendarService $outlookCalendarService */
68 $outlookCalendarService = $this->container->get('infrastructure.outlook.calendar.service');
69 /** @var ProviderRepository $providerRepository */
70 $providerRepository = $this->container->get('domain.users.providers.repository');
71
72
73 $companyDaysOff = $settingsService->getCategorySettings('daysOff');
74
75 $companyDayOff = $providerService->checkIfTodayIsCompanyDayOff($companyDaysOff);
76
77 /** @var Provider $provider */
78 $provider = $providerService->getProviderWithServicesAndSchedule($providerId, true);
79
80 $providerService->modifyPeriodsWithSingleLocationAfterFetch($provider->getWeekDayList());
81 $providerService->modifyPeriodsWithSingleLocationAfterFetch($provider->getSpecialDayList());
82
83 $futureAppointmentsServicesIds = $appointmentRepository->getFutureAppointmentsServicesIds(
84 [$provider->getId()->getValue()],
85 DateTimeService::getNowDateTime(),
86 null
87 );
88
89 $providerArray = $providerService->manageProvidersActivity(
90 [$provider->toArray()],
91 $companyDayOff
92 )[0];
93
94 $successfulGoogleConnection = true;
95
96 $successfulOutlookConnection = true;
97
98 try {
99 $providerArray['googleCalendar']['calendarList'] = $googleCalService->listCalendarList($provider);
100
101 $providerArray['googleCalendar']['calendarId'] = $googleCalService->getProviderGoogleCalendarId($provider);
102 } catch (\Exception $e) {
103 $providerArray['googleCalendar']['calendarId'] = !empty($providerArray['googleCalendar']['calendarId'])
104 ? $providerArray['googleCalendar']['calendarId']
105 : null;
106
107 $providerArray['googleCalendar']['calendarList'] = [];
108
109 $providerRepository->updateErrorColumn($providerId, $e->getMessage());
110 $successfulGoogleConnection = false;
111 }
112
113 try {
114 $providerArray['outlookCalendar']['calendarList'] = $outlookCalendarService->listCalendarList($provider);
115
116 $providerArray['outlookCalendar']['calendarId'] = $outlookCalendarService->getProviderOutlookCalendarId(
117 $provider
118 );
119 } catch (\Exception $e) {
120 $providerArray['outlookCalendar']['calendarId'] = !empty($providerArray['outlookCalendar']['calendarId'])
121 ? $providerArray['outlookCalendar']['calendarId']
122 : null;
123
124 $providerArray['outlookCalendar']['calendarList'] = [];
125
126 $providerRepository->updateErrorColumn($providerId, $e->getMessage());
127 $successfulOutlookConnection = false;
128 }
129
130 $providerArray['mandatoryServicesIds'] = $providerService->getMandatoryServicesIds($providerId);
131
132 $providerArray = apply_filters('amelia_get_provider_filter', $providerArray);
133
134 do_action('amelia_get_provider', $providerArray);
135
136 $result->setResult(CommandResult::RESULT_SUCCESS);
137 $result->setMessage('Successfully retrieved user.');
138 $result->setData(
139 [
140 Entities::USER => $providerArray,
141 'successfulGoogleConnection' => $successfulGoogleConnection,
142 'successfulOutlookConnection' => $successfulOutlookConnection,
143 'futureAppointmentsServicesIds' => $futureAppointmentsServicesIds,
144 ]
145 );
146
147 return $result;
148 }
149 }
150