PluginProbe
Booking for Appointments and Events Calendar – Amelia / 2.4.2
Booking for Appointments and Events Calendar – Amelia v2.4.2
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 All 59 releases
ameliabooking / src / Application / Commands / Calendar / GetBlockTimeCommandHandler.php
GetBlockTimeCommandHandler.php
81 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Application\Commands\Calendar;
9
10 use AmeliaBooking\Application\Commands\CommandHandler;
11 use AmeliaBooking\Application\Commands\CommandResult;
12 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
13 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
14 use AmeliaBooking\Domain\Entity\Entities;
15 use AmeliaBooking\Domain\Entity\Schedule\BlockTime;
16 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
17 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
18 use AmeliaBooking\Infrastructure\Repository\Schedule\DayOffRepository;
19 use AmeliaVendor\Psr\Container\ContainerExceptionInterface;
20
21 /**
22 * Class GetBlockTimeCommandHandler
23 *
24 * @package AmeliaBooking\Application\Commands\Calendar
25 */
26 class GetBlockTimeCommandHandler extends CommandHandler
27 {
28 /**
29 * @param GetBlockTimeCommand $command
30 *
31 * @return CommandResult
32 * @throws AccessDeniedException
33 * @throws InvalidArgumentException
34 * @throws QueryExecutionException|ContainerExceptionInterface
35 */
36 public function handle(GetBlockTimeCommand $command): CommandResult
37 {
38 $currentUser = $this->container->get('logged.in.user');
39
40 if ($currentUser === null) {
41 throw new AccessDeniedException('You are not allowed to read block time');
42 }
43
44 if ($currentUser->getType() === Entities::CUSTOMER) {
45 throw new AccessDeniedException('You are not allowed to read block time');
46 }
47
48 $result = new CommandResult();
49
50 $this->checkMandatoryFields($command);
51
52 /** @var DayOffRepository $dayOffRepository */
53 $dayOffRepository = $this->container->get('domain.schedule.dayOff.repository');
54
55 /** @var BlockTime $blockTime */
56 $blockTime = $dayOffRepository->getBlockTimeById($command->getArg('id'));
57
58 $blockTimeArray = $blockTime->toArray();
59
60 $canManage = true;
61
62 if ($currentUser->getType() === Entities::PROVIDER) {
63 $providerId = $currentUser->getId()->getValue();
64 $blockTimeUserId = $blockTime->getUserId() ? $blockTime->getUserId()->getValue() : null;
65
66 if ($blockTimeUserId === null || (int)$blockTimeUserId !== (int)$providerId) {
67 $canManage = false;
68 }
69 }
70
71 $result->setResult(CommandResult::RESULT_SUCCESS);
72 $result->setMessage('Successfully retrieved block time.');
73 $result->setData([
74 'blockTime' => $blockTimeArray,
75 'canManage' => $canManage
76 ]);
77
78 return $result;
79 }
80 }
81