Merge branch 'issue/84'

[#88] Improve profile options for note creation
This commit is contained in:
Jens Schuppe 2024-06-12 14:44:15 +02:00
commit 933c51c48e
9 changed files with 207 additions and 13 deletions

View file

@ -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',

View file

@ -530,6 +530,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(
@ -646,6 +648,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
@ -683,7 +687,10 @@ class CRM_Twingle_Profile {
return $default_profile;
}
else {
throw new ProfileException('Could not find default profile', ProfileException::ERROR_CODE_DEFAULT_PROFILE_NOT_FOUND);
throw new ProfileException(
'Could not find default profile',
ProfileException::ERROR_CODE_DEFAULT_PROFILE_NOT_FOUND
);
}
}

View file

@ -102,4 +102,39 @@ 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.');
foreach (CRM_Twingle_Profile::getProfiles() as $profile) {
$profile_changed = FALSE;
/** @phpstan-var array<string> $contribution_notes */
$contribution_notes = $profile->getAttribute('map_as_contribution_notes', []);
/** @phpstan-var array<string> $contact_notes */
$contact_notes = $profile->getAttribute('map_as_contact_notes', []);
if (!in_array('purpose', $contribution_notes, TRUE)) {
$profile->setAttribute('map_as_contribution_notes', array_merge($contribution_notes, ['purpose']));
$profile_changed = TRUE;
}
if (!in_array('user_extrafield', $contact_notes, TRUE)) {
$profile->setAttribute('map_as_contact_notes', array_merge($contact_notes, ['user_extrafield']));
$profile_changed = TRUE;
}
if ($profile_changed) {
$profile->saveProfile();
}
}
return TRUE;
}
}

View file

@ -17,6 +17,7 @@ declare(strict_types = 1);
use CRM_Twingle_ExtensionUtil as E;
use Civi\Twingle\Exceptions\BaseException;
use Civi\Api4\Note;
/**
* TwingleDonation.Submit API specification
@ -255,6 +256,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 +485,21 @@ 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.
/** @phpstan-var array<string> $contact_note_mappings */
$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, TRUE)
) {
Note::create(FALSE)
->addValue('entity_table', 'civicrm_contact')
->addValue('entity_id', $contact_id)
->addValue('note', $params[$target])
->execute();
}
}
// Share organisation address with individual contact, using configured
@ -620,10 +636,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);
@ -791,6 +803,23 @@ function civicrm_api3_twingle_donation_Submit($params) {
);
}
// Add notes to the contribution.
/** @phpstan-var array<string> $contribution_note_mappings */
$contribution_note_mappings = $profile->getAttribute('map_as_contribution_notes', []);
foreach (['purpose', 'remarks'] as $target) {
if (
in_array($target, $contribution_note_mappings, TRUE)
&& isset($params[$target])
&& '' !== $params[$target]
) {
Note::create(FALSE)
->addValue('entity_table', 'civicrm_contribution')
->addValue('entity_id', reset($contribution['values'])['id'])
->addValue('note', reset($params[$target]))
->execute();
}
}
$result_values['contribution'] = $contribution['values'];
}

Binary file not shown.

View file

@ -96,6 +96,26 @@ msgstr ""
"Nur alphanumerische Zeichen und der Unterstrich (_) sind für Profilnamen "
"erlaubt."
#: CRM/Twingle/Form/Profile.php
msgid "Create contribution notes for"
msgstr "Zuwendungs-Notizen erstellen für"
#: CRM/Twingle/Form/Profile.php ./api/v3/TwingleDonation/Submit.php
msgid "Purpose"
msgstr "Zweck"
#: CRM/Twingle/Form/Profile.php ./api/v3/TwingleDonation/Submit.php
msgid "Remarks"
msgstr "Anmerkungen"
#: CRM/Twingle/Form/Profile.php
msgid "Create contact notes for"
msgstr "Kontakt-Notizen erstellen für"
#: CRM/Twingle/Form/Profile.php
msgid "User Extra Field"
msgstr "Benutzer-Extra-Feld"
#: CRM/Twingle/Form/Profile.php
msgid "CiviSEPA"
msgstr "CiviSEPA"
@ -231,6 +251,22 @@ msgstr "Zahlungsmethoden"
msgid "Groups"
msgstr "Gruppen"
#: templates/CRM/Twingle/Form/Profile.tpl
msgid "Create contribution note for"
msgstr "Zuwendungs-Notiz erstellen für"
#: templates/CRM/Twingle/Form/Profile.tpl
msgid "Create contact note for"
msgstr "Kontakt-Notiz erstellen für"
#: templates/CRM/Twingle/Form/Profile.hlp
msgid "Create a contribution note for each field specified in this selection. 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. 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. 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. 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?"

View file

@ -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 "<p>Create a contribution note for each field specified in this selection.</p>\n <p><i>Tip: You can enable or disable this fields in the TwingleMANAGER.</i></p>"
msgstr ""
#: ./templates/CRM/Twingle/Form/Profile.hlp
msgid "<p>Create a contact note for each field specified in this selection.</p>\n <p><i>Tip: You can enable or disable this fields in the TwingleMANAGER.</i></p>"
msgstr ""
#: ./templates/CRM/Twingle/Form/Profile.tpl
msgid "Are you sure you want to reset the default profile?"
msgstr ""

View file

@ -75,4 +75,14 @@
<li><strong>ContributionRecur</strong> &ndash; Will be set on the recurring contribution and deriving single contributions</li>
</ul>{/ts}
{/htxt}
{htxt id='id-map_as_contribution_notes'}
{ts domain="de.systopia.twingle"}<p>Create a contribution note for each field specified in this selection.</p>
<p><i>Tip: You can enable or disable this fields in the TwingleMANAGER.</i></p>{/ts}
{/htxt}
{htxt id='id-map_as_contact_notes'}
{ts domain="de.systopia.twingle"}<p>Create a contact note for each field specified in this selection.</p>
<p><i>Tip: You can enable or disable this fields in the TwingleMANAGER.</i></p>{/ts}
{/htxt}
{/crmScope}

View file

@ -313,6 +313,22 @@
<td class="content">{$form.contribution_source.html}</td>
</tr>
<tr class="crm-section">
<td class="label">
{$form.map_as_contribution_notes.label}
{help id="id-map_as_contribution_notes" title=$form.map_as_contribution_notes.label}
</td>
<td class="content">{$form.map_as_contribution_notes.html}</td>
</tr>
<tr class="crm-section">
<td class="label">
{$form.map_as_contact_notes.label}
{help id="id-map_as_contact_notes" title=$form.map_as_contact_notes.label}
</td>
<td class="content">{$form.map_as_contact_notes.html}</td>
</tr>
<tr class="crm-section">
<td class="label">
{$form.custom_field_mapping.label}