diff --git a/CRM/TwingleCampaign/BAO/Configuration.php b/CRM/TwingleCampaign/BAO/Configuration.php new file mode 100644 index 0000000..bd51b20 --- /dev/null +++ b/CRM/TwingleCampaign/BAO/Configuration.php @@ -0,0 +1,60 @@ + value for the setting + */ + public static function set(array $settings) { + Civi::settings()->add($settings); + } + + + /** + * Returns a specific value of a setting if the key is passed as parameter. + * Else all settings will be returned als associative array. + * + * @param null $key + * The name of the setting or NULL + * + * @return array|mixed|null + */ + public static function get($key = NULL) { + if ($key) { + return Civi::settings()->get($key); + } + else { + $settings = []; + foreach (self::$settingsKeys as $key) { + $settings[$key] = Civi::settings()->get($key); + } + return $settings; + } + } + + + /** + * Delete all settings of the TwingleCampaign extension + */ + public static function deleteAll() { + foreach (self::$settingsKeys as $key) { + Civi::settings()->set($key, NULL); + } + } + +} \ No newline at end of file diff --git a/CRM/TwingleCampaign/Form/Settings.php b/CRM/TwingleCampaign/Form/Settings.php index 2a6cd2e..71a9033 100644 --- a/CRM/TwingleCampaign/Form/Settings.php +++ b/CRM/TwingleCampaign/Form/Settings.php @@ -1,7 +1,10 @@ get('twingle_api_key'); - $defaultValues['twinglecampaign_xcm_profile'] = - Civi::settings()->get('twinglecampaign_xcm_profile'); - $defaultValues['twinglecampaign_start_case'] = - Civi::settings()->get('twinglecampaign_start_case'); - return $defaultValues; + return Configuration::get(); } //TODO: validate Twingle API key public function postProcess() { - $values = $this->exportValues(); - Civi::settings()->set('twingle_api_key', $values['twingle_api_key']); - Civi::settings() - ->set('twinglecampaign_xcm_profile', $values['twinglecampaign_xcm_profile']); - Civi::settings() - ->set('twinglecampaign_start_case', $values['twinglecampaign_start_case']); + Configuration::set($this->exportValues()); parent::postProcess(); }