return NULL;
}
+ /**
+ * Get the number of terms for this contribution for a given membership type
+ * based on querying the line item table and relevant price field values
+ * Note that any one contribution should only be able to have one line item relating to a particular membership
+ * type
+ * @param int $membershipTypeID
+ *
+ * @return int
+ */
+ public function getNumTermsByContributionAndMembershipType($membershipTypeID) {
+ if (!is_numeric($membershipTypeID)) {
+ //precautionary measure - this is being introduced to a mature release hence adding extra checks that
+ // might be removed later
+ return 1;
+ }
+ $numTerms = CRM_Core_DAO::singleValueQuery("
+ SELECT membership_num_terms FROM civicrm_line_item li
+ LEFT JOIN civicrm_price_field_value v ON li.price_field_value_id = v.id
+ WHERE entity_id = %1 AND entity_table = 'civicrm_contribution' AND membership_type_id = %2",
+ array(1 => array($this->id, 'Integer') , 2 => array($membershipTypeID, 'Integer'))
+ );
+ // default of 1 is precautionary
+ return empty($numTerms) ? 1 : $numTerms;
+ }
+
/**
* takes an associative array and creates a contribution object
*
*/
CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday);
+ $num_terms = $contribution->getNumTermsByContributionAndMembershipType($membership->membership_type_id);
+ // @todo - we should pass membership_type_id instead of null here but not
+ // adding as not sure of testing
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id,
- $changeToday
+ $changeToday, NULL, $num_terms
);
+
$dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
}
else {