[#17] pass campaign to XCM (merged dev_17)

This commit is contained in:
B. Endres 2020-01-30 07:16:24 +01:00
commit 6db38e5706
3 changed files with 14 additions and 4 deletions

View file

@ -311,7 +311,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
$this->add( $this->add(
'select', // field type 'select', // field type
'campaign', // field name 'campaign', // field name
E::ts('Assign donation to campaign'), // field label E::ts('Campaign (e.g. for donation)'), // field label
array('' => E::ts('- none -')) + static::getCampaigns(), // list of options array('' => E::ts('- none -')) + static::getCampaigns(), // list of options
FALSE, // is not required FALSE, // is not required
array('class' => 'crm-select2 huge') array('class' => 'crm-select2 huge')

View file

@ -124,6 +124,8 @@ class CRM_Twingle_Submission {
* The contact type to look for/to create. * The contact type to look for/to create.
* @param array $contact_data * @param array $contact_data
* Data to use for contact lookup/to create a contact with. * Data to use for contact lookup/to create a contact with.
* @param CRM_Twingle_Profile $profile
* Profile used for this process
* *
* @return int | NULL * @return int | NULL
* The ID of the matching/created contact, or NULL if no matching contact * The ID of the matching/created contact, or NULL if no matching contact
@ -131,12 +133,18 @@ class CRM_Twingle_Submission {
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
* When invalid data was given. * When invalid data was given.
*/ */
public static function getContact($contact_type, $contact_data) { public static function getContact($contact_type, $contact_data, $profile) {
// If no parameters are given, do nothing. // If no parameters are given, do nothing.
if (empty($contact_data)) { if (empty($contact_data)) {
return NULL; return NULL;
} }
// add campaign
$campaign_id = (int) $profile->getAttribute('campaign');
if ($campaign_id) {
$contact_data['campaign_id'] = $campaign_id;
}
// Prepare values: country. // Prepare values: country.
if (!empty($contact_data['country'])) { if (!empty($contact_data['country'])) {
if (is_numeric($contact_data['country'])) { if (is_numeric($contact_data['country'])) {

View file

@ -394,7 +394,8 @@ function civicrm_api3_twingle_donation_Submit($params) {
if (!$contact_id = CRM_Twingle_Submission::getContact( if (!$contact_id = CRM_Twingle_Submission::getContact(
'Individual', 'Individual',
$contact_data $contact_data,
$profile
)) { )) {
throw new CiviCRM_API3_Exception( throw new CiviCRM_API3_Exception(
E::ts('Individual contact could not be found or created.'), E::ts('Individual contact could not be found or created.'),
@ -429,7 +430,8 @@ function civicrm_api3_twingle_donation_Submit($params) {
} }
if (!$organisation_id = CRM_Twingle_Submission::getContact( if (!$organisation_id = CRM_Twingle_Submission::getContact(
'Organization', 'Organization',
$organisation_data $organisation_data,
$profile
)) { )) {
throw new CiviCRM_API3_Exception( throw new CiviCRM_API3_Exception(
E::ts('Organisation contact could not be found or created.'), E::ts('Organisation contact could not be found or created.'),