make soft credits optional

This commit is contained in:
Marc Michalsky forumZFD 2021-03-04 17:55:19 +01:00
parent 6cac4882b5
commit db15d5deb1
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
4 changed files with 26 additions and 3 deletions

View file

@ -7,6 +7,7 @@ class CRM_TwingleCampaign_BAO_Configuration {
'twingle_api_key', 'twingle_api_key',
'twinglecampaign_xcm_profile', 'twinglecampaign_xcm_profile',
'twinglecampaign_start_case', 'twinglecampaign_start_case',
'twinglecampaign_soft_credits'
]; ];
@ -17,13 +18,19 @@ class CRM_TwingleCampaign_BAO_Configuration {
* Expects an array with key => value for the setting * Expects an array with key => value for the setting
*/ */
public static function set(array $settings) { public static function set(array $settings) {
// Set twinglecampaign_soft_credits to '0' if checkbox is unchecked
if (!array_key_exists('twinglecampaign_soft_credits', $settings)) {
Civi::settings()->set('twinglecampaign_soft_credits', 0);
}
Civi::settings()->add($settings); Civi::settings()->add($settings);
} }
/** /**
* Returns a specific value of a setting if the key is passed as parameter. * Returns a specific value of a setting if the key is passed as parameter.
* Else all settings will be returned als associative array. * Else all settings will be returned as associative array.
* *
* @param null $key * @param null $key
* The name of the setting or NULL * The name of the setting or NULL
@ -31,7 +38,7 @@ class CRM_TwingleCampaign_BAO_Configuration {
* @return array|mixed|null * @return array|mixed|null
*/ */
public static function get($key = NULL) { public static function get($key = NULL) {
if ($key) { if (!is_null($key)) {
return Civi::settings()->get($key); return Civi::settings()->get($key);
} }
else { else {

View file

@ -35,6 +35,13 @@ class CRM_TwingleCampaign_Form_Settings extends CRM_Core_Form {
['class' => 'crm-select2 huge'] ['class' => 'crm-select2 huge']
); );
$this->addElement(
'checkbox',
'twinglecampaign_soft_credits',
E::ts('Create soft credits for event initiators'),
FALSE
);
$this->addButtons([ $this->addButtons([
[ [
'type' => 'submit', 'type' => 'submit',

View file

@ -1,6 +1,7 @@
<?php <?php
use CRM_TwingleCampaign_ExtensionUtil as E; use CRM_TwingleCampaign_ExtensionUtil as E;
use CRM_TwingleCampaign_BAO_Configuration as Configuration;
/** /**
* # APIWrapper class for TwingleDonation.submit * # APIWrapper class for TwingleDonation.submit
@ -31,7 +32,10 @@ class CRM_TwingleCampaign_Utils_APIWrapper {
*/ */
public static function RESPOND($event) { public static function RESPOND($event) {
$request = $event->getApiRequestSig(); $request = $event->getApiRequestSig();
if ($request == '3.twingledonation.submit') { if (
$request == '3.twingledonation.submit' &&
Configuration::get('twinglecampaign_soft_credits')
) {
$response = $event->getResponse(); $response = $event->getResponse();

View file

@ -21,6 +21,11 @@
<div class="content">{$form.twinglecampaign_start_case.html}</div> <div class="content">{$form.twinglecampaign_start_case.html}</div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<div class="crm-section">
<div class="label">{$form.twinglecampaign_soft_credits.label}</div>
<div class="content">{$form.twinglecampaign_soft_credits.html}</div>
<div class="clear"></div>
</div>
</div> </div>