PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
2.4.7 2.4.6 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 / GetServiceDeleteEffectCommandHandler.php
ameliabooking / src / Application / Commands / Bookable / Service Last commit date
AddServiceCommand.php 7 months ago AddServiceCommandHandler.php 7 months ago DeleteServiceCommand.php 7 months ago DeleteServiceCommandHandler.php 4 weeks ago GetServiceCommand.php 7 months ago GetServiceCommandHandler.php 7 months ago GetServiceDeleteEffectCommand.php 1 year ago GetServiceDeleteEffectCommandHandler.php 4 weeks ago GetServicesCommand.php 7 months ago GetServicesCommandHandler.php 1 month ago UpdateServiceCommand.php 7 months ago UpdateServiceCommandHandler.php 7 months ago UpdateServiceStatusCommand.php 7 months ago UpdateServiceStatusCommandHandler.php 4 weeks ago UpdateServicesPositionsCommand.php 1 year ago UpdateServicesPositionsCommandHandler.php 1 year ago
GetServiceDeleteEffectCommandHandler.php
82 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\Bookable\Service;
4
5 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
6 use AmeliaBooking\Application\Services\Bookable\BookableApplicationService;
7 use AmeliaBooking\Domain\Collection\Collection;
8 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
9 use AmeliaBooking\Domain\Entity\Entities;
10 use AmeliaBooking\Application\Commands\CommandResult;
11 use AmeliaBooking\Application\Commands\CommandHandler;
12 use AmeliaBooking\Application\Services\Bookable\AbstractPackageApplicationService;
13 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
14 use AmeliaBooking\Infrastructure\Repository\Bookable\Service\PackageRepository;
15 use Slim\Exception\ContainerValueNotFoundException;
16
17 /**
18 * Class GetServiceDeleteEffectCommandHandler
19 *
20 * @package AmeliaBooking\Application\Commands\Bookable\Service
21 */
22 class GetServiceDeleteEffectCommandHandler extends CommandHandler
23 {
24 /**
25 * @param GetServiceDeleteEffectCommand $command
26 *
27 * @return CommandResult
28 * @throws ContainerValueNotFoundException
29 * @throws AccessDeniedException
30 * @throws QueryExecutionException
31 * @throws InvalidArgumentException
32 */
33 public function handle(GetServiceDeleteEffectCommand $command)
34 {
35 if (!$command->getPermissionService()->currentUserCanRead(Entities::SERVICES)) {
36 throw new AccessDeniedException('You are not allowed to read services');
37 }
38
39 $result = new CommandResult();
40
41 /** @var AbstractPackageApplicationService $packageApplicationService */
42 $packageApplicationService = $this->container->get('application.bookable.package');
43
44 /** @var BookableApplicationService $bookableAS */
45 $bookableAS = $this->getContainer()->get('application.bookable.service');
46
47 $appointmentsCount = $bookableAS->getAppointmentsCountForServices([$command->getArg('id')]);
48
49 $messageKey = '';
50 $messageData = null;
51
52 if ($appointmentsCount['futureAppointments'] > 0) {
53 $messageKey = 'red_delete_service_effect_future';
54 $messageData = ['count' => $appointmentsCount['futureAppointments']];
55 } elseif ($appointmentsCount['packageAppointments']) {
56 $messageKey = 'red_delete_service_effect_package';
57 } elseif ($appointmentsCount['pastAppointments'] > 0) {
58 $messageKey = 'red_delete_service_effect_past';
59 $messageData = ['count' => $appointmentsCount['pastAppointments']];
60 }
61
62 /** @var array $packages */
63 $packages = $packageApplicationService->getPackagesArray(['services' => [$command->getArg('id')]]);
64
65 if ($packages && count($packages) > 0) {
66 $messageKey = 'red_service_failed_to_be_deleted';
67 }
68
69 $result->setResult(CommandResult::RESULT_SUCCESS);
70 $result->setMessage('Successfully retrieved message.');
71 $result->setData(
72 [
73 'valid' => !$appointmentsCount['futureAppointments'] && (!$packages || count($packages) === 0),
74 'messageKey' => $messageKey,
75 'messageData' => $messageData,
76 ]
77 );
78
79 return $result;
80 }
81 }
82