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 / UpdateCategoryCommandHandler.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
UpdateCategoryCommandHandler.php
73 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 InvalidArgumentException
31 */
32 public function handle(UpdateCategoryCommand $command)
33 {
34 if (!$command->getPermissionService()->currentUserCanWrite(Entities::SERVICES)) {
35 throw new AccessDeniedException('You are not allowed to update bookable category.');
36 }
37
38 $result = new CommandResult();
39
40 $categoryArray = $command->getFields();
41
42 $categoryArray = apply_filters('amelia_before_category_updated_filter', $categoryArray);
43
44 do_action('amelia_before_category_updated', $categoryArray);
45
46 $category = CategoryFactory::create($categoryArray);
47 if (!$category instanceof Category) {
48 $result->setResult(CommandResult::RESULT_ERROR);
49 $result->setMessage('Could not update bookable category.');
50
51 return $result;
52 }
53
54 /** @var CategoryRepository $categoryRepository */
55 $categoryRepository = $this->container->get('domain.bookable.category.repository');
56 if ($categoryRepository->update($command->getArg('id'), $category)) {
57 $category->setId(new Id($command->getArg('id')));
58
59 do_action('amelia_after_category_updated', $category->toArray());
60
61 $result->setResult(CommandResult::RESULT_SUCCESS);
62 $result->setMessage('Successfully updated bookable category.');
63 $result->setData(
64 [
65 Entities::CATEGORY => $category->toArray()
66 ]
67 );
68 }
69
70 return $result;
71 }
72 }
73