PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 / UpdateCategoryCommandHandler.php
ameliabooking / src / Application / Commands / Bookable / Category Last commit date
AddCategoryCommand.php 7 years ago AddCategoryCommandHandler.php 2 years ago DeleteCategoryCommand.php 7 years ago DeleteCategoryCommandHandler.php 2 years ago GetCategoriesCommand.php 7 years ago GetCategoriesCommandHandler.php 2 years ago GetCategoryCommand.php 7 years ago GetCategoryCommandHandler.php 2 years ago UpdateCategoriesPositionsCommand.php 7 years ago UpdateCategoriesPositionsCommandHandler.php 2 years ago UpdateCategoryCommand.php 7 years ago UpdateCategoryCommandHandler.php 2 years ago
UpdateCategoryCommandHandler.php
72 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\Common\Exceptions\InvalidArgumentException;
9 use AmeliaBooking\Domain\Entity\Bookable\Service\Category;
10 use AmeliaBooking\Domain\Entity\Entities;
11 use AmeliaBooking\Domain\Factory\Bookable\Service\CategoryFactory;
12 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
13 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
14 use AmeliaBooking\Infrastructure\Repository\Bookable\Service\CategoryRepository;
15
16 /**
17 * Class UpdateCategoryCommandHandler
18 *
19 * @package AmeliaBooking\Application\Commands\Bookable\Category
20 */
21 class UpdateCategoryCommandHandler extends CommandHandler
22 {
23 /**
24 * @param UpdateCategoryCommand $command
25 *
26 * @return CommandResult
27 * @throws \Slim\Exception\ContainerValueNotFoundException
28 * @throws AccessDeniedException
29 * @throws QueryExecutionException
30 * @throws \Interop\Container\Exception\ContainerException
31 * @throws InvalidArgumentException
32 */
33 public function handle(UpdateCategoryCommand $command)
34 {
35 if (!$command->getPermissionService()->currentUserCanWrite(Entities::SERVICES)) {
36 throw new AccessDeniedException('You are not allowed to update bookable category.');
37 }
38
39 $result = new CommandResult();
40
41 $categoryArray = $command->getFields();
42
43 $categoryArray = apply_filters('amelia_before_category_updated_filter', $categoryArray);
44
45 do_action('amelia_before_category_updated', $categoryArray);
46
47 $category = CategoryFactory::create($categoryArray);
48 if (!$category instanceof Category) {
49 $result->setResult(CommandResult::RESULT_ERROR);
50 $result->setMessage('Could not update bookable category.');
51
52 return $result;
53 }
54
55 /** @var CategoryRepository $categoryRepository */
56 $categoryRepository = $this->container->get('domain.bookable.category.repository');
57 if ($categoryRepository->update($command->getArg('id'), $category)) {
58 $category->setId(new Id($command->getArg('id')));
59
60 do_action('amelia_after_category_updated', $category->toArray());
61
62 $result->setResult(CommandResult::RESULT_SUCCESS);
63 $result->setMessage('Successfully updated bookable category.');
64 $result->setData([
65 Entities::CATEGORY => $category->toArray()
66 ]);
67 }
68
69 return $result;
70 }
71 }
72