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