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 / User / Provider / GetProviderCommandHandler.php
ameliabooking / src / Application / Commands / User / Provider Last commit date
AddProviderCommand.php 1 year ago AddProviderCommandHandler.php 1 year ago GetProviderCommand.php 7 years ago GetProviderCommandHandler.php 1 year ago GetProvidersCommand.php 1 year ago GetProvidersCommandHandler.php 1 year ago UpdateProviderCommand.php 1 year ago UpdateProviderCommandHandler.php 1 year ago UpdateProviderStatusCommand.php 1 year ago UpdateProviderStatusCommandHandler.php 2 years ago
GetProviderCommandHandler.php
151 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 (
49 !$command->getPermissionService()->currentUserCanRead(Entities::EMPLOYEES) ||
50 (
51 !$command->getPermissionService()->currentUserCanReadOthers(Entities::EMPLOYEES) &&
52 $currentUser->getId()->getValue() !== $providerId
53 )
54 ) {
55 throw new AccessDeniedException('You are not allowed to read employee.');
56 }
57
58 $result = new CommandResult();
59
60 /** @var AppointmentRepository $appointmentRepository */
61 $appointmentRepository = $this->container->get('domain.booking.appointment.repository');
62 /** @var ProviderApplicationService $providerService */
63 $providerService = $this->container->get('application.user.provider.service');
64 /** @var SettingsService $settingsService */
65 $settingsService = $this->container->get('domain.settings.service');
66 /** @var AbstractGoogleCalendarService $googleCalService */
67 $googleCalService = $this->container->get('infrastructure.google.calendar.service');
68 /** @var AbstractOutlookCalendarService $outlookCalendarService */
69 $outlookCalendarService = $this->container->get('infrastructure.outlook.calendar.service');
70 /** @var ProviderRepository $providerRepository */
71 $providerRepository = $this->container->get('domain.users.providers.repository');
72
73
74 $companyDaysOff = $settingsService->getCategorySettings('daysOff');
75
76 $companyDayOff = $providerService->checkIfTodayIsCompanyDayOff($companyDaysOff);
77
78 /** @var Provider $provider */
79 $provider = $providerService->getProviderWithServicesAndSchedule($providerId, true);
80
81 $providerService->modifyPeriodsWithSingleLocationAfterFetch($provider->getWeekDayList());
82 $providerService->modifyPeriodsWithSingleLocationAfterFetch($provider->getSpecialDayList());
83
84 $futureAppointmentsServicesIds = $appointmentRepository->getFutureAppointmentsServicesIds(
85 [$provider->getId()->getValue()],
86 DateTimeService::getNowDateTime(),
87 null
88 );
89
90 $providerArray = $providerService->manageProvidersActivity(
91 [$provider->toArray()],
92 $companyDayOff
93 )[0];
94
95 $successfulGoogleConnection = true;
96
97 $successfulOutlookConnection = true;
98
99 try {
100 $providerArray['googleCalendar']['calendarList'] = $googleCalService->listCalendarList($provider);
101
102 $providerArray['googleCalendar']['calendarId'] = $googleCalService->getProviderGoogleCalendarId($provider);
103 } catch (\Exception $e) {
104 $providerArray['googleCalendar']['calendarId'] = !empty($providerArray['googleCalendar']['calendarId'])
105 ? $providerArray['googleCalendar']['calendarId']
106 : null;
107
108 $providerArray['googleCalendar']['calendarList'] = [];
109
110 $providerRepository->updateErrorColumn($providerId, $e->getMessage());
111 $successfulGoogleConnection = false;
112 }
113
114 try {
115 $providerArray['outlookCalendar']['calendarList'] = $outlookCalendarService->listCalendarList($provider);
116
117 $providerArray['outlookCalendar']['calendarId'] = $outlookCalendarService->getProviderOutlookCalendarId(
118 $provider
119 );
120 } catch (\Exception $e) {
121 $providerArray['outlookCalendar']['calendarId'] = !empty($providerArray['outlookCalendar']['calendarId'])
122 ? $providerArray['outlookCalendar']['calendarId']
123 : null;
124
125 $providerArray['outlookCalendar']['calendarList'] = [];
126
127 $providerRepository->updateErrorColumn($providerId, $e->getMessage());
128 $successfulOutlookConnection = false;
129 }
130
131 $providerArray['mandatoryServicesIds'] = $providerService->getMandatoryServicesIds($providerId);
132
133 $providerArray = apply_filters('amelia_get_provider_filter', $providerArray);
134
135 do_action('amelia_get_provider', $providerArray);
136
137 $result->setResult(CommandResult::RESULT_SUCCESS);
138 $result->setMessage('Successfully retrieved user.');
139 $result->setData(
140 [
141 Entities::USER => $providerArray,
142 'successfulGoogleConnection' => $successfulGoogleConnection,
143 'successfulOutlookConnection' => $successfulOutlookConnection,
144 'futureAppointmentsServicesIds' => $futureAppointmentsServicesIds,
145 ]
146 );
147
148 return $result;
149 }
150 }
151