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 / Settings / GetSettingsCommandHandler.php
ameliabooking / src / Application / Commands / Settings Last commit date
FeaturesIntegrations 2 weeks ago GetSettingsCommand.php 1 year ago GetSettingsCommandHandler.php 2 weeks ago UpdateSettingsCategoriesCommand.php 6 months ago UpdateSettingsCategoriesCommandHandler.php 2 weeks ago UpdateSettingsCommand.php 1 year ago UpdateSettingsCommandHandler.php 2 weeks ago
GetSettingsCommandHandler.php
86 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\Services\Settings\SettingsService;
10 use AmeliaBooking\Infrastructure\Services\Mailchimp\AbstractMailchimpService;
11 use AmeliaBooking\Infrastructure\WP\Integrations\IvyForms\IvyFormsService;
12 use AmeliaVendor\Melograno\UsageTracker\Core\UsageTracker;
13 use Interop\Container\Exception\ContainerException;
14 use AmeliaVendor\Melograno\UsageTracker\Collectors\Plugin\AmeliaCollector;
15
16 /**
17 * Class GetSettingsCommandHandler
18 *
19 * @package AmeliaBooking\Application\Commands\Settings
20 */
21 class GetSettingsCommandHandler extends CommandHandler
22 {
23 /**
24 * @return CommandResult
25 * @throws ContainerException
26 * @throws AccessDeniedException
27 */
28 public function handle(GetSettingsCommand $command)
29 {
30 $result = new CommandResult();
31
32 if (!$command->getPermissionService()->currentUserCanRead(Entities::SETTINGS)) {
33 throw new AccessDeniedException('You are not allowed to read settings.');
34 }
35
36 /** @var SettingsService $settingsService */
37 $settingsService = $this->getContainer()->get('domain.settings.service');
38
39 $settings = $settingsService->getAllSettingsCategorized();
40
41 if ($settings['activation']['purchaseCodeStore'] !== '' && $settings['activation']['active']) {
42 $settings['activation']['purchaseCodeStore'] = null;
43 }
44
45 if (!empty($settings['payments']['square'])) {
46 $settings['payments']['square']['phpVersion'] = phpversion();
47 }
48
49 $mailchimpLists = [];
50 if ($settingsService->isFeatureEnabled('mailchimp') && !empty($settings['mailchimp']['accessToken'])) {
51 /** @var AbstractMailchimpService $mailchimpService */
52 $mailchimpService = $this->getContainer()->get('infrastructure.mailchimp.service');
53 $mailchimpLists = $mailchimpService->getLists();
54 if (!empty($mailchimpLists)) {
55 if (!$settings['mailchimp']['list']) {
56 $settings['mailchimp']['list'] = $mailchimpLists[0]['id'];
57 $settingsService->setCategorySettings('mailchimp', $settings['mailchimp']);
58 }
59 }
60 }
61
62 $result->setResult(CommandResult::RESULT_SUCCESS);
63 $result->setMessage('Successfully retrieved settings.');
64
65 if (isset($settings['general'])) {
66 $settings['general'] = array_merge($settings['general'], UsageTracker::getSettings(new AmeliaCollector()));
67 }
68
69 $settings = apply_filters('amelia_get_settings_filter', $settings);
70
71 do_action('amelia_get_settings', $settings);
72
73 $result->setData(
74 [
75 'settings' => $settings,
76 'additionalData' => [
77 'mailchimpLists' => $mailchimpLists,
78 'ivyForms' => IvyFormsService::getForms(),
79 ]
80 ]
81 );
82
83 return $result;
84 }
85 }
86