protected function WebformCivicrmBase::findMemberships in Webform CiviCRM Integration 8.5
Get memberships for a contact
Parameters
$cid:
Return value
array
2 calls to WebformCivicrmBase::findMemberships()
- WebformCivicrmPostProcess::processMemberships in src/
WebformCivicrmPostProcess.php - Process memberships for a contact Called during webform submission
- WebformCivicrmPreProcess::loadMemberships in src/
WebformCivicrmPreProcess.php - Load existing membership information and display a message to members.
File
- src/
WebformCivicrmBase.php, line 592 - Front-end form handler base class.
Class
- WebformCivicrmBase
- Class WebformCivicrmBase
Namespace
Drupal\webform_civicrmCode
protected function findMemberships($cid) {
static $status_types;
static $membership_types;
$utils = \Drupal::service('webform_civicrm.utils');
if (!isset($membership_types)) {
$domain = $utils
->wf_civicrm_api('domain', 'get', [
'current_domain' => 1,
'return' => 'id',
]);
$domain = wf_crm_aval($domain, 'id', 1);
$membership_types = array_keys($utils
->wf_crm_apivalues('membershipType', 'get', [
'is_active' => 1,
'domain_id' => $domain,
'return' => 'id',
]));
}
$existing = $utils
->wf_crm_apivalues('membership', 'get', [
'contact_id' => $cid,
// Limit to only enabled membership types
'membership_type_id' => [
'IN' => $membership_types,
],
// skip membership through Inheritance.
'owner_membership_id' => [
'IS NULL' => 1,
],
]);
if (!$existing) {
return [];
}
if (!$status_types) {
$status_types = $utils
->wf_crm_apivalues('membership_status', 'get');
}
// Attempt to order memberships by most recent and active
$active = $expired = [];
foreach ($existing as $membership) {
$membership['is_active'] = $status_types[$membership['status_id']]['is_current_member'];
$membership['status'] = $status_types[$membership['status_id']]['label'];
$list = $membership['is_active'] ? 'active' : 'expired';
array_unshift(${$list}, $membership);
}
return array_merge($active, $expired);
}