worked on CRM-12463, more cleanup
authorKurund Jalmi <kurund@civicrm.org>
Thu, 2 May 2013 21:31:49 +0000 (14:31 -0700)
committerKurund Jalmi <kurund@civicrm.org>
Thu, 2 May 2013 21:31:49 +0000 (14:31 -0700)
CRM/Contribute/BAO/ContributionSoft.php
CRM/Contribute/Form/ContributionView.php
CRM/Contribute/Form/SoftCredit.php
CRM/Contribute/Import/Parser/Contribution.php
templates/CRM/Contribute/Form/ContributionView.tpl

index 77ce7a3868f3b90514c29fd7ec5e7f8136eb9e31..102540d67008b9b585b56b171ae1fbbe0f697ae6 100644 (file)
@@ -141,7 +141,7 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
    *  @return array of soft contribution ids, amounts, and associated contact ids
    *  @static
    */
-  static function getSoftContribution($params, $all = FALSE) {
+  static function getSoftContribution($contributionID, $all = FALSE) {
     $pcpFields = array(
       'pcp_id',
       'pcp_display_in_roll',
@@ -149,6 +149,36 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
       'pcp_personal_note',
     );
 
+    $query = '
+    SELECT ccs.id, pcp_id, pcp_display_in_roll, pcp_roll_nickname, pcp_personal_note, amount, contact_id, c.display_name
+    FROM civicrm_contribution_soft ccs INNER JOIN civicrm_contact c on c.id = ccs.contact_id
+    WHERE contribution_id = %1;
+    ';
+
+    $params = array(1 => array($contributionID, 'Integer'));
+
+    $dao = CRM_Core_DAO::executeQuery($query, $params);
+
+    $softContribution = array();
+    $count = 1;
+    while ($dao->fetch()) {
+      if ($all) {
+        foreach ($pcpFields as $val) {
+          $softContribution['pcp'][$val] = $dao->$val;
+        }
+      }
+
+      $softContribution['soft_credit'][$count] = array(
+        'contact_id' => $dao->contact_id,
+        'soft_credit_id' => $dao->id,
+        'amount' => $dao->amount,
+        'contact_name' => $dao->display_name
+      );
+      $count++;
+    }
+
+    /*
+     * FIX API before deleting this
     $cs = new CRM_Contribute_DAO_ContributionSoft();
     $cs->copyValues($params);
     $softContribution = array();
@@ -171,6 +201,8 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
         $count++;
       }
     }
+    */
+
     return $softContribution;
   }
 
index e909556b9c769b0cc590a1d2b99a0b25d3ed51c8..be1fe301b6c5c8886e5dfb950e89b05bfe69a001 100644 (file)
@@ -129,22 +129,7 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
     }
 
     //get soft credit record if exists.
-    $softParams = array('contribution_id' => CRM_Utils_Array::value('contribution_id', $values));
-    $softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($softParams);
-    if (!empty($softContribution)) {
-      foreach($softContribution['soft_credit'] 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;
-    }
+    $values['softContributions'] = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id']);
 
     $lineItems = array();
     if ($id) {
index 2cc49b1f38cd560bc485f98f842d0b2fd23f67d7..2e6e2e2b0e2e8a2b9769a5592c19121263b16455 100644 (file)
@@ -54,8 +54,7 @@ class CRM_Contribute_Form_SoftCredit {
     $showSoftCreditRow = 2;
     $showCreateNew = true;
     if ($form->_action & CRM_Core_Action::UPDATE) {
-      $csParams = array('contribution_id' => $form->_id);
-      $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($csParams, TRUE);
+      $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE);
       if (!empty($form->_softCreditInfo['soft_credit'])) {
         $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
         $showSoftCreditRow++;
index 3eb438a3c90d99368998c7173871c53adc1a2a3a..7e695d28580b3b48d91e59b9cd48b999c4bb2277 100644 (file)
@@ -387,6 +387,8 @@ class CRM_Contribute_Import_Parser_Contribution extends CRM_Contribute_Import_Pa
               'contact_id' => $formatted['soft_credit_to'],
               'contribution_id' => $ids['contribution'],
             );
+            
+            //FIXE ME: Need to fix this logic
             $existingSoftCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($dupeSoftCredit);
             if (CRM_Utils_Array::value('soft_credit_id', $existingSoftCredit)) {
               $formatted['softID'] = $existingSoftCredit['soft_credit_id'];
index cb23e46dc094f6063fc77d85442893160b63d6be..210862dc32ea9e07cb599a64c2ea0889d3a7d050 100644 (file)
     <div class="crm-accordion-body">
       <table class="crm-info-panel">
         {foreach from=$softContributions.soft_credit 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=`$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>{$softCont.soft_credit_amount|crmMoney:$currency}</td>
-            </tr>
-          {/if}
+          <tr>
+            <td>
+              <a href="{crmURL p="civicrm/contact/view" q="reset=1&cid=`$softCont.contact_id`"}"
+                 id="view_contact" title="{ts}View contact record{/ts}">{$softCont.contact_name}
+              </a>
+            </td>
+            <td>{$softCont.amount|crmMoney:$currency}</td>
+          </tr>
         {/foreach}
       </table>
     </div>