add logic to create selected contact and contribution notes

This commit is contained in:
Marc Michalsky 2024-04-26 18:19:54 +02:00
parent 9836168122
commit 758b793c0d
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9

View file

@ -255,6 +255,13 @@ function _civicrm_api3_twingle_donation_Submit_spec(&$params) {
'api.required' => 0, 'api.required' => 0,
'description' => E::ts('Additional information for either the contact or the (recurring) contribution.'), '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. // Create contact notes.
if (isset($params['user_extrafield']) && '' != $params['user_extrafield']) { $contact_note_mappings = $profile->getAttribute('map_as_contact_notes', []);
civicrm_api3('Note', 'create', [ foreach (['user_extrafield'] as $target) {
'entity_table' => 'civicrm_contact', if (
'entity_id' => $contact_id, isset($params[$target])
'note' => $params['user_extrafield'], && '' != $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 // Share organisation address with individual contact, using configured
@ -620,10 +634,6 @@ function civicrm_api3_twingle_donation_Submit($params) {
$contribution_data += $custom_fields['Contribution']; $contribution_data += $custom_fields['Contribution'];
} }
if (isset($params['purpose'])) {
$contribution_data['note'] = $params['purpose'];
}
// set campaign, subject to configuration // set campaign, subject to configuration
CRM_Twingle_Submission::setCampaign($contribution_data, 'contribution', $params, $profile); 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']; $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 // MEMBERSHIP CREATION
// CHECK whether a membership should be created (based on profile settings and data provided) // CHECK whether a membership should be created (based on profile settings and data provided)