Add support to Contribution view for multiple soft credits
authorJon goldberg - Linux laptop <jon@palantetech.coop>
Tue, 30 Apr 2013 23:20:47 +0000 (16:20 -0700)
committerJon goldberg - Linux laptop <jon@palantetech.coop>
Tue, 30 Apr 2013 23:49:35 +0000 (16:49 -0700)
CRM/Contribute/Form/ContributionView.php
templates/CRM/Contribute/Form/ContributionView.tpl

index efed31503690a5c2a4263c41a036f9531c1dc953..d24bca8ed5a2fce664cca4afd1db570122d82fe4 100644 (file)
@@ -53,12 +53,6 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
     $this->assign('context', $context);
 
     CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids);
-
-    $softParams = array('contribution_id' => CRM_Utils_Array::value('contribution_id', $values));
-    $softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams, TRUE);
-//    if ($softContribution) {
-//      $values = array_merge($values, $softContribution);
-//    }
     CRM_Contribute_BAO_Contribution::resolveDefaults($values);
 
     if (CRM_Utils_Array::value('contribution_page_id', $values)) {
@@ -135,18 +129,21 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
     }
 
     //get soft credit record if exists.
-    //FIXME: The next line seems really inefficient.  Can't we just check the length of the array?
-    if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams)) {
-
-      $softContribution['softCreditToName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
-        $softContribution['soft_credit_to'], 'display_name'
-      );
-      //hack to avoid dispalyName conflict
-      //for viewing softcredit record.
-      $softContribution['displayName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
-        $values['contact_id'], 'display_name'
-      );
-      $values = array_merge($values, $softContribution);
+    $softParams = array('contribution_id' => CRM_Utils_Array::value('contribution_id', $values));
+    $softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams);
+    if (!empty($softContribution)) {
+      foreach($softContribution as &$individualSoftContribution) {
+        $individualSoftContribution['softCreditToName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
+          $individualSoftContribution['soft_credit_to'], 'display_name'
+        );
+        //hack to avoid displayName conflict
+        //for viewing softcredit record.
+        $individualSoftContribution['displayName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
+          $values['contact_id'], 'display_name'
+        );
+        
+      }
+      $values['softContributions'] = $softContribution;
     }
 
     $lineItems = array();
index 2b930414e29e7e519e7a4de6447370803cfc6359..34a0ea099d070f72a322012e2bbfd284da4512ff 100644 (file)
   {/if}
 </table>
 
-  {if $softCreditToName and !$pcp_id} {* We show soft credit name with PCP section if contribution is linked to a PCP. *}
+  {if $softContributions and !$pcp_id} {* We show soft credit name with PCP section if contribution is linked to a PCP. *}
     <div class="crm-accordion-wrapper ">
       <div class="crm-accordion-header">
           {ts}Soft Credit{/ts}
       </div>
       <div class="crm-accordion-body">
         <table class="crm-info-panel">
+    {foreach from=$softContributions item="softCont"}
+      {if $softCont }
           <tr>
             <td class="label">{ts}Soft Credit To{/ts}</td>
-            <td><a href="{crmURL p="civicrm/contact/view" q="reset=1&cid=`$soft_credit_to`"}" id="view_contact" title="{ts}View contact record{/ts}">{$softCreditToName}</a></td>
+            <td><a href="{crmURL p="civicrm/contact/view" q="reset=1&cid=`$softCont.soft_credit_to`"}" id="view_contact" title="{ts}View contact record{/ts}">{$softCont.softCreditToName}</a></td>
             <td class="label">{ts}Amount{/ts}</td>
-            <td>{$soft_credit_amount|crmMoney:$currency}</td>
+            <td>{$softCont.soft_credit_amount|crmMoney:$currency}</td>
           </tr>
+      {/if}
+    {/foreach}
         </table>
       </div>
     </div>