+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017 |
+ | Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
* Array of parameters determined by getfields.
*/
function _civicrm_api3_membership_delete_spec(&$params) {
- $params['preserve_contribution'] = array(
+ $params['preserve_contribution'] = [
'api.required' => 0,
'title' => 'Preserve Contribution',
'description' => 'By default this is 0, or 0 if not set. Set to 1 to preserve the associated contribution record when membership is deleted.',
'type' => CRM_Utils_Type::T_BOOLEAN,
- );
+ ];
}
/**
}
}
- $values = array();
+ $values = [];
_civicrm_api3_custom_format_params($params, $values, 'Membership');
$params = array_merge($params, $values);
}
else {
// This is an existing membership, calculate the membership dates after renewal
+ // num_terms is treated as a 'special sauce' for is_renewal but this
+ // isn't really helpful for completing pendings.
$calcDates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType(
$params['id'],
NULL,
$params['num_terms']
);
}
- foreach (array('join_date', 'start_date', 'end_date') as $date) {
+ foreach (['join_date', 'start_date', 'end_date'] as $date) {
if (empty($params[$date]) && isset($calcDates[$date])) {
$params[$date] = $calcDates[$date];
}
}
// Fixme: This code belongs in the BAO
+ $ids = [];
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'];
}
else {
// edit mode
$params['action'] = CRM_Core_Action::UPDATE;
- // $ids['membership'] is required in CRM_Price_BAO_LineItem::processPriceSet
+ // @todo remove $ids['membership'] is required in CRM_Price_BAO_LineItem::processPriceSet
$ids['membership'] = $params['id'];
}
+ // @todo stop passing $ids (membership and userId may be set above)
$membershipBAO = CRM_Member_BAO_Membership::create($params, $ids, TRUE);
if (array_key_exists('is_error', $membershipBAO)) {
return civicrm_api3_create_error(ts('The membership can not be saved, no valid membership status for given dates'));
}
- $membership = array();
+ $membership = [];
_civicrm_api3_object_to_array($membershipBAO, $membership[$membershipBAO->id]);
return civicrm_api3_create_success($membership, $params, 'Membership', 'create', $membershipBAO);
$params['contact_id']['api.required'] = 1;
$params['membership_type_id']['api.required'] = 1;
$params['is_test']['api.default'] = 0;
- $params['membership_type_id']['api.aliases'] = array('membership_type');
- $params['status_id']['api.aliases'] = array('membership_status');
- $params['skipStatusCal'] = array(
+ $params['membership_type_id']['api.aliases'] = ['membership_type'];
+ $params['status_id']['api.aliases'] = ['membership_status'];
+ $params['skipStatusCal'] = [
'title' => 'Skip status calculation',
'description' => 'By default this is 0 if id is not set and 1 if it is set.',
'type' => CRM_Utils_Type::T_BOOLEAN,
- );
- $params['num_terms'] = array(
+ ];
+ $params['num_terms'] = [
'title' => 'Number of terms',
'description' => 'Terms to add/renew. If this parameter is passed, dates will be calculated automatically. If no id is passed (new membership) and no dates are given, num_terms will be assumed to be 1.',
'type' => CRM_Utils_Type::T_INT,
- );
+ ];
}
/**
* Array of parameters determined by getfields.
*/
function _civicrm_api3_membership_get_spec(&$params) {
- $params['membership_type_id']['api.aliases'] = array('membership_type');
- $params['active_only'] = array(
+ $params['membership_type_id']['api.aliases'] = ['membership_type'];
+ $params['active_only'] = [
'title' => 'Active Only',
'description' => 'Only retrieve active memberships',
'type' => CRM_Utils_Type::T_BOOLEAN,
- );
+ ];
}
/**
}
$activeOnly = CRM_Utils_Array::value('active_only', $params, $activeOnly);
if ($activeOnly && empty($params['status_id'])) {
- $params['status_id'] = array('IN' => CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent());
+ $params['status_id'] = ['IN' => CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent()];
}
$options = _civicrm_api3_get_options_from_params($params, TRUE, 'Membership', 'get');
*/
function _civicrm_api3_membership_get_customv2behaviour(&$params, $membershipTypeId, $activeOnly) {
// get the membership for the given contact ID
- $membershipParams = array('contact_id' => $params['contact_id']);
+ $membershipParams = ['contact_id' => $params['contact_id']];
if ($membershipTypeId) {
$membershipParams['membership_type_id'] = $membershipTypeId;
}
- $membershipValues = array();
+ $membershipValues = [];
CRM_Member_BAO_Membership::getValues($membershipParams, $membershipValues, $activeOnly);
return $membershipValues;
}
-
/**
* Non-standard behaviour inherited from v2.
*
* result for calling function
*/
function _civicrm_api3_membership_relationsship_get_customv2behaviour(&$params, $membershipValues, $contactID) {
- $relationships = array();
+ $relationships = [];
foreach ($membershipValues as $membershipId => $values) {
// populate the membership type name for the membership type id
$membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);