PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 / Bookable / Category / GetCategoryCommandHandler.php
ameliabooking / src / Application / Commands / Bookable / Category Last commit date
AddCategoryCommand.php 1 year ago AddCategoryCommandHandler.php 6 months ago DeleteCategoryCommand.php 1 year ago DeleteCategoryCommandHandler.php 6 months ago GetCategoriesCommand.php 1 year ago GetCategoriesCommandHandler.php 6 months ago GetCategoryCommand.php 1 year ago GetCategoryCommandHandler.php 6 months ago GetCategoryDeleteEffectCommand.php 6 months ago GetCategoryDeleteEffectCommandHandler.php 3 months ago UpdateCategoriesPositionsCommand.php 1 year ago UpdateCategoriesPositionsCommandHandler.php 6 months ago UpdateCategoryCommand.php 1 year ago UpdateCategoryCommandHandler.php 6 months ago
GetCategoryCommandHandler.php
98 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\Bookable\Category;
4
5 use AmeliaBooking\Application\Commands\CommandHandler;
6 use AmeliaBooking\Application\Commands\CommandResult;
7 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
8 use AmeliaBooking\Domain\Collection\AbstractCollection;
9 use AmeliaBooking\Domain\Collection\Collection;
10 use AmeliaBooking\Domain\Entity\Bookable\Service\Category;
11 use AmeliaBooking\Domain\Entity\Bookable\Service\Service;
12 use AmeliaBooking\Domain\Entity\Entities;
13 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
14 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
15 use AmeliaBooking\Infrastructure\Repository\Bookable\Service\CategoryRepository;
16 use AmeliaBooking\Infrastructure\Repository\Bookable\Service\ServiceRepository;
17
18 /**
19 * Class GetCategoryCommandHandler
20 *
21 * @package AmeliaBooking\Application\Commands\Bookable\Category
22 */
23 class GetCategoryCommandHandler extends CommandHandler
24 {
25 /**
26 * @param GetCategoryCommand $command
27 *
28 * @return CommandResult
29 * @throws \Slim\Exception\ContainerValueNotFoundException
30 * @throws NotFoundException
31 * @throws QueryExecutionException
32 * @throws \AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException
33 */
34 public function handle(GetCategoryCommand $command)
35 {
36 if (!$command->getPermissionService()->currentUserCanRead(Entities::SERVICES)) {
37 throw new AccessDeniedException('You are not allowed to read categories.');
38 }
39
40 $result = new CommandResult();
41
42 /** @var CategoryRepository $categoryRepository */
43 $categoryRepository = $this->container->get('domain.bookable.category.repository');
44 /** @var ServiceRepository $serviceRepository */
45 $serviceRepository = $this->container->get('domain.bookable.service.repository');
46
47 /**
48 * Get services for category
49 */
50 $services = $serviceRepository->getByCriteria(['categories' => [$command->getArg('id')]]);
51
52 if (!$services instanceof AbstractCollection) {
53 $result->setResult(CommandResult::RESULT_ERROR);
54 $result->setMessage('Could not get services.');
55
56 return $result;
57 }
58
59 /**
60 * Get category
61 */
62 $category = $categoryRepository->getById($command->getArg('id'));
63
64 if (!$category instanceof Category) {
65 $result->setResult(CommandResult::RESULT_ERROR);
66 $result->setMessage('Could not get category.');
67
68 return $result;
69 }
70
71 /**
72 * Add services to category
73 */
74 $category->setServiceList(new Collection());
75
76 /** @var Service $service */
77 foreach ($services->getItems() as $service) {
78 $category->getServiceList()->addItem($service, $service->getId()->getValue());
79 }
80
81 $categoryArray = $category->toArray();
82
83 $categoryArray = apply_filters('amelia_get_category_filter', $categoryArray);
84
85 do_action('amelia_get_category', $categoryArray);
86
87 $result->setResult(CommandResult::RESULT_SUCCESS);
88 $result->setMessage('Successfully retrieved category.');
89 $result->setData(
90 [
91 Entities::CATEGORY => $categoryArray
92 ]
93 );
94
95 return $result;
96 }
97 }
98