/** * Get contact membership record. * * This api will return the membership records for the contacts * having membership based on the relationship with the direct members. * * @param Array $params key/value pairs for contact_id and some * options affecting the desired results; has legacy support * for just passing the contact_id itself as the argument * * @return Array of all found membership property values. * @access public * @todo needs some love - basically only a get for a given contact right now * {@getfields membership_get} */ function civicrm_api3_membership_get($params) { $activeOnly = $membershipTypeId = $membershipType = NULL; $contactID = CRM_Utils_Array::value('contact_id', $params); if (!empty($params['filters']) && is_array($params['filters'])) { $activeOnly = CRM_Utils_Array::value('is_current', $params['filters'], FALSE); } $activeOnly = CRM_Utils_Array::value('active_only', $params, $activeOnly); if (!empty($params['contact_id']) && !is_array($params['contact_id'])) { $membershipValues = _civicrm_api3_membership_get_customv2behaviour($params, $membershipTypeId, $activeOnly); } else { //legacy behaviour only ever worked when contact_id passed in - use standard api function otherwise $membershipValues = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE); } $options = _civicrm_api3_get_options_from_params($params, TRUE, 'membership', 'get'); $return = $options['return']; if (empty($membershipValues) || !empty($return) && !array_key_exists('related_contact_id', $return) && !array_key_exists('relationship_name', $return)) { return civicrm_api3_create_success($membershipValues, $params, 'membership', 'get'); } $members = _civicrm_api3_membership_relationsship_get_customv2behaviour($params, $membershipValues, $contactID); return civicrm_api3_create_success($members, $params, 'membership', 'get'); }
/** * Get contact Membership record. * * This api will return the membership records for the contacts * having membership based on the relationship with the direct members. * * @param array $params * Key/value pairs for contact_id and some. * options affecting the desired results; has legacy support * for just passing the contact_id itself as the argument * * @return array * Array of all found membership property values. */ function civicrm_api3_membership_get($params) { $activeOnly = $membershipTypeId = $membershipType = NULL; $contactID = CRM_Utils_Array::value('contact_id', $params); if (!empty($params['filters']) && is_array($params['filters']) && isset($params['filters']['is_current'])) { $activeOnly = $params['filters']['is_current']; unset($params['filters']['is_current']); } $activeOnly = CRM_Utils_Array::value('active_only', $params, $activeOnly); if ($activeOnly && empty($params['status_id'])) { $params['status_id'] = array('IN' => CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent()); } $options = _civicrm_api3_get_options_from_params($params, TRUE, 'Membership', 'get'); if ($options['is_count']) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } $membershipValues = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Membership'); $return = $options['return']; if (empty($membershipValues) || !empty($return) && !array_key_exists('related_contact_id', $return) && !array_key_exists('relationship_name', $return)) { return civicrm_api3_create_success($membershipValues, $params, 'Membership', 'get'); } $members = _civicrm_api3_membership_relationsship_get_customv2behaviour($params, $membershipValues, $contactID); return civicrm_api3_create_success($members, $params, 'Membership', 'get'); }