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 / User / GetUserDeleteEffectCommandHandler.php
ameliabooking / src / Application / Commands / User Last commit date
Customer 2 days ago Provider 2 days ago DeleteUserCommand.php 1 year ago DeleteUserCommandHandler.php 1 year ago GetCurrentUserCommand.php 1 year ago GetCurrentUserCommandHandler.php 1 year ago GetUserDeleteEffectCommand.php 1 year ago GetUserDeleteEffectCommandHandler.php 6 months ago GetWPUsersCommand.php 1 year ago GetWPUsersCommandHandler.php 6 months ago
GetUserDeleteEffectCommandHandler.php
98 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\User;
4
5 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
6 use AmeliaBooking\Application\Services\User\UserApplicationService;
7 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
8 use AmeliaBooking\Domain\Entity\Entities;
9 use AmeliaBooking\Application\Commands\CommandResult;
10 use AmeliaBooking\Application\Commands\CommandHandler;
11 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
12 use AmeliaBooking\Domain\ValueObjects\String\BookingStatus;
13 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
14 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
15 use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventRepository;
16 use Interop\Container\Exception\ContainerException;
17 use Slim\Exception\ContainerValueNotFoundException;
18
19 /**
20 * Class GetUserDeleteEffectCommandHandler
21 *
22 * @package AmeliaBooking\Application\Commands\User
23 */
24 class GetUserDeleteEffectCommandHandler extends CommandHandler
25 {
26 /**
27 * @param GetUserDeleteEffectCommand $command
28 *
29 * @return CommandResult
30 * @throws ContainerValueNotFoundException
31 * @throws AccessDeniedException
32 * @throws InvalidArgumentException
33 * @throws NotFoundException
34 * @throws QueryExecutionException
35 * @throws ContainerException
36 */
37 public function handle(GetUserDeleteEffectCommand $command)
38 {
39 if (
40 !$command->getPermissionService()->currentUserCanRead(Entities::EMPLOYEES) &&
41 !$command->getPermissionService()->currentUserCanRead(Entities::CUSTOMERS)
42 ) {
43 throw new AccessDeniedException('You are not allowed to read user');
44 }
45
46 $result = new CommandResult();
47
48 /** @var UserApplicationService $userAS */
49 $userAS = $this->getContainer()->get('application.user.service');
50
51 /** @var EventRepository $eventRepository */
52 $eventRepository = $this->container->get('domain.booking.event.repository');
53
54 $appointmentsCount = $userAS->getAppointmentsCountForUser($command->getArg('id'));
55
56 $eventsIds = $eventRepository->getFilteredIds(
57 [
58 'customerId' => $command->getArg('id'),
59 'customerBookingStatus' => BookingStatus::APPROVED,
60 'dates' => [DateTimeService::getNowDateTime()],
61 ],
62 0
63 );
64
65 $messageKey = '';
66 $messageData = null;
67
68 if ($appointmentsCount['futureAppointments'] > 0) {
69 $messageKey = 'red_delete_user_effect_future';
70 $messageData = ['count' => $appointmentsCount['futureAppointments']];
71 } elseif ($appointmentsCount['packageAppointments']) {
72 $messageKey = 'red_delete_user_effect_package';
73 } elseif ($appointmentsCount['pastAppointments'] > 0) {
74 $messageKey = 'red_delete_user_effect_past';
75 $messageData = ['count' => $appointmentsCount['pastAppointments']];
76 } elseif ($eventsIds) {
77 $messageKey = 'red_delete_user_event_effect_future';
78 $messageData = ['count' => count($eventsIds)];
79 }
80
81 $result->setResult(CommandResult::RESULT_SUCCESS);
82 $result->setMessage('Successfully retrieved message.');
83 $result->setData(
84 [
85 'valid' => ! $appointmentsCount['futureAppointments'],
86 'messageKey' => $messageKey,
87 'messageData' => $messageData,
88 'futureAppointmentsCount' => $appointmentsCount['futureAppointments'],
89 'packageAppointmentsCount' => $appointmentsCount['packageAppointments'],
90 'pastAppointmentsCount' => $appointmentsCount['pastAppointments'],
91 'eventsCount' => count($eventsIds)
92 ]
93 );
94
95 return $result;
96 }
97 }
98