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 |