$membershipValues = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE);
}
- if (empty($membershipValues)) {
- // No results is NOT an error!
- return civicrm_api3_create_success($membershipValues, $params);
+ $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');
+}
+
+/**
+ * When we copied apiv3 from api v2 we brought across some custom behaviours - in the case of
+ * membership a complicated return array is constructed. The original
+ * behaviour made contact_id a required field. We still need to keep this for v3 when contact_id
+ * is passed in as part of the reasonable expectation developers have that we will keep the api
+ * as stable as possible
+ *
+ * @param array $params parameters passed into get function
+ * @return array result for calling function
+ */
+function _civicrm_api3_membership_get_customv2behaviour(&$params, $membershipTypeId, $activeOnly) {
+ // get the membership for the given contact ID
+ $membershipParams = array('contact_id' => $params['contact_id']);
+ if ($membershipTypeId) {
+ $membershipParams['membership_type_id'] = $membershipTypeId;
+ }
+ $membershipValues = array();
+ CRM_Member_BAO_Membership::getValues($membershipParams, $membershipValues, $activeOnly);
+ return $membershipValues;
+}
+
+
+/**
+ * non-standard behaviour inherited from v2
+* @param array $params parameters passed into get function
+* @return array result for calling function
+*/
+function _civicrm_api3_membership_relationsship_get_customv2behaviour(&$params, $membershipValues, $contactID) {
$relationships = array();
foreach ($membershipValues as $membershipId => $values) {
// populate the membership type name for the membership type id
}
}
-
- return civicrm_api3_create_success($members, $params, 'membership', 'get');
-}
-
-/**
- * When we copied apiv3 from api v2 we brought across some custom behaviours - in the case of
- * membership a complicated return array is constructed. The original
- * behaviour made contact_id a required field. We still need to keep this for v3 when contact_id
- * is passed in as part of the reasonable expectation developers have that we will keep the api
- * as stable as possible
- *
- * @param array $params parameters passed into get function
- * @return array result for calling function
- */
-function _civicrm_api3_membership_get_customv2behaviour(&$params, $membershipTypeId, $activeOnly) {
- // get the membership for the given contact ID
- $membershipParams = array('contact_id' => $params['contact_id']);
- if ($membershipTypeId) {
- $membershipParams['membership_type_id'] = $membershipTypeId;
- }
- $membershipValues = array();
- CRM_Member_BAO_Membership::getValues($membershipParams, $membershipValues, $activeOnly);
- return $membershipValues;
+ return $members;
}
*/
function membership_get_example(){
$params = array(
- 'contact_id' => 13,
+ 'contact_id' => 17,
'filters' => array(
'is_current' => 1,
),
'1' => array(
'id' => '1',
'membership_id' => '1',
- 'contact_id' => '13',
- 'membership_contact_id' => '13',
- 'membership_type_id' => '21',
+ 'contact_id' => '17',
+ 'membership_contact_id' => '17',
+ 'membership_type_id' => '25',
'join_date' => '2009-01-21',
'start_date' => '2013-07-29 00:00:00',
'membership_start_date' => '2009-01-21',
'membership_end_date' => '2009-12-21',
'source' => 'Payment',
'membership_source' => 'Payment',
- 'status_id' => '18',
+ 'status_id' => '20',
'is_override' => '1',
'is_test' => 0,
'member_is_test' => 0,
*/
function membership_create_example(){
$params = array(
- 'contact_id' => 25,
- 'membership_type_id' => 42,
+ 'contact_id' => 30,
+ 'membership_type_id' => 48,
'join_date' => '2009-01-21',
'start_date' => '2009-01-21',
'end_date' => '2009-12-21',
'source' => 'Payment',
'is_override' => 1,
- 'status_id' => 28,
+ 'status_id' => 31,
'custom_1' => 'custom string',
);
'values' => array(
'1' => array(
'id' => '1',
- 'contact_id' => '25',
- 'membership_type_id' => '42',
+ 'contact_id' => '30',
+ 'membership_type_id' => '48',
'join_date' => '20090121000000',
'start_date' => '2013-07-29 00:00:00',
'end_date' => '2013-08-04 00:00:00',
'source' => 'Payment',
- 'status_id' => '28',
+ 'status_id' => '31',
'is_override' => '1',
'owner_membership_id' => '',
'max_related' => '',
- 'is_test' => '',
+ 'is_test' => 0,
'is_pay_later' => '',
'contribution_recur_id' => '',
'campaign_id' => '',
*/
function membership_update_example(){
$params = array(
- 'contact_id' => 31,
- 'membership_type_id' => 54,
+ 'contact_id' => 36,
+ 'membership_type_id' => 60,
'join_date' => '2009-01-21',
'start_date' => '2009-01-21',
'end_date' => '2009-12-21',
'source' => 'Payment',
'is_override' => 1,
- 'status_id' => 34,
+ 'status_id' => 37,
'custom_1' => 'custom string',
);
'values' => array(
'1' => array(
'id' => '1',
- 'contact_id' => '31',
- 'membership_type_id' => '54',
+ 'contact_id' => '36',
+ 'membership_type_id' => '60',
'join_date' => '20090121000000',
'start_date' => '2013-07-29 00:00:00',
'end_date' => '2013-08-04 00:00:00',
'source' => 'Payment',
- 'status_id' => '34',
+ 'status_id' => '37',
'is_override' => '1',
'owner_membership_id' => '',
'max_related' => '',
- 'is_test' => '',
+ 'is_test' => 0,
'is_pay_later' => '',
'contribution_recur_id' => '',
'campaign_id' => '',