else {
$dao->whereAdd('is_test IS NULL OR is_test = 0');
}
-
+
//avoid pending membership as current membership: CRM-3027
- $pendingStatusId = array_search('Pending', CRM_Member_PseudoConstant::membershipStatus());
- $dao->whereAdd("status_id != $pendingStatusId");
-
+ $statusIds[] = array_search('Pending', CRM_Member_PseudoConstant::membershipStatus());
+ if (!$membershipId) {
+ $statusIds[] = array_search('Cancelled', CRM_Member_PseudoConstant::membershipStatus());
+ }
+ $dao->whereAdd('status_id NOT IN ( ' . implode(',', $statusIds) . ')');
+
// order by start date to find most recent membership first, CRM-4545
$dao->orderBy('start_date DESC');
self::$_renewalActType = CRM_Utils_Array::key('Membership Renewal', $activityTypes);
self::$_signupActType = CRM_Utils_Array::key('Membership Signup', $activityTypes);
}
+
+ /**
+ * Get all Cancelled Membership(s) for a contact
+ *
+ * @param int $contactID contact id
+ * @param boolean $isTest mode of payment
+ *
+ * @return array of membership type
+ * @static
+ * @access public
+ */
+ static function getContactsCancelledMembership($contactID, $isTest = FALSE) {
+ if (!$contactID) {
+ return array();
+ }
+ $allStatus = CRM_Member_PseudoConstant::membershipStatus();
+ $query = 'SELECT membership_type_id FROM civicrm_membership WHERE contact_id = %1 AND status_id = %2 AND is_test = %3';
+ $queryParams = array(
+ 1 => array($contactID, 'Integer'),
+ 2 => array(array_search('Cancelled', $allStatus), 'Integer'),
+ 3 => array($isTest, 'Boolean'),
+ );
+
+ $dao = CRM_Core_DAO::executeQuery($query, $queryParams);
+ $cancelledMembershipIds = array();
+ while ($dao->fetch()) {
+ $cancelledMembershipIds[] = $dao->membership_type_id;
+ }
+ return $cancelledMembershipIds;
+ }
}