PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 1 year ago Provider 1 year ago DeleteUserCommand.php 7 years ago DeleteUserCommandHandler.php 2 years ago GetCurrentUserCommand.php 7 years ago GetCurrentUserCommandHandler.php 2 years ago GetUserDeleteEffectCommand.php 7 years ago GetUserDeleteEffectCommandHandler.php 1 year ago GetWPUsersCommand.php 7 years ago GetWPUsersCommandHandler.php 2 years ago
GetUserDeleteEffectCommandHandler.php
97 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 (!$command->getPermissionService()->currentUserCanRead(Entities::EMPLOYEES) &&
40 !$command->getPermissionService()->currentUserCanRead(Entities::CUSTOMERS)
41 ) {
42 throw new AccessDeniedException('You are not allowed to read user');
43 }
44
45 $result = new CommandResult();
46
47 /** @var UserApplicationService $userAS */
48 $userAS = $this->getContainer()->get('application.user.service');
49
50 /** @var EventRepository $eventRepository */
51 $eventRepository = $this->container->get('domain.booking.event.repository');
52
53 $appointmentsCount = $userAS->getAppointmentsCountForUser($command->getArg('id'));
54
55 $eventsIds = $eventRepository->getFilteredIds(
56 [
57 'customerId' => $command->getArg('id'),
58 'customerBookingStatus' => BookingStatus::APPROVED,
59 'dates' => [DateTimeService::getNowDateTime()],
60 ],
61 0
62 );
63
64 $message = '';
65
66 if ($appointmentsCount['futureAppointments'] > 0) {
67 $appointmentString = $appointmentsCount['futureAppointments'] === 1 ? 'appointment' : 'appointments';
68
69 $message = "Could not delete user.
70 This user has {$appointmentsCount['futureAppointments']} {$appointmentString} in the future.";
71 } elseif ($appointmentsCount['packageAppointments']) {
72 $message = "This user has bookings in purchased package.
73 Are you sure you want to delete this user?";
74 } elseif ($appointmentsCount['pastAppointments'] > 0) {
75 $appointmentString = $appointmentsCount['pastAppointments'] === 1 ? 'appointment' : 'appointments';
76
77 $message = "This user has {$appointmentsCount['pastAppointments']} {$appointmentString} in the past.";
78 } elseif ($eventsIds) {
79 $eventString = sizeof($eventsIds) > 1 ? 'events' : 'event';
80
81 $message = "This user is an attendee in future {$eventString}.
82 Are you sure you want to delete this user?";
83 }
84
85 $result->setResult(CommandResult::RESULT_SUCCESS);
86 $result->setMessage('Successfully retrieved message.');
87 $result->setData(
88 [
89 'valid' => $appointmentsCount['futureAppointments'] ? false : true,
90 'message' => $message
91 ]
92 );
93
94 return $result;
95 }
96 }
97