PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.31
Booking for Appointments and Events Calendar – Amelia v1.2.31
2.4.5 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 / Bookable / Service / GetServicesCommandHandler.php
ameliabooking / src / Application / Commands / Bookable / Service Last commit date
AddServiceCommand.php 1 year ago AddServiceCommandHandler.php 1 year ago DeleteServiceCommand.php 1 year ago DeleteServiceCommandHandler.php 1 year ago GetServiceCommand.php 1 year ago GetServiceCommandHandler.php 1 year ago GetServiceDeleteEffectCommand.php 1 year ago GetServiceDeleteEffectCommandHandler.php 2 years ago GetServicesCommand.php 1 year ago GetServicesCommandHandler.php 1 year ago UpdateServiceCommand.php 1 year ago UpdateServiceCommandHandler.php 1 year ago UpdateServiceStatusCommand.php 1 year ago UpdateServiceStatusCommandHandler.php 1 year ago UpdateServicesPositionsCommand.php 1 year ago UpdateServicesPositionsCommandHandler.php 1 year ago
GetServicesCommandHandler.php
95 lines
1 <?php
2
3 /**
4 * @copyright © TMS-Plugins. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Application\Commands\Bookable\Service;
9
10 use AmeliaBooking\Application\Commands\CommandHandler;
11 use AmeliaBooking\Application\Commands\CommandResult;
12 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
13 use AmeliaBooking\Domain\Collection\Collection;
14 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
15 use AmeliaBooking\Domain\Entity\Bookable\Service\Service;
16 use AmeliaBooking\Domain\Entity\Entities;
17 use AmeliaBooking\Domain\Services\Settings\SettingsService;
18 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
19 use AmeliaBooking\Infrastructure\Repository\Bookable\Service\ServiceRepository;
20 use Interop\Container\Exception\ContainerException;
21 use Slim\Exception\ContainerValueNotFoundException;
22
23 /**
24 * Class GetServicesCommandHandler
25 *
26 * @package AmeliaBooking\Application\Commands\Bookable\Service
27 */
28 class GetServicesCommandHandler extends CommandHandler
29 {
30 /**
31 * @param GetServicesCommand $command
32 *
33 * @return CommandResult
34 * @throws ContainerValueNotFoundException
35 * @throws QueryExecutionException
36 * @throws InvalidArgumentException
37 * @throws AccessDeniedException
38 * @throws ContainerException
39 */
40 public function handle(GetServicesCommand $command)
41 {
42 if (!$command->getPermissionService()->currentUserCanRead(Entities::SERVICES)) {
43 throw new AccessDeniedException('You are not allowed to read services.');
44 }
45
46 $result = new CommandResult();
47
48 $this->checkMandatoryFields($command);
49
50 /** @var ServiceRepository $serviceRepository */
51 $serviceRepository = $this->container->get('domain.bookable.service.repository');
52
53 /** @var SettingsService $settingsService */
54 $settingsService = $this->getContainer()->get('domain.settings.service');
55
56 $generalSettings = $settingsService->getCategorySettings('general');
57
58 /** @var Collection $services */
59 $services = $serviceRepository->getFiltered(
60 array_merge(
61 $command->getField('params'),
62 [
63 'sort' => $generalSettings['sortingServices']
64 ]
65 ),
66 $generalSettings['servicesPerPage']
67 );
68
69 /** @var Service $service */
70 foreach ($services->getItems() as $service) {
71 if ($service->getSettings() && json_decode($service->getSettings()->getValue(), true) === null) {
72 $service->setSettings(null);
73 }
74 }
75
76 $servicesArray = $services->toArray();
77
78 $servicesArray = apply_filters('amelia_get_services_filter', $servicesArray);
79
80 do_action('amelia_get_services', $servicesArray);
81
82 $result->setResult(CommandResult::RESULT_SUCCESS);
83 $result->setMessage('Successfully retrieved services.');
84 $result->setData(
85 [
86 Entities::SERVICES => $servicesArray,
87 'countFiltered' => (int)$serviceRepository->getCount($command->getField('params')),
88 'countTotal' => (int)$serviceRepository->getCount([]),
89 ]
90 );
91
92 return $result;
93 }
94 }
95