diff --git a/app/Controllers/Config.php b/app/Controllers/Config.php index 4a7e6e42d..2405860e4 100644 --- a/app/Controllers/Config.php +++ b/app/Controllers/Config.php @@ -3,7 +3,6 @@ namespace App\Controllers; use App\Libraries\Barcode_lib; -use App\Libraries\Mailchimp_lib; use App\Libraries\Receiving_lib; use App\Libraries\Sale_lib; use App\Libraries\Tax_lib; @@ -287,7 +286,6 @@ class Config extends Secure_Controller return $this->response->setJSON(['success' => $success, 'message' => $message]); } - /** * @return array */ @@ -536,45 +534,6 @@ class Config extends Secure_Controller return $this->response->setJSON(['success' => $success, 'message' => lang('Config.saved_' . ($success ? '' : 'un') . 'successfully')]); } - /** - * This function fetches all the available lists from Mailchimp for the given API key - */ - private function _mailchimp(string $api_key = ''): array // TODO: Hungarian notation - { - $mailchimp_lib = new Mailchimp_lib(['api_key' => $api_key]); - - $result = []; - - $lists = $mailchimp_lib->getLists(); - if ($lists !== false) { - if (is_array($lists) && !empty($lists['lists']) && is_array($lists['lists'])) { - foreach ($lists['lists'] as $list) { - $result[$list['id']] = $list['name'] . ' [' . $list['stats']['member_count'] . ']'; - } - } - } - - return $result; - } - - /** - * Gets Mailchimp lists when a valid API key is inserted. Used in app/Views/configs/integrations_config.php - * - * @return ResponseInterface - * @noinspection PhpUnused - */ - public function postCheckMailchimpApiKey(): ResponseInterface - { - $lists = $this->_mailchimp($this->request->getPost('mailchimp_api_key')); - $success = count($lists) > 0; - - return $this->response->setJSON([ - 'success' => $success, - 'message' => lang('Config.mailchimp_key_' . ($success ? '' : 'un') . 'successfully'), - 'mailchimp_lists' => $lists - ]); - } - /** * Gets all stock locations. Used in app/Views/configs/stock_config.php * diff --git a/app/Controllers/Secure_Controller.php b/app/Controllers/Secure_Controller.php index 2e6affc44..82381f479 100644 --- a/app/Controllers/Secure_Controller.php +++ b/app/Controllers/Secure_Controller.php @@ -99,10 +99,10 @@ class Secure_Controller extends BaseController } /** - * @param $key + * @param string $key * @return mixed|void */ - public function getConfig($key) + public function getConfig(string $key) { if (isset($config[$key])) { return $config[$key]; diff --git a/app/Plugins/MailchimpPlugin.php b/app/Plugins/MailchimpPlugin.php index 24cd4919c..1b22a12e1 100644 --- a/app/Plugins/MailchimpPlugin.php +++ b/app/Plugins/MailchimpPlugin.php @@ -5,6 +5,7 @@ namespace App\Plugins; use App\Libraries\Plugins\BasePlugin; use App\Libraries\Mailchimp_lib; use CodeIgniter\Events\Events; +use CodeIgniter\HTTP\ResponseInterface; use Config\Services; use Exception; @@ -163,6 +164,45 @@ class MailchimpPlugin extends BasePlugin return $this->mailchimpLib; } + /** + * Gets Mailchimp lists when a valid API key is inserted. Used in app/Views/configs/integrations_config.php + * + * @return ResponseInterface + * @noinspection PhpUnused + */ + public function postCheckMailchimpApiKey(): ResponseInterface + { + $lists = $this->_mailchimp($this->request->getPost('mailchimp_api_key')); + $success = count($lists) > 0; + + return $this->response->setJSON([ + 'success' => $success, + 'message' => lang('Config.mailchimp_key_' . ($success ? '' : 'un') . 'successfully'), + 'mailchimp_lists' => $lists + ]); + } + + /** + * This function fetches all the available lists from Mailchimp for the given API key + */ + private function _mailchimp(string $api_key = ''): array // TODO: Hungarian notation + { + $mailchimp_lib = new Mailchimp_lib(['api_key' => $api_key]); + + $result = []; + + $lists = $mailchimp_lib->getLists(); + if ($lists !== false) { + if (is_array($lists) && !empty($lists['lists']) && is_array($lists['lists'])) { + foreach ($lists['lists'] as $list) { + $result[$list['id']] = $list['name'] . ' [' . $list['stats']['member_count'] . ']'; + } + } + } + + return $result; + } + public function testConnection(): array { $apiKey = $this->getSetting('api_key'); diff --git a/app/Plugins/MailchimpPlugin/Views/config.php b/app/Plugins/MailchimpPlugin/Views/config.php index a2cd42892..873c2b824 100644 --- a/app/Plugins/MailchimpPlugin/Views/config.php +++ b/app/Plugins/MailchimpPlugin/Views/config.php @@ -1,6 +1,6 @@ @@ -24,7 +24,7 @@ 'name' => 'mailchimp_api_key', 'id' => 'mailchimp_api_key', 'class' => 'form-control input-sm', - 'value' => $mailchimp['api_key'] + 'value' => esc($settings['api_key'] ?? '') ]) ?> @@ -46,8 +46,8 @@ diff --git a/app/Views/configs/integrations_config.php b/app/Views/configs/integrations_config.php index ea5881643..3f4008677 100644 --- a/app/Views/configs/integrations_config.php +++ b/app/Views/configs/integrations_config.php @@ -1,108 +1,9 @@ 'mailchimp_config_form', 'enctype' => 'multipart/form-data', 'class' => 'form-horizontal']) ?> -
-
- -
-
- - -
- 'control-label col-xs-2']) ?> -
-
- - - - 'mailchimp_api_key', - 'id' => 'mailchimp_api_key', - 'class' => 'form-control input-sm', - 'value' => $mailchimp['api_key'] - ]) ?> -
-
-
- -
-
- -
- 'control-label col-xs-2']) ?> -
-
- - - - -
-
-
- - 'submit_mailchimp', - 'id' => 'submit_mailchimp', - 'value' => lang('Common.submit'), - 'class' => 'btn btn-primary btn-sm pull-right' - ]) ?> - -
-
+ - -