From 10f6ca4e897a89002edb493cc2083765b568a555 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Fri, 26 Apr 2024 18:19:16 +0200 Subject: [PATCH 1/5] add profile settings for note mapping --- CRM/Twingle/Form/Profile.php | 25 +++++++++++++++ CRM/Twingle/Profile.php | 4 +++ templates/CRM/Twingle/Form/Profile.hlp | 12 ++++++- templates/CRM/Twingle/Form/Profile.tpl | 44 ++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index af1832a..d0a1beb 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -498,6 +498,31 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { [] ); + $this->add( + 'select', + 'map_as_contribution_notes', + E::ts('Create contribution notes for'), + [ + 'purpose' => E::ts('Purpose'), + 'remarks' => E::ts('Remarks'), + ], + // is not required + FALSE, + ['class' => 'crm-select2 huge', 'multiple' => 'multiple'] + ); + + $this->add( + 'select', + 'map_as_contact_notes', + E::ts('Create contact notes for'), + [ + 'user_extrafield' => E::ts('User Extra Field'), + ], + // is not required + FALSE, + ['class' => 'crm-select2 huge', 'multiple' => 'multiple'] + ); + $this->addButtons([ [ 'type' => 'submit', diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index 1a150af..0580eeb 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -527,6 +527,8 @@ class CRM_Twingle_Profile { 'membership_postprocess_call' => ['required' => FALSE], 'newsletter_double_opt_in' => ['required' => FALSE], 'required_address_components' => ['required' => FALSE], + 'map_as_contribution_notes' => ['required' => FALSE], + 'map_as_contact_notes' => ['required' => FALSE], ], // Add payment methods. array_combine( @@ -643,6 +645,8 @@ class CRM_Twingle_Profile { 'city', 'country', ], + 'map_as_contribution_notes' => [], + 'map_as_contact_notes' => [], ] // Add contribution status for all payment methods. // phpcs:ignore Drupal.Formatting.SpaceUnaryOperator.PlusMinus diff --git a/templates/CRM/Twingle/Form/Profile.hlp b/templates/CRM/Twingle/Form/Profile.hlp index e3841d7..b8d67a4 100644 --- a/templates/CRM/Twingle/Form/Profile.hlp +++ b/templates/CRM/Twingle/Form/Profile.hlp @@ -75,4 +75,14 @@
  • ContributionRecur – Will be set on the recurring contribution and deriving single contributions
  • {/ts} {/htxt} -{/crmScope} \ No newline at end of file + +{htxt id='id-map_as_contribution_notes'} + {ts domain="de.systopia.twingle"}

    Create a contribution note for each field specified in this selection.

    +

    Tip: You can enable or disable this fields in the TwingleMANAGER.

    {/ts} +{/htxt} + +{htxt id='id-map_as_contact_notes'} + {ts domain="de.systopia.twingle"}

    Create a contact note for each field specified in this selection.

    +

    Tip: You can enable or disable this fields in the TwingleMANAGER.

    {/ts} +{/htxt} +{/crmScope} diff --git a/templates/CRM/Twingle/Form/Profile.tpl b/templates/CRM/Twingle/Form/Profile.tpl index df54418..83accec 100644 --- a/templates/CRM/Twingle/Form/Profile.tpl +++ b/templates/CRM/Twingle/Form/Profile.tpl @@ -313,6 +313,50 @@ {$form.contribution_source.html} + + + {$form.map_as_contribution_notes.label} + + + {$form.map_as_contribution_notes.html} + + + + + {$form.map_as_contact_notes.label} + + + {$form.map_as_contact_notes.html} + + {$form.custom_field_mapping.label} From df51d59ceaad75e8bbb6d435496e1b7a2fd96303 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Fri, 26 Apr 2024 18:19:54 +0200 Subject: [PATCH 2/5] add logic to create selected contact and contribution notes --- api/v3/TwingleDonation/Submit.php | 48 ++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index ecaeac8..2466575 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -255,6 +255,13 @@ function _civicrm_api3_twingle_donation_Submit_spec(&$params) { 'api.required' => 0, 'description' => E::ts('Additional information for either the contact or the (recurring) contribution.'), ]; + $params['remarks'] = [ + 'name' => 'remarks', + 'title' => E::ts('Remarks'), + 'type' => CRM_Utils_Type::T_STRING, + 'api.required' => 0, + 'description' => E::ts('Additional remarks for the donation.'), + ]; } /** @@ -477,13 +484,20 @@ function civicrm_api3_twingle_donation_Submit($params) { ); } - // Save user_extrafield as contact note. - if (isset($params['user_extrafield']) && '' != $params['user_extrafield']) { - civicrm_api3('Note', 'create', [ - 'entity_table' => 'civicrm_contact', - 'entity_id' => $contact_id, - 'note' => $params['user_extrafield'], - ]); + // Create contact notes. + $contact_note_mappings = $profile->getAttribute('map_as_contact_notes', []); + foreach (['user_extrafield'] as $target) { + if ( + isset($params[$target]) + && '' != $params[$target] + && in_array($target, $contact_note_mappings) + ) { + civicrm_api3('Note', 'create', [ + 'entity_table' => 'civicrm_contact', + 'entity_id' => $contact_id, + 'note' => $params[$target], + ]); + } } // Share organisation address with individual contact, using configured @@ -620,10 +634,6 @@ function civicrm_api3_twingle_donation_Submit($params) { $contribution_data += $custom_fields['Contribution']; } - if (isset($params['purpose'])) { - $contribution_data['note'] = $params['purpose']; - } - // set campaign, subject to configuration CRM_Twingle_Submission::setCampaign($contribution_data, 'contribution', $params, $profile); @@ -794,6 +804,22 @@ function civicrm_api3_twingle_donation_Submit($params) { $result_values['contribution'] = $contribution['values']; } + // Add notes to the contribution. + $contribution_note_mappings = $profile->getAttribute("map_as_contribution_notes"); + foreach (['purpose', 'remarks'] as $target) { + if ( + in_array($target, $contribution_note_mappings) + && isset($params[$target]) + && '' != $params[$target] + ) { + civicrm_api3('Note', 'create', [ + 'entity_table' => 'civicrm_contribution', + 'entity_id' => CRM_Utils_Array::first($result_values['contribution'])['id'], + 'note' => $params[$target], + ]); + } + } + // MEMBERSHIP CREATION // CHECK whether a membership should be created (based on profile settings and data provided) From b3f82fbfba2d650128722300ebc0be22221d402f Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Tue, 30 Apr 2024 16:51:39 +0200 Subject: [PATCH 3/5] add Upgrader to maintain profile behaviour --- CRM/Twingle/Upgrader.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/CRM/Twingle/Upgrader.php b/CRM/Twingle/Upgrader.php index 2af4667..4d00514 100644 --- a/CRM/Twingle/Upgrader.php +++ b/CRM/Twingle/Upgrader.php @@ -102,4 +102,40 @@ class CRM_Twingle_Upgrader extends CRM_Extension_Upgrader_Base { return TRUE; } + /** + * Upgrade to 1.5.0 + * + * - Activate mapping of `purpose` and `user_extra_field` to notes in each existing profile to + * maintain default behavior after making the fields optional. + * + * @return bool + * @throws \Civi\Core\Exception\DBQueryException + * @throws \Civi\Twingle\Exceptions\ProfileException + */ + public function upgrade_5150(): bool { + $this->ctx->log->info('Activate mapping of `purpose` and `user_extra_field` to notes in each existing profile.'); + + $profiles = CRM_Twingle_Profile::getProfiles(); + if ($profiles) { + foreach ($profiles as $profile) { + $profile_changed = FALSE; + $contribution_notes = $profile->getAttribute('map_as_contribution_notes', []); + $contact_notes = $profile->getAttribute('map_as_contact_notes', []); + if (!in_array('purpose', $contribution_notes)) { + $profile->setAttribute('map_as_contribution_notes', array_merge($contribution_notes, ['purpose'])); + $profile_changed = TRUE; + } + if (!in_array('user_extrafield', $contact_notes)) { + $profile->setAttribute('map_as_contact_notes', array_merge($contact_notes, ['user_extrafield'])); + $profile_changed = TRUE; + } + if ($profile_changed) { + $profile->saveProfile(); + } + } + } + + return TRUE; + } + } From 63b7e4d3eed502569bef8c437168210e347f051c Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Tue, 30 Apr 2024 15:43:44 +0200 Subject: [PATCH 4/5] add German translations --- l10n/de_DE/LC_MESSAGES/twingle.mo | Bin 6167 -> 7350 bytes l10n/de_DE/LC_MESSAGES/twingle.po | 36 ++++++++++++++++++++++++++++++ l10n/pot/twingle.pot | 36 ++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/l10n/de_DE/LC_MESSAGES/tw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ecKiUd@hPg=W>NEg z#f|t4m9WJkN~{`7uqloD>ukDtLuYpici}MV2;QI%UCdgEji|FeftqLt={qxuD)Cip z!t3b8xu}_}UdDYZR$?EjqBp`^uu1a-1Nah^aTZx=p@yjYkSd#A)E5Uah!dy^EMP1C zK=n+3@^#=&Wbbbvw>YaP2jm#jqnR#^6BfpV(!X}wdxwo?dyF9X)PzkjgJS|A!XQSV!pT z(5N6*5ZbYa&`?$W4Lz3pzL`yglGXb5XjsPHxh|ElcCDc@`3VxXcMf)Q$|_ng$)ktc}YC=u8 znow!g7aErRx_m6U+)U^wG}N301bt~gSuUNSMj;Vdia+g$d`cK_CI!0=_x5#Kg+41Z yGLSM8+3)tpIKAb*#7I)cEk~p(t0mUWhh2R~LjC<+$E{FL|H!y!F>)o>Create a contribution note for each field specified in this selection.

    \n

    Tip: You can enable or disable this fields in the TwingleMANAGER.

    " +msgstr "

    Erstelle eine Zuwendungs-Notiz für jedes Feld, das in dieser Auswahl angegeben ist.

    \n

    Tipp: Sie können diese Felder im TwingleMANAGER aktivieren oder deaktivieren.

    " + +#: templates/CRM/Twingle/Form/Profile.hlp +msgid "

    Create a contact note for each field specified in this selection.

    \n

    Tip: You can enable or disable this fields in the TwingleMANAGER.

    " +msgstr "

    Erstelle eine Kontakt-Notiz für jedes Feld, das in dieser Auswahl angegeben ist.

    \n

    Tipp: Sie können diese Felder im TwingleMANAGER aktivieren oder deaktivieren.

    " + #: templates/CRM/Twingle/Form/Profile.tpl msgid "Are you sure you want to reset the default profile?" msgstr "Möchten Sie wirklich das Standard-Profil zurücksetzen?" diff --git a/l10n/pot/twingle.pot b/l10n/pot/twingle.pot index 868ab0a..7de3f72 100644 --- a/l10n/pot/twingle.pot +++ b/l10n/pot/twingle.pot @@ -74,6 +74,26 @@ msgstr "" msgid "Only alphanumeric characters and the underscore (_) are allowed for profile names." msgstr "" +#: ./CRM/Twingle/Form/Profile.php +msgid "Create contribution notes for" +msgstr "" + +#: ./CRM/Twingle/Form/Profile.php ./api/v3/TwingleDonation/Submit.php +msgid "Purpose" +msgstr "" + +#: ./CRM/Twingle/Form/Profile.php ./api/v3/TwingleDonation/Submit.php +msgid "Remarks" +msgstr "" + +#: ./CRM/Twingle/Form/Profile.php +msgid "Create contact notes for" +msgstr "" + +#: ./CRM/Twingle/Form/Profile.php +msgid "User Extra Field" +msgstr "" + #: ./CRM/Twingle/Form/Profile.php msgid "CiviSEPA" msgstr "" @@ -206,6 +226,22 @@ msgstr "" msgid "Groups" msgstr "" +#: ./templates/CRM/Twingle/Form/Profile.tpl +msgid "Create contribution note for" +msgstr "" + +#: ./templates/CRM/Twingle/Form/Profile.tpl +msgid "Create contact note for" +msgstr "" + +#: ./templates/CRM/Twingle/Form/Profile.hlp +msgid "

    Create a contribution note for each field specified in this selection.

    \n

    Tip: You can enable or disable this fields in the TwingleMANAGER.

    " +msgstr "" + +#: ./templates/CRM/Twingle/Form/Profile.hlp +msgid "

    Create a contact note for each field specified in this selection.

    \n

    Tip: You can enable or disable this fields in the TwingleMANAGER.

    " +msgstr "" + #: ./templates/CRM/Twingle/Form/Profile.tpl msgid "Are you sure you want to reset the default profile?" msgstr "" From f5723a4e7d030617062d54deece8bbc286f5001d Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Thu, 6 Jun 2024 11:57:32 +0200 Subject: [PATCH 5/5] fix obsolete use of CRM_Utils_Array::first() --- api/v3/TwingleDonation/Submit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index 2466575..2ffbdd2 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -814,7 +814,7 @@ function civicrm_api3_twingle_donation_Submit($params) { ) { civicrm_api3('Note', 'create', [ 'entity_table' => 'civicrm_contribution', - 'entity_id' => CRM_Utils_Array::first($result_values['contribution'])['id'], + 'entity_id' => $result_values['contribution']['id'], 'note' => $params[$target], ]); }