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
5 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 |