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 / GetProvidersCommandHandler.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
GetProvidersCommandHandler.php
93 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\Collection\AbstractCollection;
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\Repository\User\ProviderRepository;
16 use Interop\Container\Exception\ContainerException;
17 use Slim\Exception\ContainerValueNotFoundException;
18
19 /**
20 * Class GetProvidersCommandHandler
21 *
22 * @package AmeliaBooking\Application\Commands\User\Provider
23 */
24 class GetProvidersCommandHandler extends CommandHandler
25 {
26 /**
27 * @param GetProvidersCommand $command
28 *
29 * @return CommandResult
30 * @throws ContainerValueNotFoundException
31 * @throws QueryExecutionException
32 * @throws ContainerException
33 * @throws AccessDeniedException
34 * @throws InvalidArgumentException
35 */
36 public function handle(GetProvidersCommand $command)
37 {
38 if (!$command->getPermissionService()->currentUserCanRead(Entities::EMPLOYEES)) {
39 throw new AccessDeniedException('You are not allowed to read employees.');
40 }
41
42 $result = new CommandResult();
43
44 /** @var ProviderRepository $providerRepository */
45 $providerRepository = $this->container->get('domain.users.providers.repository');
46
47 /** @var ProviderApplicationService $providerService */
48 $providerService = $this->container->get('application.user.provider.service');
49 /** @var SettingsService $settingsService */
50 $settingsService = $this->container->get('domain.settings.service');
51
52 $itemsPerPage = $settingsService->getSetting('general', 'itemsPerPageBackEnd');
53 $companyDaysOff = $settingsService->getCategorySettings('daysOff');
54
55 $params = $command->getField('params');
56
57 if (!$command->getPermissionService()->currentUserCanReadOthers(Entities::EMPLOYEES)) {
58 /** @var AbstractUser $currentUser */
59 $currentUser = $this->container->get('logged.in.user');
60
61 $params['providers'][] = $currentUser->getId()->getValue();
62 }
63
64 $providers = $providerRepository->getFiltered($params, $itemsPerPage);
65
66 if (!$providers instanceof AbstractCollection) {
67 $result->setResult(CommandResult::RESULT_ERROR);
68 $result->setMessage('Could not get users');
69
70 return $result;
71 }
72
73 $result->setResult(CommandResult::RESULT_SUCCESS);
74 $result->setMessage('Successfully retrieved users.');
75 $providers = $providers->toArray();
76
77 $companyDayOff = $providerService->checkIfTodayIsCompanyDayOff($companyDaysOff);
78 $providers = $providerService->manageProvidersActivity($providers, $companyDayOff);
79
80 $providers = apply_filters('amelia_get_providers_filter', $providers);
81
82 do_action('amelia_get_providers', $providers);
83
84 $result->setData([
85 Entities::USERS => $providers,
86 'countFiltered' => (int)$providerRepository->getCount($command->getField('params')),
87 'countTotal' => (int)$providerRepository->getCount([]),
88 ]);
89
90 return $result;
91 }
92 }
93