PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 / GetServiceCommandHandler.php
ameliabooking / src / Application / Commands / Bookable / Service Last commit date
AddServiceCommand.php 6 months ago AddServiceCommandHandler.php 6 months ago DeleteServiceCommand.php 6 months ago DeleteServiceCommandHandler.php 3 months ago GetServiceCommand.php 6 months ago GetServiceCommandHandler.php 6 months ago GetServiceDeleteEffectCommand.php 1 year ago GetServiceDeleteEffectCommandHandler.php 3 months ago GetServicesCommand.php 6 months ago GetServicesCommandHandler.php 2 weeks ago UpdateServiceCommand.php 6 months ago UpdateServiceCommandHandler.php 6 months ago UpdateServiceStatusCommand.php 6 months ago UpdateServiceStatusCommandHandler.php 6 months ago UpdateServicesPositionsCommand.php 1 year ago UpdateServicesPositionsCommandHandler.php 1 year ago
GetServiceCommandHandler.php
104 lines
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. 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\Common\Exceptions\InvalidArgumentException;
14 use AmeliaBooking\Domain\Entity\Bookable\Service\Service;
15 use AmeliaBooking\Domain\Entity\Entities;
16 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
17 use AmeliaBooking\Domain\Services\Settings\SettingsService;
18 use AmeliaBooking\Domain\ValueObjects\Json;
19 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
20 use AmeliaBooking\Infrastructure\Repository\Bookable\Service\ServiceRepository;
21 use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\AppointmentRepository;
22 use Slim\Exception\ContainerValueNotFoundException;
23 use AmeliaBooking\Infrastructure\Repository\User\ProviderRepository;
24
25 /**
26 * Class GetServiceCommandHandler
27 *
28 * @package AmeliaBooking\Application\Commands\Bookable\Service
29 */
30 class GetServiceCommandHandler extends CommandHandler
31 {
32 /**
33 * @param GetServiceCommand $command
34 *
35 * @return CommandResult
36 * @throws ContainerValueNotFoundException
37 * @throws QueryExecutionException
38 * @throws InvalidArgumentException
39 */
40 public function handle(GetServiceCommand $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 /** @var ServiceRepository $serviceRepository */
49 $serviceRepository = $this->container->get('domain.bookable.service.repository');
50
51 /** @var AppointmentRepository $appointmentRepository */
52 $appointmentRepository = $this->container->get('domain.booking.appointment.repository');
53
54 /** @var Service $service */
55 $service = $serviceRepository->getByCriteria(
56 ['services' => [$command->getArg('id')]]
57 )->getItem($command->getArg('id'));
58
59 // fix for wrongly saved JSON
60 if (
61 $service->getSettings() &&
62 json_decode($service->getSettings()->getValue(), true) === null
63 ) {
64 $service->setSettings(null);
65 }
66
67 if ($service->getSettings()) {
68 /** @var SettingsService $settingsDS */
69 $settingsDS = $this->container->get('domain.settings.service');
70
71 $service->setSettings(new Json(json_encode($settingsDS->getSavedSettings($service->getSettings()))));
72 }
73
74 $futureAppointmentsProvidersIds = $appointmentRepository->getFutureAppointmentsProvidersIds(
75 [$service->getId()->getValue()],
76 DateTimeService::getNowDateTime(),
77 null
78 );
79
80 $serviceArray = $service->toArray();
81
82 /** @var ProviderRepository $providerRepository */
83 $providerRepository = $this->container->get('domain.users.providers.repository');
84
85 $providers = $providerRepository->getProvidersServices([$service->getId()->getValue()]);
86 $serviceArray['providers'] = array_keys($providers);
87
88 $serviceArray = apply_filters('amelia_get_service_filter', $serviceArray);
89
90 do_action('amelia_get_service', $serviceArray);
91
92 $result->setResult(CommandResult::RESULT_SUCCESS);
93 $result->setMessage('Successfully retrieved service.');
94 $result->setData(
95 [
96 Entities::SERVICE => $serviceArray,
97 'futureAppointmentsProvidersIds' => $futureAppointmentsProvidersIds,
98 ]
99 );
100
101 return $result;
102 }
103 }
104