PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.0.2
Booking for Appointments and Events Calendar – Amelia v2.0.2
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 / Settings / UpdateSettingsCategoriesCommandHandler.php
ameliabooking / src / Application / Commands / Settings Last commit date
FeaturesIntegrations 6 months ago GetSettingsCommand.php 1 year ago GetSettingsCommandHandler.php 6 months ago UpdateSettingsCategoriesCommand.php 6 months ago UpdateSettingsCategoriesCommandHandler.php 6 months ago UpdateSettingsCommand.php 1 year ago UpdateSettingsCommandHandler.php 6 months ago
UpdateSettingsCategoriesCommandHandler.php
68 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\Settings;
4
5 use AmeliaBooking\Application\Commands\CommandHandler;
6 use AmeliaBooking\Application\Commands\CommandResult;
7 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
8 use AmeliaBooking\Domain\Entity\Entities;
9 use AmeliaBooking\Domain\Entity\User\AbstractUser;
10 use AmeliaBooking\Domain\Services\Settings\SettingsService;
11 use Exception;
12 use Interop\Container\Exception\ContainerException;
13 use Slim\Exception\ContainerValueNotFoundException;
14
15 /**
16 * Class UpdateSettingsCategoriesCommandHandler
17 *
18 * @package AmeliaBooking\Application\Commands\Settings
19 */
20 class UpdateSettingsCategoriesCommandHandler extends CommandHandler
21 {
22 /**
23 * @param UpdateSettingsCategoriesCommand $command
24 *
25 * @return CommandResult
26 * @throws AccessDeniedException
27 * @throws ContainerValueNotFoundException
28 * @throws ContainerException
29 * @throws Exception
30 */
31 public function handle(UpdateSettingsCategoriesCommand $command)
32 {
33 $result = new CommandResult();
34
35 if (!$this->getContainer()->getPermissionsService()->currentUserCanWrite(Entities::SETTINGS)) {
36 /** @var AbstractUser $loggedInUser */
37 $loggedInUser = $this->container->get('logged.in.user');
38
39 if (
40 !$loggedInUser || !(
41 $loggedInUser->getType() === AbstractUser::USER_ROLE_ADMIN ||
42 $loggedInUser->getType() === AbstractUser::USER_ROLE_MANAGER
43 )
44 ) {
45 throw new AccessDeniedException('You are not allowed to write settings.');
46 }
47 }
48
49 /** @var SettingsService $settingsService */
50 $settingsService = $this->getContainer()->get('domain.settings.service');
51
52 foreach ($command->getField('categories') as $category => $data) {
53 $categorySettings = $settingsService->getCategorySettings($category);
54
55 if ($categorySettings) {
56 $categorySettings = array_replace_recursive($categorySettings, $data);
57
58 $settingsService->setCategorySettings($category, $categorySettings);
59 }
60 }
61
62 $result->setResult(CommandResult::RESULT_SUCCESS);
63 $result->setMessage('Successfully updated settings.');
64
65 return $result;
66 }
67 }
68