PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
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 / Settings / UpdateSettingsCategoriesCommandHandler.php
ameliabooking / src / Application / Commands / Settings Last commit date
FeaturesIntegrations 1 month ago ExportDataTransferCommand.php 3 weeks ago ExportDataTransferCommandHandler.php 3 weeks ago GetSettingsCommand.php 1 year ago GetSettingsCommandHandler.php 1 month ago ProcessImportDataTransferCommand.php 3 weeks ago ProcessImportDataTransferCommandHandler.php 3 weeks ago StartImportDataTransferCommand.php 3 weeks ago StartImportDataTransferCommandHandler.php 3 weeks ago UpdateSettingsCategoriesCommand.php 7 months ago UpdateSettingsCategoriesCommandHandler.php 1 month ago UpdateSettingsCommand.php 1 year ago UpdateSettingsCommandHandler.php 1 month ago
UpdateSettingsCategoriesCommandHandler.php
77 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 !== null) {
56 if ($category === 'general' && array_key_exists('usedLanguages', $data)) {
57 $categorySettings['usedLanguages'] = $data['usedLanguages'];
58 unset($data['usedLanguages']);
59 }
60
61 if ($category === 'ivy') {
62 $categorySettings = !empty($data['ivy']) ? $data['ivy'] : [];
63 }
64
65 $categorySettings = array_replace_recursive($categorySettings, $data);
66
67 $settingsService->setCategorySettings($category, $categorySettings);
68 }
69 }
70
71 $result->setResult(CommandResult::RESULT_SUCCESS);
72 $result->setMessage('Successfully updated settings.');
73
74 return $result;
75 }
76 }
77