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 / Provider / AddProviderCommandHandler.php
ameliabooking / src / Application / Commands / User / Provider Last commit date
AddProviderCommand.php 1 year ago AddProviderCommandHandler.php 3 days ago GetProviderCommand.php 7 years ago GetProviderCommandHandler.php 2 months ago GetProvidersCommand.php 1 year ago GetProvidersCommandHandler.php 4 months ago UpdateProviderCommand.php 1 year ago UpdateProviderCommandHandler.php 3 days ago UpdateProviderStatusCommand.php 1 year ago UpdateProviderStatusCommandHandler.php 6 months ago
AddProviderCommandHandler.php
86 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\User\Provider;
4
5 use AmeliaBooking\Application\Commands\CommandHandler;
6 use AmeliaBooking\Application\Commands\CommandResult;
7 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
8 use AmeliaBooking\Application\Services\User\ProviderApplicationService;
9 use AmeliaBooking\Application\Services\User\UserApplicationService;
10 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
11 use AmeliaBooking\Domain\Entity\Entities;
12 use AmeliaBooking\Domain\Entity\User\AbstractUser;
13 use AmeliaBooking\Domain\Entity\User\Provider;
14 use AmeliaBooking\Domain\Factory\User\UserFactory;
15 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
16 use AmeliaBooking\Domain\ValueObjects\String\Password;
17 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
18 use AmeliaBooking\Infrastructure\Repository\User\ProviderRepository;
19 use Interop\Container\Exception\ContainerException;
20 use Slim\Exception\ContainerValueNotFoundException;
21
22 /**
23 * Class AddProviderCommandHandler
24 *
25 * @package AmeliaBooking\Application\Commands\User\Provider
26 */
27 class AddProviderCommandHandler extends CommandHandler
28 {
29 public $mandatoryFields = [
30 'type',
31 'firstName',
32 'lastName',
33 'email'
34 ];
35
36 /**
37 * @param AddProviderCommand $command
38 *
39 * @return CommandResult
40 * @throws ContainerValueNotFoundException
41 * @throws AccessDeniedException
42 * @throws InvalidArgumentException
43 * @throws QueryExecutionException
44 * @throws ContainerException
45 */
46 public function handle(AddProviderCommand $command)
47 {
48 if (
49 !$command->getPermissionService()->currentUserCanWrite(Entities::EMPLOYEES) ||
50 !$command->getPermissionService()->currentUserCanWriteOthers(Entities::EMPLOYEES)
51 ) {
52 throw new AccessDeniedException('You are not allowed to add employee.');
53 }
54
55 /** @var AbstractUser $currentUser */
56 $currentUser = $this->container->get('logged.in.user');
57
58 // Only admins may link a new provider to an existing WordPress user account.
59 $requestedExternalId = $command->getField('externalId');
60 if (
61 !empty($requestedExternalId) &&
62 (int)$requestedExternalId !== 0 &&
63 (!$currentUser || $currentUser->getType() !== AbstractUser::USER_ROLE_ADMIN)
64 ) {
65 throw new AccessDeniedException('You are not allowed to link to an existing WordPress user.');
66 }
67
68 /** @var ProviderApplicationService $providerAS */
69 $providerAS = $this->container->get('application.user.provider.service');
70
71 $this->checkMandatoryFields($command);
72
73 $providerData = $command->getFields();
74
75 $providerData = apply_filters('amelia_before_provider_added_filter', $providerData);
76
77 do_action('amelia_before_provider_added', $providerData);
78
79 $result = $providerAS->createProvider($providerData);
80
81 do_action('amelia_after_provider_added', $result ? $result->getData() : null);
82
83 return $result;
84 }
85 }
86