PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.0.2
Booking for Appointments and Events Calendar – Amelia v2.0.2
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 / Category / GetCategoryDeleteEffectCommandHandler.php
ameliabooking / src / Application / Commands / Bookable / Category Last commit date
AddCategoryCommand.php 1 year ago AddCategoryCommandHandler.php 6 months ago DeleteCategoryCommand.php 1 year ago DeleteCategoryCommandHandler.php 6 months ago GetCategoriesCommand.php 1 year ago GetCategoriesCommandHandler.php 6 months ago GetCategoryCommand.php 1 year ago GetCategoryCommandHandler.php 6 months ago GetCategoryDeleteEffectCommand.php 6 months ago GetCategoryDeleteEffectCommandHandler.php 6 months ago UpdateCategoriesPositionsCommand.php 1 year ago UpdateCategoriesPositionsCommandHandler.php 6 months ago UpdateCategoryCommand.php 1 year ago UpdateCategoryCommandHandler.php 6 months ago
GetCategoryDeleteEffectCommandHandler.php
89 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\Bookable\Category;
4
5 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
6 use AmeliaBooking\Application\Services\Bookable\BookableApplicationService;
7 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
8 use AmeliaBooking\Domain\Entity\Bookable\Service\Service;
9 use AmeliaBooking\Domain\Entity\Entities;
10 use AmeliaBooking\Application\Commands\CommandResult;
11 use AmeliaBooking\Application\Commands\CommandHandler;
12 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
13 use AmeliaBooking\Infrastructure\Repository\Bookable\Service\ServiceRepository;
14 use AmeliaBooking\Domain\Collection\Collection;
15 use Interop\Container\Exception\ContainerException;
16 use Slim\Exception\ContainerValueNotFoundException;
17
18 /**
19 * Class GetCategoryDeleteEffectCommandHandler
20 *
21 * @package AmeliaBooking\Application\Commands\Bookable\Category
22 */
23 class GetCategoryDeleteEffectCommandHandler extends CommandHandler
24 {
25 /**
26 * @param GetCategoryDeleteEffectCommand $command
27 *
28 * @return CommandResult
29 * @throws ContainerValueNotFoundException
30 * @throws AccessDeniedException
31 * @throws QueryExecutionException
32 * @throws ContainerException
33 * @throws InvalidArgumentException
34 */
35 public function handle(GetCategoryDeleteEffectCommand $command)
36 {
37 if (!$command->getPermissionService()->currentUserCanRead(Entities::SERVICES)) {
38 throw new AccessDeniedException('You are not allowed to read categories');
39 }
40
41 $result = new CommandResult();
42
43 /** @var BookableApplicationService $bookableAS */
44 $bookableAS = $this->getContainer()->get('application.bookable.service');
45
46 /** @var ServiceRepository $serviceRepository */
47 $serviceRepository = $this->getContainer()->get('domain.bookable.service.repository');
48
49 /** @var Collection $services */
50 $services = $serviceRepository->getByCriteria(['categories' => [$command->getArg('id')]]);
51
52 $categoryServiceIds = [];
53
54 /** @var Service $service */
55 foreach ($services->getItems() as $service) {
56 $categoryServiceIds[] = $service->getId()->getValue();
57 }
58
59 $messageKey = '';
60 $messageData = null;
61
62 if ($categoryServiceIds) {
63 $appointmentsCount = $bookableAS->getAppointmentsCountForServices($categoryServiceIds);
64
65 if ($appointmentsCount['futureAppointments'] > 0) {
66 $messageKey = 'red_delete_category_effect_future';
67 $messageData = ['count' => $appointmentsCount['futureAppointments']];
68 } elseif ($appointmentsCount['packageAppointments']) {
69 $messageKey = 'red_delete_category_effect_package';
70 } elseif ($appointmentsCount['pastAppointments'] > 0) {
71 $messageKey = 'red_delete_category_effect_past';
72 $messageData = ['count' => $appointmentsCount['pastAppointments']];
73 }
74 }
75
76 $result->setResult(CommandResult::RESULT_SUCCESS);
77 $result->setMessage('Successfully retrieved message.');
78 $result->setData(
79 [
80 'valid' => !($categoryServiceIds && ($appointmentsCount['futureAppointments'] || $appointmentsCount['packageAppointments'])),
81 'messageKey' => $messageKey,
82 'messageData' => $messageData,
83 ]
84 );
85
86 return $result;
87 }
88 }
89