Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup of api_v3_membership_create towards #11556 #12313

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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