From 76ca33459ca96a5e63fa15a1e0d0efae4e5e2e01 Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Fri, 3 May 2013 00:05:21 -0700 Subject: [PATCH] more work on CRM-12463, fixed api for backward compatibility --- CRM/Contribute/BAO/ContributionSoft.php | 2 +- CRM/Contribute/Form/SoftCredit.php | 4 ++-- api/v3/Contribution.php | 28 ++++++++++++++++++------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CRM/Contribute/BAO/ContributionSoft.php b/CRM/Contribute/BAO/ContributionSoft.php index 102540d670..1039a0bd12 100644 --- a/CRM/Contribute/BAO/ContributionSoft.php +++ b/CRM/Contribute/BAO/ContributionSoft.php @@ -164,7 +164,7 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio while ($dao->fetch()) { if ($all) { foreach ($pcpFields as $val) { - $softContribution['pcp'][$val] = $dao->$val; + $softContribution[$val] = $dao->$val; } } diff --git a/CRM/Contribute/Form/SoftCredit.php b/CRM/Contribute/Form/SoftCredit.php index 22d653083b..5958e80109 100644 --- a/CRM/Contribute/Form/SoftCredit.php +++ b/CRM/Contribute/Form/SoftCredit.php @@ -93,8 +93,8 @@ class CRM_Contribute_Form_SoftCredit { } } - if (CRM_Utils_Array::value('pcp_id', $form->_softCreditInfo['pcp'])) { - $pcpInfo = $form->_softCreditInfo['pcp']; + if (CRM_Utils_Array::value('pcp_id', $form->_softCreditInfo)) { + $pcpInfo = $form->_softCreditInfo; $pcpId = CRM_Utils_Array::value('pcp_id', $pcpInfo); $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title'); $contributionPageTitle = CRM_PCP_BAO_PCP::getPcpPageTitle($pcpId, 'contribute'); diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index 65b006cd41..3023f47151 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -198,14 +198,28 @@ function civicrm_api3_contribution_get($params) { $contribution = array(); while ($dao->fetch()) { //CRM-8662 - $contribution_details = $query->store ( $dao ); - $soft_params = array('contribution_id' => $dao->contribution_id); - $soft_contribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution ( $soft_params , true); - $contribution [$dao->contribution_id] = array_merge($contribution_details, $soft_contribution); + $contribution_details = $query->store($dao); + $softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($dao->contribution_id , TRUE); + $contribution[$dao->contribution_id] = array_merge($contribution_details, $softContribution); + + // format soft credit for backward compatibility + _civicrm_api3_format_soft_credit($contribution[$dao->contribution_id]); } return civicrm_api3_create_success($contribution, $params, 'contribution', 'get', $dao); } +/** + * This function is used to format the soft credit for backward compatibility + * as of v4.4 we support multiple soft credit, so now contribution returns array with 'soft_credit' as key + * but we still return first soft credit as a part of contribution array + */ +function _civicrm_api3_format_soft_credit(&$contribution) { + if (!empty($contribution['soft_credit'])) { + $contribution['soft_credit_to'] = $contribution['soft_credit'][1]['contact_id']; + $contribution['soft_credit_id'] = $contribution['soft_credit'][1]['soft_credit_id']; + } +} + /** * Adjust Metadata for Get action * @@ -355,12 +369,12 @@ function civicrm_api3_contribution_transact($params) { function civicrm_api3_contribution_sendconfirmation($params) { $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $params['id']; - if (! $contribution->find(true)) { + if (! $contribution->find(TRUE)) { throw new Exception('Contribution does not exist'); } $input = $ids = $cvalues = array('receipt_from_email' => $params['receipt_from_email']); - $contribution->loadRelatedObjects($input, $ids, FALSE, true); - $contribution->composeMessageArray($input, $ids, $cvalues, false, false); + $contribution->loadRelatedObjects($input, $ids, FALSE, TRUE); + $contribution->composeMessageArray($input, $ids, $cvalues, FALSE, FALSE); } /** -- 2.25.1