Skip to content

Commit

Permalink
Cleanup of api_v3_membership_create towards civicrm#11556
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Jun 15, 2018
1 parent 58d4a38 commit fd88af0
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions api/v3/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,12 @@ function civicrm_api3_membership_create($params) {
_civicrm_api3_custom_format_params($params, $values, 'Membership');
$params = array_merge($params, $values);

// Calculate membership dates
// Fixme: This code belongs in the BAO
if (empty($params['id']) || !empty($params['num_terms'])) {
// If this is a new membership or we have a specified number of terms calculate membership dates.
if (empty($params['id'])) {
// This is a new membership, calculate the membership dates.
$calcDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType(
$params['membership_type_id'],
CRM_Utils_Array::value('join_date', $params),
Expand All @@ -113,6 +116,7 @@ function civicrm_api3_membership_create($params) {
);
}
else {
// This is an existing membership, calculate the membership dates after renewal
$calcDates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType(
$params['id'],
NULL,
Expand All @@ -128,20 +132,20 @@ function civicrm_api3_membership_create($params) {
}

// Fixme: This code belongs in the BAO
$action = CRM_Core_Action::ADD;
// we need user id during add mode
$ids = array();
if (!empty($params['contact_id'])) {
$ids['userId'] = $params['contact_id'];
if (empty($params['id'])) {
$params['action'] = CRM_Core_Action::ADD;
// we need user id during add mode
$ids = array();
if (!empty($params['contact_id'])) {
$ids['userId'] = $params['contact_id'];
}
}
//for edit membership id should be present
// probably not required now.
if (!empty($params['id'])) {
else {
// edit mode
$params['action'] = CRM_Core_Action::UPDATE;
// $ids['membership'] is required in CRM_Price_BAO_LineItem::processPriceSet
$ids['membership'] = $params['id'];
$action = CRM_Core_Action::UPDATE;
}
//need to pass action to handle related memberships.
$params['action'] = $action;

$membershipBAO = CRM_Member_BAO_Membership::create($params, $ids, TRUE);

Expand Down

0 comments on commit fd88af0

Please sign in to comment.