From: Kurund Jalmi Date: Thu, 2 May 2013 04:46:08 +0000 (-0700) Subject: more work on CRM-12463 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=dfbad3f794108901f01550abcacadc99a879b193;p=civicrm-core.git more work on CRM-12463 --- diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index 938e26acc1..78f6d64eb4 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -190,29 +190,6 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Core_Form { $values['note'] = $daoNote->note; } $this->_contributionType = $values['financial_type_id']; - - $csParams = array('contribution_id' => $id); - $softCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($csParams, TRUE); - - 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' - ); - } - $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); - $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); - } } /** diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 1701c4d3a2..fb4eaecfc3 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -151,9 +151,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP */ public function preProcess() { - $resources = CRM_Core_Resources::singleton(); - $resources->addScriptFile('civicrm', 'templates/CRM/Contribute/Form/SoftCredit.js'); - //check permission for action. if (!CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page')); @@ -168,6 +165,9 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP return; } + $resources = CRM_Core_Resources::singleton(); + $resources->addScriptFile('civicrm', 'templates/CRM/Contribute/Form/SoftCredit.js'); + $this->_formType = CRM_Utils_Array::value('formType', $_GET); // get price set id. @@ -271,7 +271,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container CRM_Utils_System::setTitle(ts('Contribution from') . ' ' . $displayName); } - } function setDefaultValues() { @@ -296,6 +295,9 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP return $defaults; } + // set soft credit defaults + CRM_Contribute_Form_SoftCredit::setDefaultValues($defaults); + if ($this->_mode) { $config = CRM_Core_Config::singleton(); // set default country from config if no country set @@ -497,7 +499,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP 'invoice_id', 'non_deductible_amount', 'fee_amount', - 'net_amount' + 'net_amount', ); foreach ($additionalDetailFields as $key) { if (!empty($defaults[$key])) { diff --git a/CRM/Contribute/Form/SoftCredit.php b/CRM/Contribute/Form/SoftCredit.php index c4a82a64c9..a672e788c0 100644 --- a/CRM/Contribute/Form/SoftCredit.php +++ b/CRM/Contribute/Form/SoftCredit.php @@ -63,5 +63,34 @@ class CRM_Contribute_Form_SoftCredit { } $form->addElement('hidden', 'soft_contact_id', '', array('id' => 'soft_contact_id')); } + + /** + * 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); + + 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' + ); + } + $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); + $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); + } + + } }