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