PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.4
Booking for Appointments and Events Calendar – Amelia v1.2.4
2.4.9 2.4.8 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 / User / GetUserDeleteEffectCommandHandler.php
ameliabooking / src / Application / Commands / User Last commit date
Customer 1 year ago Provider 1 year 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 1 year ago GetWPUsersCommand.php 1 year ago GetWPUsersCommandHandler.php 1 year ago
GetUserDeleteEffectCommandHandler.php
99 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\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\Domain\Services\DateTime\DateTimeService;
13 use AmeliaBooking\Domain\ValueObjects\String\BookingStatus;
14 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
15 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
16 use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventRepository;
17 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
18 use Interop\Container\Exception\ContainerException;
19 use Slim\Exception\ContainerValueNotFoundException;
20
21 /**
22 * Class GetUserDeleteEffectCommandHandler
23 *
24 * @package AmeliaBooking\Application\Commands\User
25 */
26 class GetUserDeleteEffectCommandHandler extends CommandHandler
27 {
28 /**
29 * @param GetUserDeleteEffectCommand $command
30 *
31 * @return CommandResult
32 * @throws ContainerValueNotFoundException
33 * @throws AccessDeniedException
34 * @throws InvalidArgumentException
35 * @throws NotFoundException
36 * @throws QueryExecutionException
37 * @throws ContainerException
38 */
39 public function handle(GetUserDeleteEffectCommand $command)
40 {
41 if (!$command->getPermissionService()->currentUserCanRead(Entities::EMPLOYEES) &&
42 !$command->getPermissionService()->currentUserCanRead(Entities::CUSTOMERS)
43 ) {
44 throw new AccessDeniedException('You are not allowed to read user');
45 }
46
47 $result = new CommandResult();
48
49 /** @var UserApplicationService $userAS */
50 $userAS = $this->getContainer()->get('application.user.service');
51
52 /** @var EventRepository $eventRepository */
53 $eventRepository = $this->container->get('domain.booking.event.repository');
54
55 $appointmentsCount = $userAS->getAppointmentsCountForUser($command->getArg('id'));
56
57 /** @var Collection $events */
58 $events = $eventRepository->getFiltered(
59 [
60 'customerId' => $command->getArg('id'),
61 'bookingStatus' => BookingStatus::APPROVED,
62 'dates' => [DateTimeService::getNowDateTime()],
63 ]
64 );
65
66 $message = '';
67
68 if ($appointmentsCount['futureAppointments'] > 0) {
69 $appointmentString = $appointmentsCount['futureAppointments'] === 1 ? 'appointment' : 'appointments';
70
71 $message = "Could not delete user.
72 This user has {$appointmentsCount['futureAppointments']} {$appointmentString} in the future.";
73 } elseif ($appointmentsCount['packageAppointments']) {
74 $message = "This service is available for booking in purchased package.
75 Are you sure you want to delete this user?";
76 } elseif ($appointmentsCount['pastAppointments'] > 0) {
77 $appointmentString = $appointmentsCount['pastAppointments'] === 1 ? 'appointment' : 'appointments';
78
79 $message = "This user has {$appointmentsCount['pastAppointments']} {$appointmentString} in the past.";
80 } elseif ($events->length()) {
81 $eventString = $events->length() > 1 ? 'events' : 'event';
82
83 $message = "This user is an attendee in future {$eventString}.
84 Are you sure you want to delete this user?";
85 }
86
87 $result->setResult(CommandResult::RESULT_SUCCESS);
88 $result->setMessage('Successfully retrieved message.');
89 $result->setData(
90 [
91 'valid' => $appointmentsCount['futureAppointments'] ? false : true,
92 'message' => $message
93 ]
94 );
95
96 return $result;
97 }
98 }
99