From 4ff060884a0ab72e3f09306223b6f6a1c738fd0e Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Fri, 24 Jul 2020 10:57:14 +0200 Subject: [PATCH 01/10] implement CiviCRM's double opt-in feature for newsletter --- CRM/Twingle/Form/Profile.php | 43 +++++++++++++++++++------- CRM/Twingle/Profile.php | 2 ++ README.md | 3 +- api/v3/TwingleDonation/Submit.php | 23 +++++++++++++- l10n/de_DE/LC_MESSAGES/twingle.po | 4 +++ templates/CRM/Twingle/Form/Profile.tpl | 5 +++ 6 files changed, 67 insertions(+), 13 deletions(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index a38dc7e..5f18715 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -327,11 +327,19 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { ); } + $this->add( + 'checkbox', // field type + 'double_opt_in', // field name + E::ts('Use Double-Opt-In for newsletter'), // field label + FALSE, // is not required + array() + ); + $this->add( 'select', // field type 'newsletter_groups', // field name E::ts('Sign up for newsletter groups'), // field label - static::getNewsletterGroups(), // list of options + static::getNewsletterGroups($this->profile->getAttribute('double_opt_in')), // list of options FALSE, // is not required array('class' => 'crm-select2 huge', 'multiple' => 'multiple') ); @@ -548,6 +556,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { $values['name'] = 'default'; } $this->profile->setName($values['name']); + $this->profile->setAttribute('double_opt_in', isset($values['double_opt_in'])); foreach ($this->profile->getData() as $element_name => $value) { if (isset($values[$element_name])) { $this->profile->setAttribute($element_name, $values[$element_name]); @@ -791,15 +800,16 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { return self::$_contributionStatusOptions; } - /** - * Retrieves active groups used as mailing lists within the system as options - * for select form elements. - * - * @return array - * - * @throws \CiviCRM_API3_Exception - */ - public static function getNewsletterGroups() { + /** + * Retrieves active groups used as mailing lists within the system as options + * for select form elements. + * + * @param $double_opt_in + * + * @return array + * + */ + public static function getNewsletterGroups($double_opt_in) { if (!isset(static::$_newsletterGroups)) { static::$_newsletterGroups = array(); $group_types = civicrm_api3('OptionValue', 'get', array( @@ -807,7 +817,18 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { 'option_group_id' => 'group_type', 'name' => CRM_Twingle_Submission::GROUP_TYPE_NEWSLETTER, )); - if ($group_types['count'] > 0) { + if ($group_types['count'] > 0 && $double_opt_in) { + $query = civicrm_api3('Group', 'get', array( + 'is_active' => 1, + 'group_type' => "Mailing List", + 'option.limit' => 0, + 'visibility' => 'Public Pages', + 'return' => 'id,name' + )); + foreach ($query['values'] as $group) { + static::$_newsletterGroups[$group['id']] = $group['name']; + } + } elseif ($group_types['count'] > 0) { $group_type = reset($group_types['values']); $query = civicrm_api3('Group', 'get', array( 'is_active' => 1, diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index be93bc6..e0afe35 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -221,6 +221,7 @@ class CRM_Twingle_Profile { 'membership_type_id', 'membership_type_id_recur', 'membership_postprocess_call', + 'double_opt_in' ), // Add payment methods. array_keys(static::paymentInstruments()), @@ -293,6 +294,7 @@ class CRM_Twingle_Profile { 'custom_field_mapping' => NULL, 'membership_type_id' => NULL, 'membership_type_id_recur' => NULL, + 'double_opt_in' => NULL, ) // Add contribution status for all payment methods. + array_fill_keys(array_map(function($attribute) { diff --git a/README.md b/README.md index e8c2a1d..b1b7409 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ for all newly created Twingle projects. | CiviSEPA creditor | When enabled to integrate with CiviSEPA, specify the CiviSEPA creditor to use. | | Gender options | Specify which CiviCRM gender option the incoming Twingle gender value should be mapped to. The list is based on your CiviCRM configuration. | | Record *Payment method* as | Specifiy the payment methods mapping for incoming donations for each Twingle payment method. | +| Double opt-In | Let CiviCRM handle the double opt-in. Group memberships for newsletter mailing lists will be pending until receivement of double opt-in confirmataion. | | Sign up for groups | Whenever the donor checked the newsletter/postal mailing/donation receipt checkbox on the Twingle form, the contact will be added to the groups listed here. | | Assign donation to campaign | The donation will be assigned to the selected campaign. If a campaign ID is being submitted using the `campaign_id` parameter, this setting will be overridden with the submitted value. | | Create membership of type | A membership of the selected type will be created for the Individual contact for incoming one-time donations. If no membership type is selected, no membership will be created. | @@ -147,4 +148,4 @@ The action accepts the following parameters: You may also refer to [the code](https://github.com/systopia/de.systopia.twingle/blob/master/api/v3/TwingleDonation/Cancel.php) -for more insight into this API action. +for more insight into this API action. \ No newline at end of file diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index afa3ca3..d0f9061 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -484,8 +484,29 @@ function civicrm_api3_twingle_donation_Submit($params) { $result_values['organization'] = $organisation_id; } + // If usage of double opt-in is selected, use MailingEventSubscribe.create to add contact to newsletter groups + // defined in the profile + $result_values['newsletter']['double_opt_in'] = ($profile->getAttribute('double_opt_in')) ? 'true' : 'false'; + if ($profile->getAttribute('double_opt_in') && + !empty($params['newsletter']) && + !empty($groups = $profile->getAttribute('newsletter_groups'))) { + $group_memberships = array_column(civicrm_api3('GroupContact', 'get', array ( + 'sequential' => 1, + 'contact_id' => $contact_id + ))['values'], 'group_id'); + foreach ($groups as $group_id) { + if (!in_array($group_id, $group_memberships)) { + $result_values['newsletter'][][$group_id] = civicrm_api3('MailingEventSubscribe', 'create', array( + 'email' => $params['user_email'], + 'group_id' => (int) $group_id, + 'contact_id' => $contact_id, + )); + } else { + $result_values['newsletter'][] = $group_id; + } + } // If requested, add contact to newsletter groups defined in the profile. - if (!empty($params['newsletter']) && !empty($groups = $profile->getAttribute('newsletter_groups'))) { + } elseif (!empty($params['newsletter']) && !empty($groups = $profile->getAttribute('newsletter_groups'))) { foreach ($groups as $group_id) { civicrm_api3('GroupContact', 'create', array( 'group_id' => $group_id, diff --git a/l10n/de_DE/LC_MESSAGES/twingle.po b/l10n/de_DE/LC_MESSAGES/twingle.po index f914552..921eedb 100644 --- a/l10n/de_DE/LC_MESSAGES/twingle.po +++ b/l10n/de_DE/LC_MESSAGES/twingle.po @@ -306,3 +306,7 @@ msgstr "Profil %1 zurücksetzen" #: templates/CRM/Twingle/Page/Profiles.tpl msgid "Delete profile %1" msgstr "Profil % 1 löschen" + +#: templates/CRM/Twingle/Page/Profiles.tpl +msgid "Use Double-Opt-In for newsletter" +msgstr "Nutze Double-Opt-In für Newsletter" diff --git a/templates/CRM/Twingle/Form/Profile.tpl b/templates/CRM/Twingle/Form/Profile.tpl index 708cb5a..3e6a07e 100644 --- a/templates/CRM/Twingle/Form/Profile.tpl +++ b/templates/CRM/Twingle/Form/Profile.tpl @@ -208,6 +208,11 @@ + + + + + From d3c1aabfb4bb8d01eebf93262c8595113e4779e7 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Fri, 14 Aug 2020 10:13:51 +0200 Subject: [PATCH 02/10] [#36] Rename "double_opt_in" property to "newsletter_double_opt_in" --- CRM/Twingle/Form/Profile.php | 6 +++--- CRM/Twingle/Profile.php | 4 ++-- api/v3/TwingleDonation/Submit.php | 4 ++-- templates/CRM/Twingle/Form/Profile.tpl | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 5f18715..3491125 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -329,7 +329,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { $this->add( 'checkbox', // field type - 'double_opt_in', // field name + 'newsletter_double_opt_in', // field name E::ts('Use Double-Opt-In for newsletter'), // field label FALSE, // is not required array() @@ -339,7 +339,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { 'select', // field type 'newsletter_groups', // field name E::ts('Sign up for newsletter groups'), // field label - static::getNewsletterGroups($this->profile->getAttribute('double_opt_in')), // list of options + static::getNewsletterGroups($this->profile->getAttribute('newsletter_double_opt_in')), // list of options FALSE, // is not required array('class' => 'crm-select2 huge', 'multiple' => 'multiple') ); @@ -556,7 +556,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { $values['name'] = 'default'; } $this->profile->setName($values['name']); - $this->profile->setAttribute('double_opt_in', isset($values['double_opt_in'])); + $this->profile->setAttribute('newsletter_double_opt_in', isset($values['newsletter_double_opt_in'])); foreach ($this->profile->getData() as $element_name => $value) { if (isset($values[$element_name])) { $this->profile->setAttribute($element_name, $values[$element_name]); diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index e0afe35..9c86f1a 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -221,7 +221,7 @@ class CRM_Twingle_Profile { 'membership_type_id', 'membership_type_id_recur', 'membership_postprocess_call', - 'double_opt_in' + 'newsletter_double_opt_in' ), // Add payment methods. array_keys(static::paymentInstruments()), @@ -294,7 +294,7 @@ class CRM_Twingle_Profile { 'custom_field_mapping' => NULL, 'membership_type_id' => NULL, 'membership_type_id_recur' => NULL, - 'double_opt_in' => NULL, + 'newsletter_double_opt_in' => NULL, ) // Add contribution status for all payment methods. + array_fill_keys(array_map(function($attribute) { diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index d0f9061..19217b6 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -486,8 +486,8 @@ function civicrm_api3_twingle_donation_Submit($params) { // If usage of double opt-in is selected, use MailingEventSubscribe.create to add contact to newsletter groups // defined in the profile - $result_values['newsletter']['double_opt_in'] = ($profile->getAttribute('double_opt_in')) ? 'true' : 'false'; - if ($profile->getAttribute('double_opt_in') && + $result_values['newsletter']['newsletter_double_opt_in'] = ($profile->getAttribute('newsletter_double_opt_in')) ? 'true' : 'false'; + if ($profile->getAttribute('newsletter_double_opt_in') && !empty($params['newsletter']) && !empty($groups = $profile->getAttribute('newsletter_groups'))) { $group_memberships = array_column(civicrm_api3('GroupContact', 'get', array ( diff --git a/templates/CRM/Twingle/Form/Profile.tpl b/templates/CRM/Twingle/Form/Profile.tpl index 3e6a07e..83dc4cb 100644 --- a/templates/CRM/Twingle/Form/Profile.tpl +++ b/templates/CRM/Twingle/Form/Profile.tpl @@ -209,13 +209,13 @@
{$form.double_opt_in.label}{$form.double_opt_in.html}
{$form.newsletter_groups.label} {$form.newsletter_groups.html}
- - + + - - + + From 11558d4fbd93603c707f2133d3bf7cf840f9393b Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Fri, 14 Aug 2020 10:19:54 +0200 Subject: [PATCH 03/10] [#36] Save newsletter_double_opt_in property as integer --- CRM/Twingle/Form/Profile.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 3491125..046df2f 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -556,8 +556,10 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { $values['name'] = 'default'; } $this->profile->setName($values['name']); - $this->profile->setAttribute('newsletter_double_opt_in', isset($values['newsletter_double_opt_in'])); foreach ($this->profile->getData() as $element_name => $value) { + if ($element_name == 'newsletter_double_opt_in') { + $values[$element_name] = (int) isset($values[$element_name]); + } if (isset($values[$element_name])) { $this->profile->setAttribute($element_name, $values[$element_name]); } From 94cc262c2170ee74881d474ed8f901ed53bd6b1a Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Fri, 14 Aug 2020 10:25:04 +0200 Subject: [PATCH 04/10] [#36] Add help text for the Newsletter Double-Opt-In setting --- templates/CRM/Twingle/Form/Profile.hlp | 4 ++++ templates/CRM/Twingle/Form/Profile.tpl | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/templates/CRM/Twingle/Form/Profile.hlp b/templates/CRM/Twingle/Form/Profile.hlp index 8a89223..12136cb 100644 --- a/templates/CRM/Twingle/Form/Profile.hlp +++ b/templates/CRM/Twingle/Form/Profile.hlp @@ -38,6 +38,10 @@ {ts domain="de.systopia.twingle"}Select which financial type to use for recurring contributions.{/ts} {/htxt} +{htxt id='id-newsletter-double-opt-in'} + {ts domain="de.systopia.twingle"}Select whether to use CiviCRM's Double-Opt-In feature for subscribing to mailing lists. Note that this only works for public mailing lists. Any non-public mailing list selected above will be ignored when this setting is enabled.{/ts} +{/htxt} + {htxt id='id-membership-postprocessing-call'} {ts domain="de.systopia.twingle"}Some organisations have specific conventions on how a membership should be created. Since the Twingle-API can only create a "bare bone" membership object, you can enter a API Call (as 'Entity.Action') to adjust any newly created membership to your organisation's needs.{/ts} {ts domain="de.systopia.twingle"}The API call would receive the following parameters:
    diff --git a/templates/CRM/Twingle/Form/Profile.tpl b/templates/CRM/Twingle/Form/Profile.tpl index 83dc4cb..ec51647 100644 --- a/templates/CRM/Twingle/Form/Profile.tpl +++ b/templates/CRM/Twingle/Form/Profile.tpl @@ -214,7 +214,24 @@
- + From 3553ed83b93fab896190db36eb391512e4237ae0 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Fri, 14 Aug 2020 10:33:00 +0200 Subject: [PATCH 05/10] [#36] Do not alter the mailing lists available for the profile field since that might be confusing and still produce invalid states --- CRM/Twingle/Form/Profile.php | 17 ++----- api/v3/TwingleDonation/Submit.php | 77 ++++++++++++++++++++----------- 2 files changed, 53 insertions(+), 41 deletions(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 046df2f..9c69f6b 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -339,7 +339,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { 'select', // field type 'newsletter_groups', // field name E::ts('Sign up for newsletter groups'), // field label - static::getNewsletterGroups($this->profile->getAttribute('newsletter_double_opt_in')), // list of options + static::getNewsletterGroups(), // list of options FALSE, // is not required array('class' => 'crm-select2 huge', 'multiple' => 'multiple') ); @@ -811,7 +811,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { * @return array * */ - public static function getNewsletterGroups($double_opt_in) { + public static function getNewsletterGroups() { if (!isset(static::$_newsletterGroups)) { static::$_newsletterGroups = array(); $group_types = civicrm_api3('OptionValue', 'get', array( @@ -819,18 +819,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { 'option_group_id' => 'group_type', 'name' => CRM_Twingle_Submission::GROUP_TYPE_NEWSLETTER, )); - if ($group_types['count'] > 0 && $double_opt_in) { - $query = civicrm_api3('Group', 'get', array( - 'is_active' => 1, - 'group_type' => "Mailing List", - 'option.limit' => 0, - 'visibility' => 'Public Pages', - 'return' => 'id,name' - )); - foreach ($query['values'] as $group) { - static::$_newsletterGroups[$group['id']] = $group['name']; - } - } elseif ($group_types['count'] > 0) { + if ($group_types['count'] > 0) { $group_type = reset($group_types['values']); $query = civicrm_api3('Group', 'get', array( 'is_active' => 1, diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index 19217b6..d8577e6 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -484,34 +484,57 @@ function civicrm_api3_twingle_donation_Submit($params) { $result_values['organization'] = $organisation_id; } - // If usage of double opt-in is selected, use MailingEventSubscribe.create to add contact to newsletter groups - // defined in the profile - $result_values['newsletter']['newsletter_double_opt_in'] = ($profile->getAttribute('newsletter_double_opt_in')) ? 'true' : 'false'; - if ($profile->getAttribute('newsletter_double_opt_in') && - !empty($params['newsletter']) && - !empty($groups = $profile->getAttribute('newsletter_groups'))) { - $group_memberships = array_column(civicrm_api3('GroupContact', 'get', array ( - 'sequential' => 1, - 'contact_id' => $contact_id - ))['values'], 'group_id'); - foreach ($groups as $group_id) { - if (!in_array($group_id, $group_memberships)) { - $result_values['newsletter'][][$group_id] = civicrm_api3('MailingEventSubscribe', 'create', array( - 'email' => $params['user_email'], - 'group_id' => (int) $group_id, - 'contact_id' => $contact_id, - )); - } else { - $result_values['newsletter'][] = $group_id; - } - } - // If requested, add contact to newsletter groups defined in the profile. - } elseif (!empty($params['newsletter']) && !empty($groups = $profile->getAttribute('newsletter_groups'))) { + // If usage of double opt-in is selected, use MailingEventSubscribe.create + // to add contact to newsletter groups defined in the profile + $result_values['newsletter']['newsletter_double_opt_in'] = ($profile->getAttribute('newsletter_double_opt_in')) ? 'true' : 'false'; + if ( + $profile->getAttribute('newsletter_double_opt_in') && + !empty($params['newsletter']) && + !empty($groups = $profile->getAttribute('newsletter_groups')) + ) { + $group_memberships = array_column( + civicrm_api3( + 'GroupContact', + 'get', + array( + 'sequential' => 1, + 'contact_id' => $contact_id, + ) + )['values'], + 'group_id' + ); + // TODO: Filter for public mailing list groups? foreach ($groups as $group_id) { - civicrm_api3('GroupContact', 'create', array( - 'group_id' => $group_id, - 'contact_id' => $contact_id, - )); + if (!in_array($group_id, $group_memberships)) { + $result_values['newsletter'][][$group_id] = civicrm_api3( + 'MailingEventSubscribe', + 'create', + array( + 'email' => $params['user_email'], + 'group_id' => (int) $group_id, + 'contact_id' => $contact_id, + ) + ); + } + else { + $result_values['newsletter'][] = $group_id; + } + } + // If requested, add contact to newsletter groups defined in the profile. + } + elseif ( + !empty($params['newsletter']) + && !empty($groups = $profile->getAttribute('newsletter_groups')) + ) { + foreach ($groups as $group_id) { + civicrm_api3( + 'GroupContact', + 'create', + array( + 'group_id' => $group_id, + 'contact_id' => $contact_id, + ) + ); $result_values['newsletter'][] = $group_id; } From 6b42c72bf8ef25c720234c35973bf46500035e4a Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Fri, 14 Aug 2020 10:43:06 +0200 Subject: [PATCH 06/10] [#36] Fix indentation --- CRM/Twingle/Form/Profile.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 9c69f6b..90241c2 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -802,15 +802,15 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { return self::$_contributionStatusOptions; } - /** - * Retrieves active groups used as mailing lists within the system as options - * for select form elements. - * - * @param $double_opt_in - * - * @return array - * - */ + /** + * Retrieves active groups used as mailing lists within the system as options + * for select form elements. + * + * @param $double_opt_in + * + * @return array + * + */ public static function getNewsletterGroups() { if (!isset(static::$_newsletterGroups)) { static::$_newsletterGroups = array(); @@ -819,7 +819,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { 'option_group_id' => 'group_type', 'name' => CRM_Twingle_Submission::GROUP_TYPE_NEWSLETTER, )); - if ($group_types['count'] > 0) { + if ($group_types['count'] > 0) { $group_type = reset($group_types['values']); $query = civicrm_api3('Group', 'get', array( 'is_active' => 1, From 021cd5257b5f958c85d1aee00aece78cce63c381 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Fri, 14 Aug 2020 10:48:50 +0200 Subject: [PATCH 07/10] [#36] Fix PHPDoc --- CRM/Twingle/Form/Profile.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 90241c2..be9dd27 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -806,10 +806,10 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { * Retrieves active groups used as mailing lists within the system as options * for select form elements. * - * @param $double_opt_in - * * @return array * + * @throws \CiviCRM_API3_Exception + * */ public static function getNewsletterGroups() { if (!isset(static::$_newsletterGroups)) { From d140bd9ed7e633c3ccea0d3de50f62363d9cc2a5 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Tue, 18 Aug 2020 14:15:59 +0200 Subject: [PATCH 08/10] filter out non-public groups non-public groups are getting ignored --- api/v3/TwingleDonation/Submit.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index d8577e6..984fa9a 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -503,9 +503,15 @@ function civicrm_api3_twingle_donation_Submit($params) { )['values'], 'group_id' ); - // TODO: Filter for public mailing list groups? foreach ($groups as $group_id) { - if (!in_array($group_id, $group_memberships)) { + $is_public_group = civicrm_api3( + 'Group', + 'getsingle', + array( + 'id' => (int) $group_id, + ) + )['visibility'] == 'Public Pages'; + if (!in_array($group_id, $group_memberships) && $is_public_group) { $result_values['newsletter'][][$group_id] = civicrm_api3( 'MailingEventSubscribe', 'create', @@ -516,7 +522,7 @@ function civicrm_api3_twingle_donation_Submit($params) { ) ); } - else { + elseif ($is_public_group) { $result_values['newsletter'][] = $group_id; } } From d7e42035c8a6b21d70bd9c9e8b191dfab633b77d Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Tue, 18 Aug 2020 15:00:18 +0200 Subject: [PATCH 09/10] updated double opt-in description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1b7409..c338dce 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ for all newly created Twingle projects. | CiviSEPA creditor | When enabled to integrate with CiviSEPA, specify the CiviSEPA creditor to use. | | Gender options | Specify which CiviCRM gender option the incoming Twingle gender value should be mapped to. The list is based on your CiviCRM configuration. | | Record *Payment method* as | Specifiy the payment methods mapping for incoming donations for each Twingle payment method. | -| Double opt-In | Let CiviCRM handle the double opt-in. Group memberships for newsletter mailing lists will be pending until receivement of double opt-in confirmataion. | +| Double Opt-In | Let CiviCRM handle the double opt-in. Group memberships for newsletter mailing lists stay pending until the subscription gets confirmed. Note that this only works for public mailing lists. Any non-public mailing lists will be ignored. Do not forget to disable Twingle's double opt-in option in the Twingle Manager. | | Sign up for groups | Whenever the donor checked the newsletter/postal mailing/donation receipt checkbox on the Twingle form, the contact will be added to the groups listed here. | | Assign donation to campaign | The donation will be assigned to the selected campaign. If a campaign ID is being submitted using the `campaign_id` parameter, this setting will be overridden with the submitted value. | | Create membership of type | A membership of the selected type will be created for the Individual contact for incoming one-time donations. If no membership type is selected, no membership will be created. | From a65e98509a5203033b460f9f4dc40ca0c577d6e7 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Wed, 19 Aug 2020 12:27:46 +0200 Subject: [PATCH 10/10] [#36] Improve help text on Double Opt-In option --- README.md | 36 +++++++++++++------------- templates/CRM/Twingle/Form/Profile.hlp | 3 ++- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index c338dce..bb52ecd 100644 --- a/README.md +++ b/README.md @@ -43,24 +43,24 @@ The *default* profile is used whenever the plugin cannot match the Twingle project ID from any other profile. Therefore the default profile will be used for all newly created Twingle projects. -| Label | Description | -|---------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Profile name | Internal name, used inside the extension. | -| Project IDs | Twingle project IDs. Separate multiple IDs with commas. | -| Location type | Specify how the address data sent by the form should be categorised in CiviCRM. The list is based on your CiviCRM configuration. | -| Location type for organisations | Specify how the address data sent by the form should be categorised in CiviCRM for organisational donations. The list is based on your CiviCRM configuration. | -| Financial type | Specify which financial type incoming one-time donations should be recorded with in CiviCRM. The list is based on your CiviCRM configuration. | -| Financial type (recurring) | Specify which financial type incoming recurring donations should be recorded with in CiviCRM. The list is based on your CiviCRM configuration. | -| CiviSEPA creditor | When enabled to integrate with CiviSEPA, specify the CiviSEPA creditor to use. | -| Gender options | Specify which CiviCRM gender option the incoming Twingle gender value should be mapped to. The list is based on your CiviCRM configuration. | -| Record *Payment method* as | Specifiy the payment methods mapping for incoming donations for each Twingle payment method. | -| Double Opt-In | Let CiviCRM handle the double opt-in. Group memberships for newsletter mailing lists stay pending until the subscription gets confirmed. Note that this only works for public mailing lists. Any non-public mailing lists will be ignored. Do not forget to disable Twingle's double opt-in option in the Twingle Manager. | -| Sign up for groups | Whenever the donor checked the newsletter/postal mailing/donation receipt checkbox on the Twingle form, the contact will be added to the groups listed here. | -| Assign donation to campaign | The donation will be assigned to the selected campaign. If a campaign ID is being submitted using the `campaign_id` parameter, this setting will be overridden with the submitted value. | -| Create membership of type | A membership of the selected type will be created for the Individual contact for incoming one-time donations. If no membership type is selected, no membership will be created. | -| Create membership of type (recurring) | A membership of the selected type will be created for the Individual contact for incoming recurring donations. If no membership type is selected, no membership will be created. | -| Contribution source | The configured value will be set as the "Source" field for the contribution. | -| Custom field mapping | Additional field values may be set to CiviCRM custom fields using a mapping. See the option's help text for the exact format. | +| Label | Description | +|---------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Profile name | Internal name, used inside the extension. | +| Project IDs | Twingle project IDs. Separate multiple IDs with commas. | +| Location type | Specify how the address data sent by the form should be categorised in CiviCRM. The list is based on your CiviCRM configuration. | +| Location type for organisations | Specify how the address data sent by the form should be categorised in CiviCRM for organisational donations. The list is based on your CiviCRM configuration. | +| Financial type | Specify which financial type incoming one-time donations should be recorded with in CiviCRM. The list is based on your CiviCRM configuration. | +| Financial type (recurring) | Specify which financial type incoming recurring donations should be recorded with in CiviCRM. The list is based on your CiviCRM configuration. | +| CiviSEPA creditor | When enabled to integrate with CiviSEPA, specify the CiviSEPA creditor to use. | +| Gender options | Specify which CiviCRM gender option the incoming Twingle gender value should be mapped to. The list is based on your CiviCRM configuration. | +| Record *Payment method* as | Specifiy the payment methods mapping for incoming donations for each Twingle payment method. | +| Double Opt-In | Let CiviCRM handle the double opt-in. Group memberships for newsletter mailing lists stay pending until the subscription gets confirmed. Note that this only works for public mailing lists. Any non-public mailing list will be ignored. Do not forget to disable Twingle's double opt-in option in the Twingle Manager. | +| Sign up for groups | Whenever the donor checked the newsletter/postal mailing/donation receipt checkbox on the Twingle form, the contact will be added to the groups listed here. | +| Assign donation to campaign | The donation will be assigned to the selected campaign. If a campaign ID is being submitted using the `campaign_id` parameter, this setting will be overridden with the submitted value. | +| Create membership of type | A membership of the selected type will be created for the Individual contact for incoming one-time donations. If no membership type is selected, no membership will be created. | +| Create membership of type (recurring) | A membership of the selected type will be created for the Individual contact for incoming recurring donations. If no membership type is selected, no membership will be created. | +| Contribution source | The configured value will be set as the "Source" field for the contribution. | +| Custom field mapping | Additional field values may be set to CiviCRM custom fields using a mapping. See the option's help text for the exact format. | ## API documentation diff --git a/templates/CRM/Twingle/Form/Profile.hlp b/templates/CRM/Twingle/Form/Profile.hlp index 12136cb..bcbe78a 100644 --- a/templates/CRM/Twingle/Form/Profile.hlp +++ b/templates/CRM/Twingle/Form/Profile.hlp @@ -39,7 +39,8 @@ {/htxt} {htxt id='id-newsletter-double-opt-in'} - {ts domain="de.systopia.twingle"}Select whether to use CiviCRM's Double-Opt-In feature for subscribing to mailing lists. Note that this only works for public mailing lists. Any non-public mailing list selected above will be ignored when this setting is enabled.{/ts} +

{ts domain="de.systopia.twingle"}Select whether to use CiviCRM's Double-Opt-In feature for subscribing to mailing lists. Note that this only works for public mailing lists. Any non-public mailing list selected above will be ignored when this setting is enabled.{/ts}

+

{ts domain="de.systopia.twingle"}Also, do not forget to disable Twingle's own Double Opt-In option in the Twingle Manager to avoid subscribers receiving multiple confirmation e-mails. Only one or the other option should be enabled.{/ts}

{/htxt} {htxt id='id-membership-postprocessing-call'}
{$form.double_opt_in.label}{$form.double_opt_in.html}{$form.newsletter_groups.label}{$form.newsletter_groups.html}
{$form.newsletter_groups.label}{$form.newsletter_groups.html}{$form.newsletter_double_opt_in.label}{$form.newsletter_double_opt_in.html}
{$form.newsletter_double_opt_in.label} + {$form.newsletter_double_opt_in.label} + + {$form.newsletter_double_opt_in.html}