}
}
+ $currentMemberships = NULL;
+ if ($membershipIsActive) {
+ $is_test = $self->_mode != 'live' ? 1 : 0;
+ $memContactID = $self->_membershipContactID;
+
+ // For anonymous user check using dedupe rule
+ // if user has Cancelled Membership
+ if (!$memContactID) {
+ $dedupeParams = CRM_Dedupe_Finder::formatParams($fields, 'Individual');
+ $dedupeParams['check_permission'] = FALSE;
+ $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
+ // if we find more than one contact, use the first one
+ $memContactID = CRM_Utils_Array::value(0, $ids);
+ }
+ $currentMemberships = CRM_Member_BAO_Membership::getContactsCancelledMembership($memContactID,
+ $is_test
+ );
+
+ $errorText = 'Your %1 membership was previously cancelled and can not be renewed online. Please contact the site administrator for assistance.';
+ foreach ($self->_values['fee'] as $fieldKey => $fieldValue) {
+ if ($fieldValue['html_type'] != 'Text' && CRM_Utils_Array::value('price_' . $fieldKey, $fields)) {
+ if (!is_array($fields['price_' . $fieldKey])) {
+ if (in_array($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'], $currentMemberships)) {
+ $errors['price_' . $fieldKey] = ts($errorText, array( 1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'])));
+ }
+ }
+ else {
+ foreach ($fields['price_' . $fieldKey] as $key => $ignore) {
+ if (in_array($fieldValue['options'][$key]['membership_type_id'], $currentMemberships)) {
+ $errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$key]['membership_type_id'])));
+ }
+ }
+ }
+ }
+ }
+ }
+
// CRM-12233
if ($membershipIsActive && !$self->_membershipBlock['is_required']
&& $self->_values['amount_block_is_active']) {
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;
+ }
}