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 |