<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 5 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | Copyright CiviCRM LLC. All rights reserved. |
| |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
* 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']);