PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.0.2
Booking for Appointments and Events Calendar – Amelia v2.0.2
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 / GetProvidersCommandHandler.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 6 months ago GetProvidersCommand.php 1 year ago GetProvidersCommandHandler.php 6 months ago UpdateProviderCommand.php 1 year ago UpdateProviderCommandHandler.php 5 months ago UpdateProviderStatusCommand.php 1 year ago UpdateProviderStatusCommandHandler.php 6 months ago
GetProvidersCommandHandler.php
96 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\Collection\Collection;
10 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
11 use AmeliaBooking\Domain\Entity\Entities;
12 use AmeliaBooking\Domain\Entity\User\AbstractUser;
13 use AmeliaBooking\Domain\Services\Settings\SettingsService;
14 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
15 use AmeliaBooking\Infrastructure\Licence\Licence;
16 use AmeliaBooking\Infrastructure\Licence\LicenceConstants;
17 use AmeliaBooking\Infrastructure\Repository\User\ProviderRepository;
18 use AmeliaBooking\Infrastructure\Services\Google\GoogleCalendarMiddlewareService;
19 use Interop\Container\Exception\ContainerException;
20 use Slim\Exception\ContainerValueNotFoundException;
21
22 /**
23 * Class GetProvidersCommandHandler
24 *
25 * @package AmeliaBooking\Application\Commands\User\Provider
26 */
27 class GetProvidersCommandHandler extends CommandHandler
28 {
29 /**
30 * @param GetProvidersCommand $command
31 *
32 * @return CommandResult
33 * @throws ContainerValueNotFoundException
34 * @throws QueryExecutionException
35 * @throws ContainerException
36 * @throws AccessDeniedException
37 * @throws InvalidArgumentException
38 */
39 public function handle(GetProvidersCommand $command)
40 {
41 if (!$command->getPermissionService()->currentUserCanRead(Entities::EMPLOYEES)) {
42 throw new AccessDeniedException('You are not allowed to read employees.');
43 }
44
45 $result = new CommandResult();
46
47 /** @var ProviderRepository $providerRepository */
48 $providerRepository = $this->container->get('domain.users.providers.repository');
49
50 /** @var ProviderApplicationService $providerService */
51 $providerService = $this->container->get('application.user.provider.service');
52 /** @var SettingsService $settingsService */
53 $settingsService = $this->container->get('domain.settings.service');
54
55 $companyDaysOff = $settingsService->getCategorySettings('daysOff');
56
57 $params = $command->getField('params');
58
59 /** @var AbstractUser $currentUser */
60 $currentUser = $this->container->get('logged.in.user');
61
62 if (
63 !$command->getPermissionService()->currentUserCanReadOthers(Entities::EMPLOYEES) &&
64 $currentUser->getType() === Entities::PROVIDER
65 ) {
66 $params['providers'][] = $currentUser->getId()->getValue();
67 }
68
69 $itemsPerPage = !empty($params['limit']) ? $params['limit'] : 10;
70
71 /** @var Collection $providers */
72 $providers = $providerRepository->getFiltered($params, $itemsPerPage);
73
74 $result->setResult(CommandResult::RESULT_SUCCESS);
75 $result->setMessage('Successfully retrieved users.');
76 $providers = $providers->toArray();
77
78 $companyDayOff = $providerService->checkIfTodayIsCompanyDayOff($companyDaysOff);
79 $providers = $providerService->manageProvidersActivity($providers, $companyDayOff);
80
81 $providers = apply_filters('amelia_get_providers_filter', $providers);
82
83 do_action('amelia_get_providers', $providers);
84
85 $result->setData(
86 [
87 Entities::USERS => $providers,
88 'countFiltered' => (int)$providerRepository->getCount($command->getField('params')),
89 'countTotal' => (int)$providerRepository->getCount([]),
90 ]
91 );
92
93 return $result;
94 }
95 }
96