Merge branch 'dev_5'
[#5] Create membership with configurable membership type
This commit is contained in:
commit
a7bcd118cc
4 changed files with 63 additions and 2 deletions
|
@ -224,6 +224,15 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
||||||
array('class' => 'crm-select2 huge')
|
array('class' => 'crm-select2 huge')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->add(
|
||||||
|
'select', // field type
|
||||||
|
'membership_type_id', // field name
|
||||||
|
E::ts('Create membership of type'), // field label
|
||||||
|
array('' => E::ts('- none -')) + $this->getMembershipTypes(), // list of options
|
||||||
|
FALSE, // is not required
|
||||||
|
array('class' => 'crm-select2 huge')
|
||||||
|
);
|
||||||
|
|
||||||
$this->add(
|
$this->add(
|
||||||
'text', // field type
|
'text', // field type
|
||||||
'contribution_source', // field name
|
'contribution_source', // field name
|
||||||
|
@ -417,6 +426,27 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
||||||
return $financial_types;
|
return $financial_types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves membership types present within the system as options for select
|
||||||
|
* form elements.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @throws \CiviCRM_API3_Exception
|
||||||
|
*/
|
||||||
|
public function getMembershipTypes() {
|
||||||
|
$membership_types = array();
|
||||||
|
$query = civicrm_api3('MembershipType', 'get', array(
|
||||||
|
'is_active' => 1,
|
||||||
|
'option.limit' => 0,
|
||||||
|
'return' => 'id,name'
|
||||||
|
));
|
||||||
|
foreach ($query['values'] as $type) {
|
||||||
|
$membership_types[$type['id']] = $type['name'];
|
||||||
|
}
|
||||||
|
return $membership_types;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves campaigns present within the system as options for select form
|
* Retrieves campaigns present within the system as options for select form
|
||||||
* elements.
|
* elements.
|
||||||
|
|
|
@ -207,6 +207,7 @@ class CRM_Twingle_Profile {
|
||||||
'campaign',
|
'campaign',
|
||||||
'contribution_source',
|
'contribution_source',
|
||||||
'custom_field_mapping',
|
'custom_field_mapping',
|
||||||
|
'membership_type_id',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,6 +268,7 @@ class CRM_Twingle_Profile {
|
||||||
'campaign' => NULL,
|
'campaign' => NULL,
|
||||||
'contribution_source' => NULL,
|
'contribution_source' => NULL,
|
||||||
'custom_field_mapping' => NULL,
|
'custom_field_mapping' => NULL,
|
||||||
|
'membership_type_id' => NULL,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -265,6 +265,9 @@ function civicrm_api3_twingle_donation_Submit($params) {
|
||||||
// Copy submitted parameters.
|
// Copy submitted parameters.
|
||||||
$original_params = $params;
|
$original_params = $params;
|
||||||
|
|
||||||
|
// Prepare results array.
|
||||||
|
$result_values = array();
|
||||||
|
|
||||||
// Get the profile defined for the given form ID, or the default profile
|
// Get the profile defined for the given form ID, or the default profile
|
||||||
// if none matches.
|
// if none matches.
|
||||||
$profile = CRM_Twingle_Profile::getProfileForProject($params['project_id']);
|
$profile = CRM_Twingle_Profile::getProfileForProject($params['project_id']);
|
||||||
|
@ -460,6 +463,11 @@ function civicrm_api3_twingle_donation_Submit($params) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result_values['contact'] = $contact_id;
|
||||||
|
if (isset($organisation_id)) {
|
||||||
|
$result_values['organization'] = $organisation_id;
|
||||||
|
}
|
||||||
|
|
||||||
// If requested, add contact to newsletter groups defined in the profile.
|
// If requested, add contact to newsletter groups defined in the profile.
|
||||||
if (!empty($params['newsletter']) && !empty($groups = $profile->getAttribute('newsletter_groups'))) {
|
if (!empty($params['newsletter']) && !empty($groups = $profile->getAttribute('newsletter_groups'))) {
|
||||||
foreach ($groups as $group_id) {
|
foreach ($groups as $group_id) {
|
||||||
|
@ -467,6 +475,8 @@ function civicrm_api3_twingle_donation_Submit($params) {
|
||||||
'group_id' => $group_id,
|
'group_id' => $group_id,
|
||||||
'contact_id' => $contact_id,
|
'contact_id' => $contact_id,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$result_values['newsletter'][] = $group_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,6 +487,8 @@ function civicrm_api3_twingle_donation_Submit($params) {
|
||||||
'group_id' => $group_id,
|
'group_id' => $group_id,
|
||||||
'contact_id' => $contact_id,
|
'contact_id' => $contact_id,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$result_values['postinfo'][] = $group_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -488,6 +500,8 @@ function civicrm_api3_twingle_donation_Submit($params) {
|
||||||
'group_id' => $group_id,
|
'group_id' => $group_id,
|
||||||
'contact_id' => $contact_id,
|
'contact_id' => $contact_id,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$result_values['donation_receipt'][] = $group_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,7 +595,7 @@ function civicrm_api3_twingle_donation_Submit($params) {
|
||||||
// Create the mandate.
|
// Create the mandate.
|
||||||
$mandate = civicrm_api3('SepaMandate', 'createfull', $mandate_data);
|
$mandate = civicrm_api3('SepaMandate', 'createfull', $mandate_data);
|
||||||
|
|
||||||
$result_values = $mandate['values'];
|
$result_values['sepa_mandate'] = $mandate['values'];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Create (recurring) contribution.
|
// Create (recurring) contribution.
|
||||||
|
@ -629,7 +643,17 @@ function civicrm_api3_twingle_donation_Submit($params) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result_values = $contribution['values'];
|
$result_values['contribution'] = $contribution['values'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create membership if a membership type is configured within the profile.
|
||||||
|
if (!empty($membership_type_id = $profile->getAttribute('membership_type_id'))) {
|
||||||
|
$membership = civicrm_api3('Membership', 'create', array(
|
||||||
|
'contact_id' => $contact_id,
|
||||||
|
'membership_type_id' => $membership_type_id,
|
||||||
|
));
|
||||||
|
|
||||||
|
$result_values['membership'] = $membership;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = civicrm_api3_create_success($result_values);
|
$result = civicrm_api3_create_success($result_values);
|
||||||
|
|
|
@ -185,6 +185,11 @@
|
||||||
<td class="content">{$form.campaign.html}</td>
|
<td class="content">{$form.campaign.html}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr class="crm-section">
|
||||||
|
<td class="label">{$form.membership_type_id.label}</td>
|
||||||
|
<td class="content">{$form.membership_type_id.html}</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr class="crm-section">
|
<tr class="crm-section">
|
||||||
<td class="label">{$form.contribution_source.label}</td>
|
<td class="label">{$form.contribution_source.label}</td>
|
||||||
<td class="content">{$form.contribution_source.html}</td>
|
<td class="content">{$form.contribution_source.html}</td>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue