You are here

protected function wf_crm_webform_base::findMemberships in Webform CiviCRM Integration 7.4

Same name and namespace in other branches
  1. 7.5 includes/wf_crm_webform_base.inc \wf_crm_webform_base::findMemberships()

Get memberships for a contact

Parameters

$cid:

Return value

array

2 calls to wf_crm_webform_base::findMemberships()
wf_crm_webform_postprocess::processMemberships in includes/wf_crm_webform_postprocess.inc
Process memberships for a contact Called during webform submission
wf_crm_webform_preprocess::loadMemberships in includes/wf_crm_webform_preprocess.inc
Load existing membership information and display a message to members.

File

includes/wf_crm_webform_base.inc, line 590

Class

wf_crm_webform_base
Class wf_crm_webform_base

Code

protected function findMemberships($cid) {
  static $status_types;
  static $membership_types;
  if (!isset($membership_types)) {
    $membership_types = array_keys(wf_crm_apivalues('membershipType', 'get', array(
      'is_active' => 1,
      'return' => 'id',
    )));
  }
  $existing = wf_crm_apivalues('membership', 'get', array(
    'contact_id' => $cid,
    // Limit to only enabled membership types
    'membership_type_id' => array(
      'IN' => $membership_types,
    ),
  ));
  if (!$existing) {
    return array();
  }
  if (!$status_types) {
    $status_types = wf_crm_apivalues('membership_status', 'get');
  }

  // Attempt to order memberships by most recent and active
  $active = $expired = array();
  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);
}