From: Kurund Jalmi Date: Thu, 2 May 2013 07:26:57 +0000 (-0700) Subject: worked on CRM-12463, more fixes X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=17db9f82012058c63b737e6770570ae693b47b11;p=civicrm-core.git worked on CRM-12463, more fixes --- diff --git a/CRM/Contribute/BAO/ContributionSoft.php b/CRM/Contribute/BAO/ContributionSoft.php index ff9f5ed431..115d1640e8 100644 --- a/CRM/Contribute/BAO/ContributionSoft.php +++ b/CRM/Contribute/BAO/ContributionSoft.php @@ -147,22 +147,28 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio * @static */ static function getSoftContribution($params, $all = FALSE) { + $pcpFields = array( + 'pcp_id', + 'pcp_display_in_roll', + 'pcp_roll_nickname', + 'pcp_personal_note', + ); + $cs = new CRM_Contribute_DAO_ContributionSoft(); $cs->copyValues($params); $softContribution = array(); $cs->find(); + if ($cs->N > 0) { while ($cs->fetch()) { - if ($all) { - foreach (array( - 'pcp_id', 'pcp_display_in_roll', 'pcp_roll_nickname', 'pcp_personal_note') as $key => $val) { - $softContribution[$val] = $cs->$val; + foreach ($pcpFields as $val) { + $softContribution['pcp'][$val] = $cs->$val; } } - $softContribution[$cs->id]['soft_credit_to'] = $cs->contact_id; - $softContribution[$cs->id]['soft_credit_id'] = $cs->id; - $softContribution[$cs->id]['soft_credit_amount'] = $cs->amount; + $softContribution['soft_credit'][$cs->id]['soft_credit_to'] = $cs->contact_id; + $softContribution['soft_credit'][$cs->id]['soft_credit_id'] = $cs->id; + $softContribution['soft_credit'][$cs->id]['soft_credit_amount'] = $cs->amount; } } return $softContribution; diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index fb4eaecfc3..459cd53e15 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -140,6 +140,11 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP */ public $_lineItems; + /** + * @var soft credit info + */ + public $_softCreditInfo; + protected $_formType; protected $_cdType; @@ -296,7 +301,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } // set soft credit defaults - CRM_Contribute_Form_SoftCredit::setDefaultValues($defaults); + CRM_Contribute_Form_SoftCredit::setDefaultValues($defaults, $this); if ($this->_mode) { $config = CRM_Core_Config::singleton(); @@ -491,7 +496,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $showAdditionalInfo = FALSE; - $defaults = $this->_values; $additionalDetailFields = array( 'note', diff --git a/CRM/Contribute/Form/ContributionView.php b/CRM/Contribute/Form/ContributionView.php index d8ab2223ac..e909556b9c 100644 --- a/CRM/Contribute/Form/ContributionView.php +++ b/CRM/Contribute/Form/ContributionView.php @@ -132,7 +132,7 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form { $softParams = array('contribution_id' => CRM_Utils_Array::value('contribution_id', $values)); $softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($softParams); if (!empty($softContribution)) { - foreach($softContribution as &$individualSoftContribution) { + foreach($softContribution['soft_credit'] as &$individualSoftContribution) { $individualSoftContribution['softCreditToName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $individualSoftContribution['soft_credit_to'], 'display_name' ); diff --git a/CRM/Contribute/Form/SoftCredit.php b/CRM/Contribute/Form/SoftCredit.php index a672e788c0..d6bd8fd1cd 100644 --- a/CRM/Contribute/Form/SoftCredit.php +++ b/CRM/Contribute/Form/SoftCredit.php @@ -49,15 +49,27 @@ class CRM_Contribute_Form_SoftCredit { static function buildQuickForm(&$form) { $prefix = 'soft_credit_'; // by default generate 5 blocks - $form->_softCredit['item_count'] = 6; - for ($rowNumber = 1; $rowNumber <= $form->_softCredit['item_count']; $rowNumber++) { + $item_count = 6; + + if ($form->_action & CRM_Core_Action::UPDATE) { + $csParams = array('contribution_id' => $form->_id); + $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($csParams, TRUE); + $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']); + $showSoftCreditRow++; + } + else { + $showSoftCreditRow = 2; + } + + for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) { CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, $prefix); $form->addMoney("{$prefix}amount[{$rowNumber}]", ts('Amount')); } - $form->assign('rowCount', $form->_softCredit['item_count']); + $form->assign('showSoftCreditRow', $showSoftCreditRow); + $form->assign('rowCount', $item_count); - // Tell tpl to hide Soft Credit field if contribution is linked directly to a PCP Page + // Tell tpl to hide soft credit field if contribution is linked directly to a PCP Page if (CRM_Utils_Array::value('pcp_made_through_id', $form->_values)) { $form->assign('pcpLinked', 1); } @@ -67,10 +79,12 @@ class CRM_Contribute_Form_SoftCredit { /** * Function used to set defaults for soft credit block */ - static function setDefaultValues(&$defaults) { - $csParams = array('contribution_id' => $defaults['id']); - $softCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($csParams, TRUE); + static function setDefaultValues(&$defaults, &$form) { + + //crm_core_error::debug('$form->_softCreditInfo', $form->_softCreditInfo); + //exit; + /* if (CRM_Utils_Array::value('soft_credit_to', $softCredit)) { $softCredit['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $softCredit['soft_credit_to'], 'sort_name' @@ -79,16 +93,18 @@ class CRM_Contribute_Form_SoftCredit { $values['soft_credit_to'] = CRM_Utils_Array::value('sort_name', $softCredit); $values['softID'] = CRM_Utils_Array::value('soft_credit_id', $softCredit); $values['soft_contact_id'] = CRM_Utils_Array::value('soft_credit_to', $softCredit); + */ - if (CRM_Utils_Array::value('pcp_id', $softCredit)) { - $pcpId = CRM_Utils_Array::value('pcp_id', $softCredit); + if (CRM_Utils_Array::value('pcp_id', $form->_softCreditInfo['pcp'])) { + $pcpInfo = $form->_softCreditInfo['pcp']; + $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'); - $values['pcp_made_through'] = CRM_Utils_Array::value('sort_name', $softCredit) . " :: " . $pcpTitle . " :: " . $contributionPageTitle; - $values['pcp_made_through_id'] = CRM_Utils_Array::value('pcp_id', $softCredit); - $values['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $softCredit); - $values['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $softCredit); - $values['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $softCredit); + $values['pcp_made_through'] = CRM_Utils_Array::value('sort_name', $pcpInfo) . " :: " . $pcpTitle . " :: " . $contributionPageTitle; + $values['pcp_made_through_id'] = CRM_Utils_Array::value('pcp_id', $pcpInfo); + $values['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcpInfo); + $values['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcpInfo); + $values['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcpInfo); } } diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index aa8e405a29..9d55936693 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -231,12 +231,12 @@ {if $siteHasPCPs} -
{ts}credit this contribution to a personal campaign page{/ts}{help id="id-link_pcp"} + - + {$form.pcp_made_through.label} {$form.pcp_made_through.html}   diff --git a/templates/CRM/Contribute/Form/ContributionView.tpl b/templates/CRM/Contribute/Form/ContributionView.tpl index 4b218284a8..cb23e46dc0 100644 --- a/templates/CRM/Contribute/Form/ContributionView.tpl +++ b/templates/CRM/Contribute/Form/ContributionView.tpl @@ -208,7 +208,7 @@
- {foreach from=$softContributions item="softCont"} + {foreach from=$softContributions.soft_credit item="softCont"} {if $softCont } diff --git a/templates/CRM/Contribute/Form/SoftCredit.js b/templates/CRM/Contribute/Form/SoftCredit.js index 548c4bcb95..ae8ac9a9a0 100644 --- a/templates/CRM/Contribute/Form/SoftCredit.js +++ b/templates/CRM/Contribute/Form/SoftCredit.js @@ -1,6 +1,5 @@ // http://civicrm.org/licensing cj(function($) { - $('.crm-contribution-pcp-block').hide(); $('#showPCP, #showSoftCredit').click(function(){ return showHideSoftCreditAndPCP(); }); diff --git a/templates/CRM/Contribute/Form/SoftCredit.tpl b/templates/CRM/Contribute/Form/SoftCredit.tpl index 53ac6fadc4..eb8d237158 100644 --- a/templates/CRM/Contribute/Form/SoftCredit.tpl +++ b/templates/CRM/Contribute/Form/SoftCredit.tpl @@ -28,7 +28,7 @@
{ts}Soft Credit To{/ts}
{section name='i' start=1 loop=$rowCount} {assign var='rowNumber' value=$smarty.section.i.index} - +
{ts}Soft Credit To{/ts} {include file="CRM/Contact/Form/NewContact.tpl" noLabel=true skipBreak=true blockNo=$rowNumber