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