Allow contributions be assigned to a configured campaign per profile.

This commit is contained in:
Jens Schuppe 2019-01-21 11:19:49 +01:00
parent 336870c38e
commit 5ce76eae5f
4 changed files with 38 additions and 1 deletions

View file

@ -200,6 +200,15 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
array('class' => 'crm-select2 huge', 'multiple' => 'multiple') 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( $this->addButtons(array(
array( array(
'type' => 'submit', 'type' => 'submit',
@ -470,4 +479,22 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
return $this->getGroups(); 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;
}
} }

View file

@ -186,7 +186,8 @@ class CRM_Twingle_Profile {
'gender_other', 'gender_other',
'newsletter_groups', 'newsletter_groups',
'postinfo_groups', 'postinfo_groups',
'donation_receipt_groups' 'donation_receipt_groups',
'campaign',
); );
} }
@ -242,6 +243,7 @@ class CRM_Twingle_Profile {
'newsletter_groups' => NULL, 'newsletter_groups' => NULL,
'postinfo_groups' => NULL, 'postinfo_groups' => NULL,
'donation_receipt_groups' => NULL, 'donation_receipt_groups' => NULL,
'campaign' => NULL,
)); ));
} }

View file

@ -448,6 +448,9 @@ function civicrm_api3_twingle_donation_Submit($params) {
if (!empty($params['purpose'])) { if (!empty($params['purpose'])) {
$contribution_data['note'] = $params['purpose']; $contribution_data['note'] = $params['purpose'];
} }
if (!empty($campaign = $profile->getAttribute('campaign'))) {
$contribution_data['campaign_id'] = $campaign;
}
if ( if (
CRM_Twingle_Submission::civiSepaEnabled() CRM_Twingle_Submission::civiSepaEnabled()

View file

@ -102,6 +102,11 @@
<td class="content">{$form.donation_receipt_groups.html}</td> <td class="content">{$form.donation_receipt_groups.html}</td>
</tr> </tr>
<tr class="crm-section">
<td class="label">{$form.campaign.label}</td>
<td class="content">{$form.campaign.html}</td>
</tr>
</table> </table>
</fieldset> </fieldset>