}
$activeOnly = CRM_Utils_Array::value('active_only', $params, $activeOnly);
- if (CRM_Utils_Array::value('contact_id', $params)) {
- $membershipValues = _civicrm_api3_membership_get_customv2behaviour($params, $contactID, $membershipTypeId, $activeOnly );
+ if (CRM_Utils_Array::value('contact_id', $params) && !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
* @param array $params parameters passed into get function
* @return array result for calling function
*/
-function _civicrm_api3_membership_get_customv2behaviour(&$params, $contactID, $membershipTypeId, $activeOnly) {
+function _civicrm_api3_membership_get_customv2behaviour(&$params, $membershipTypeId, $activeOnly) {
// get the membership for the given contact ID
- $membershipParams = array('contact_id' => $contactID);
+ $membershipParams = array('contact_id' => $params['contact_id']);
if ($membershipTypeId) {
$membershipParams['membership_type_id'] = $membershipTypeId;
}
* Test civicrm_membership_get with params not array.
* Gets treated as contact_id, memberships expected.
*/
+ function testGetInSyntax() {
+ $this->_membershipID = $this->contactMembershipCreate($this->_params);
+ $this->_membershipID2 = $this->contactMembershipCreate($this->_params);
+ $this->_membershipID3 = $this->contactMembershipCreate($this->_params);
+ $params = array(
+ 'id' => array('IN' => array($this->_membershipID, $this->_membershipID3)),
+ );
+ $membership = $this->callAPISuccess('membership', 'get', $params);
+ $this->assertEquals(2, $membership['count']);
+ $this->assertEquals(array($this->_membershipID, $this->_membershipID3), array_keys($membership['values']));
+ $params = array(
+ 'id' => array('NOT IN' => array($this->_membershipID, $this->_membershipID3)),
+ );
+ $membership = $this->callAPISuccess('membership', 'get', $params);
+ $this->assertEquals(1, $membership['count']);
+ $this->assertEquals(array($this->_membershipID2), array_keys($membership['values']));
+ }
+ /**
+ * Test civicrm_membership_get with params not array.
+ * Gets treated as contact_id, memberships expected.
+ */
+ function testGetInSyntaxOnContactID() {
+ $this->_membershipID = $this->contactMembershipCreate($this->_params);
+ $contact2 = $this->individualCreate();
+ $contact3 = $this->individualCreate(array('first_name' => 'Scout', 'last_name' => 'Canine'));
+ $this->_membershipID2 = $this->contactMembershipCreate(array_merge($this->_params, array('contact_id' => $contact2)));
+ $this->_membershipID3 = $this->contactMembershipCreate(array_merge($this->_params, array('contact_id' => $contact3)));
+ $params = array(
+ 'contact_id' => array('IN' => array($this->_contactID, $contact3)),
+ );
+ $membership = $this->callAPISuccess('membership', 'get', $params);
+ $this->assertEquals(2, $membership['count']);
+ $this->assertEquals(array($this->_membershipID, $this->_membershipID3), array_keys($membership['values']));
+ $params = array(
+ 'contact_id' => array('NOT IN' => array($this->_contactID, $contact3)),
+ );
+ $membership = $this->callAPISuccess('membership', 'get', $params);
+ $this->assertEquals(1, $membership['count']);
+ $this->assertEquals(array($this->_membershipID2), array_keys($membership['values']));
+ }
+ /**
+ * Test civicrm_membership_get with params not array.
+ * Gets treated as contact_id, memberships expected.
+ */
+
function testGetWithParamsMemberShipTypeId() {
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$params = array(