diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 2015128..e5cc6d4 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -200,6 +200,15 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { array('class' => 'crm-select2 huge', 'multiple' => 'multiple') ); + $this->add( + 'select', // field type + 'campaign', // field name + E::ts('Assign donation to campaign'), // field label + $this->getCampaigns(), // list of options + FALSE, // is not required + array('class' => 'crm-select2 huge') + ); + $this->addButtons(array( array( 'type' => 'submit', @@ -470,4 +479,22 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { return $this->getGroups(); } + /** + * Retrieves campaigns as options for select elements. + */ + public function getCampaigns() { + $campaigns = array(); + $query = civicrm_api3('Campaign', 'get', array( + 'option.limit' => 0, + 'return' => array( + 'id', + 'title', + ) + )); + foreach ($query['values'] as $campaign) { + $campaigns[$campaign['id']] = $campaign['title']; + } + return $campaigns; + } + } diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index aa6bd0f..0a0702d 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -186,7 +186,8 @@ class CRM_Twingle_Profile { 'gender_other', 'newsletter_groups', 'postinfo_groups', - 'donation_receipt_groups' + 'donation_receipt_groups', + 'campaign', ); } @@ -242,6 +243,7 @@ class CRM_Twingle_Profile { 'newsletter_groups' => NULL, 'postinfo_groups' => NULL, 'donation_receipt_groups' => NULL, + 'campaign' => NULL, )); } diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index 67e146f..4dd6e9a 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -448,6 +448,9 @@ function civicrm_api3_twingle_donation_Submit($params) { if (!empty($params['purpose'])) { $contribution_data['note'] = $params['purpose']; } + if (!empty($campaign = $profile->getAttribute('campaign'))) { + $contribution_data['campaign_id'] = $campaign; + } if ( CRM_Twingle_Submission::civiSepaEnabled() diff --git a/templates/CRM/Twingle/Form/Profile.tpl b/templates/CRM/Twingle/Form/Profile.tpl index 62b2d8a..1841feb 100644 --- a/templates/CRM/Twingle/Form/Profile.tpl +++ b/templates/CRM/Twingle/Form/Profile.tpl @@ -102,6 +102,11 @@ {$form.donation_receipt_groups.html} + + {$form.campaign.label} + {$form.campaign.html} + +