CRM-12463 (BAO cleanup)
authoryashodha <yashodha.chaku@webaccess.co.in>
Wed, 1 May 2013 23:55:32 +0000 (05:25 +0530)
committeryashodha <yashodha.chaku@webaccess.co.in>
Thu, 2 May 2013 04:25:15 +0000 (09:55 +0530)
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/BAO/ContributionSoft.php
CRM/Contribute/Form/AbstractEditPayment.php
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/ContributionView.php
CRM/Contribute/Import/Parser/Contribution.php
CRM/Contribute/Page/Tab.php
api/v3/Contribution.php

index e92fe3a1ad52d0e096cbf67f3019842f95cf5cf0..81ade798e02203858e58bcf7aab3ef7581f078ad 100644 (file)
@@ -1178,156 +1178,6 @@ LEFT JOIN civicrm_option_value contribution_status ON (civicrm_contribution.cont
     return $address->id;
   }
 
-  /**
-   *  Function to create soft contributon with contribution record.
-   *  @param array $params an associated array
-   *
-   *  @return soft contribution id
-   *  @static
-   */
-  static function addSoftContribution($params) {
-    $softContribution = new CRM_Contribute_DAO_ContributionSoft();
-    $softContribution->copyValues($params);
-
-    // set currency for CRM-1496
-    if (!isset($softContribution->currency)) {
-      $config = CRM_Core_Config::singleton();
-      $softContribution->currency = $config->defaultCurrency;
-    }
-
-    return $softContribution->save();
-  }
-
-  /**
-   *  Function to retrieve soft contributions for contribution record.
-   *  @param array $params an associated array
-   *  @param boolean $all include PCP data
-   *
-   *  @return array of soft contribution ids, amounts, and associated contact ids
-   *  @static
-   */
-  static function getSoftContribution($params, $all = FALSE) {
-    $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;
-          }
-        }
-        $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;
-      }
-    }
-    return $softContribution;
-  }
-
-  /**
-   *  Function to retrieve the list of soft contributons for given contact.
-   *  @param int $contact_id contact id
-   *
-   *  @return array
-   *  @static
-   */
-  static function getSoftContributionList($contact_id, $isTest = 0) {
-    $query = "
-    SELECT ccs.id, ccs.amount as amount,
-                     ccs.contribution_id,
-                     ccs.pcp_id,
-                     ccs.pcp_display_in_roll,
-                     ccs.pcp_roll_nickname,
-                     ccs.pcp_personal_note,
-                     cc.receive_date,
-                     cc.contact_id as contributor_id,
-                     cc.contribution_status_id as contribution_status_id,
-                     cp.title as pcp_title,
-                     cc.currency,
-                     contact.display_name,
-                     cct.name as contributionType
-              FROM civicrm_contribution_soft ccs
-                   LEFT JOIN civicrm_contribution cc
-                          ON ccs.contribution_id = cc.id
-                   LEFT JOIN civicrm_pcp cp
-                          ON ccs.pcp_id = cp.id
-                   LEFT JOIN civicrm_contact contact
-                          ON ccs.contribution_id = cc.id AND
-                             cc.contact_id = contact.id
-                       LEFT JOIN civicrm_financial_type cct
-                              ON cc.financial_type_id = cct.id
-         WHERE cc.is_test = %2 AND ccs.contact_id = %1
-         ORDER BY cc.receive_date DESC";
-
-    $params             = array(1 => array($contact_id, 'Integer'),
-                                2 => array($isTest, 'Integer'));
-    $cs                 = CRM_Core_DAO::executeQuery($query, $params);
-    $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
-    $result             = array();
-    while ($cs->fetch()) {
-      $result[$cs->id]['amount'] = $cs->amount;
-      $result[$cs->id]['currency'] = $cs->currency;
-      $result[$cs->id]['contributor_id'] = $cs->contributor_id;
-      $result[$cs->id]['contribution_id'] = $cs->contribution_id;
-      $result[$cs->id]['contributor_name'] = $cs->display_name;
-      $result[$cs->id]['financial_type'] = $cs->contributionType;
-      $result[$cs->id]['receive_date'] = $cs->receive_date;
-      $result[$cs->id]['pcp_id'] = $cs->pcp_id;
-      $result[$cs->id]['pcp_title'] = $cs->pcp_title;
-      $result[$cs->id]['pcp_display_in_roll'] = $cs->pcp_display_in_roll;
-      $result[$cs->id]['pcp_roll_nickname'] = $cs->pcp_roll_nickname;
-      $result[$cs->id]['pcp_personal_note'] = $cs->pcp_personal_note;
-      $result[$cs->id]['contribution_status'] = CRM_Utils_Array::value($cs->contribution_status_id, $contributionStatus);
-
-      if ($isTest) {
-        $result[$cs->id]['contribution_status'] = $result[$cs->id]['contribution_status'] . '<br /> (test)';
-      }
-    }
-    return $result;
-  }
-
-  static function getSoftContributionTotals($contact_id, $isTest = 0) {
-    $query = "
-    SELECT SUM(amount) as amount,
-                         AVG(total_amount) as average,
-                         cc.currency
-                  FROM civicrm_contribution_soft  ccs
-                       LEFT JOIN civicrm_contribution cc
-                              ON ccs.contribution_id = cc.id
-    WHERE cc.is_test = %2 AND
-          ccs.contact_id = %1
-                  GROUP BY currency ";
-
-    $params = array(1 => array($contact_id, 'Integer'),
-                    2 => array($isTest, 'Integer'));
-
-    $cs = CRM_Core_DAO::executeQuery($query, $params);
-
-    $count = 0;
-    $amount = $average = array();
-
-    while ($cs->fetch()) {
-      if ($cs->amount > 0) {
-        $count++;
-        $amount[]   = $cs->amount;
-        $average[]  = $cs->average;
-        $currency[] = $cs->currency;
-      }
-    }
-
-    if ($count > 0) {
-      return array(implode(',&nbsp;', $amount),
-        implode(',&nbsp;', $average),
-        implode(',&nbsp;', $currency),
-      );
-    }
-    return array(0, 0);
-  }
-
   /**
    * Delete billing address record related contribution
    *
index 29ff23aa6cbdaf06490045e4520341f845772076..ff9f5ed431f26c95b613ba2d52c78d045efbe13f 100644 (file)
@@ -53,6 +53,12 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
   public static function add(&$params) {
     $contributionSoft = new CRM_Contribute_DAO_ContributionSoft();
     $contributionSoft->copyValues($params);
+
+    // set currency for CRM-1496
+    if (!isset($contributionSoft->currency)) {
+      $config = CRM_Core_Config::singleton();
+      $contributionSoft->currency = $config->defaultCurrency;
+    }
     return $contributionSoft->save();
   }
 
@@ -92,5 +98,138 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
     $contributionSoft->contribution_id = $contributionID;
     $contributionSoft->delete();
   }
+
+
+  static function getSoftContributionTotals($contact_id, $isTest = 0) {
+    $query = "
+    SELECT SUM(amount) as amount,
+                         AVG(total_amount) as average,
+                         cc.currency
+                  FROM civicrm_contribution_soft  ccs
+                       LEFT JOIN civicrm_contribution cc
+                              ON ccs.contribution_id = cc.id
+    WHERE cc.is_test = %2 AND
+          ccs.contact_id = %1
+                  GROUP BY currency ";
+
+    $params = array(1 => array($contact_id, 'Integer'),
+      2 => array($isTest, 'Integer'));
+
+    $cs = CRM_Core_DAO::executeQuery($query, $params);
+
+    $count = 0;
+    $amount = $average = array();
+
+    while ($cs->fetch()) {
+      if ($cs->amount > 0) {
+        $count++;
+        $amount[]   = $cs->amount;
+        $average[]  = $cs->average;
+        $currency[] = $cs->currency;
+      }
+    }
+
+    if ($count > 0) {
+      return array(implode(',&nbsp;', $amount),
+        implode(',&nbsp;', $average),
+        implode(',&nbsp;', $currency),
+      );
+    }
+    return array(0, 0);
+  }
+
+  /**
+   *  Function to retrieve soft contributions for contribution record.
+   *  @param array $params an associated array
+   *  @param boolean $all include PCP data
+   *
+   *  @return array of soft contribution ids, amounts, and associated contact ids
+   *  @static
+   */
+  static function getSoftContribution($params, $all = FALSE) {
+    $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;
+          }
+        }
+        $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;
+      }
+    }
+    return $softContribution;
+  }
+
+  /**
+   *  Function to retrieve the list of soft contributons for given contact.
+   *  @param int $contact_id contact id
+   *
+   *  @return array
+   *  @static
+   */
+  static function getSoftContributionList($contact_id, $isTest = 0) {
+    $query = "
+    SELECT ccs.id, ccs.amount as amount,
+                     ccs.contribution_id,
+                     ccs.pcp_id,
+                     ccs.pcp_display_in_roll,
+                     ccs.pcp_roll_nickname,
+                     ccs.pcp_personal_note,
+                     cc.receive_date,
+                     cc.contact_id as contributor_id,
+                     cc.contribution_status_id as contribution_status_id,
+                     cp.title as pcp_title,
+                     cc.currency,
+                     contact.display_name,
+                     cct.name as contributionType
+              FROM civicrm_contribution_soft ccs
+                   LEFT JOIN civicrm_contribution cc
+                          ON ccs.contribution_id = cc.id
+                   LEFT JOIN civicrm_pcp cp
+                          ON ccs.pcp_id = cp.id
+                   LEFT JOIN civicrm_contact contact
+                          ON ccs.contribution_id = cc.id AND
+                             cc.contact_id = contact.id
+                       LEFT JOIN civicrm_financial_type cct
+                              ON cc.financial_type_id = cct.id
+         WHERE cc.is_test = %2 AND ccs.contact_id = %1
+         ORDER BY cc.receive_date DESC";
+
+    $params             = array(1 => array($contact_id, 'Integer'),
+      2 => array($isTest, 'Integer'));
+    $cs                 = CRM_Core_DAO::executeQuery($query, $params);
+    $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
+    $result             = array();
+    while ($cs->fetch()) {
+      $result[$cs->id]['amount'] = $cs->amount;
+      $result[$cs->id]['currency'] = $cs->currency;
+      $result[$cs->id]['contributor_id'] = $cs->contributor_id;
+      $result[$cs->id]['contribution_id'] = $cs->contribution_id;
+      $result[$cs->id]['contributor_name'] = $cs->display_name;
+      $result[$cs->id]['financial_type'] = $cs->contributionType;
+      $result[$cs->id]['receive_date'] = $cs->receive_date;
+      $result[$cs->id]['pcp_id'] = $cs->pcp_id;
+      $result[$cs->id]['pcp_title'] = $cs->pcp_title;
+      $result[$cs->id]['pcp_display_in_roll'] = $cs->pcp_display_in_roll;
+      $result[$cs->id]['pcp_roll_nickname'] = $cs->pcp_roll_nickname;
+      $result[$cs->id]['pcp_personal_note'] = $cs->pcp_personal_note;
+      $result[$cs->id]['contribution_status'] = CRM_Utils_Array::value($cs->contribution_status_id, $contributionStatus);
+
+      if ($isTest) {
+        $result[$cs->id]['contribution_status'] = $result[$cs->id]['contribution_status'] . '<br /> (test)';
+      }
+    }
+    return $result;
+  }
+
+
 }
 
index 6c0cbf759755b9343498a4ab1deb8db1be15ccb0..938e26acc1d0ded4b506a13964fc96a07f450b1f 100644 (file)
@@ -192,7 +192,7 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Core_Form {
     $this->_contributionType = $values['financial_type_id'];
 
     $csParams = array('contribution_id' => $id);
-    $softCredit = CRM_Contribute_BAO_Contribution::getSoftContribution($csParams, TRUE);
+    $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',
index ca96a812fd02c53f37f3b1508a082237c7df77b8..12aed7feb5dca9f271bb85fb6d6b45b8d2cf644b 100644 (file)
@@ -1697,7 +1697,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
       // add pcp id
       $contribSoftParams['pcp_id'] = $params['pcp_made_through_id'];
 
-      $softContribution = CRM_Contribute_BAO_Contribution::addSoftContribution($contribSoftParams);
+      $softContribution = CRM_Contribute_BAO_ContributionSoft::add($contribSoftParams);
     }
   }
 
index d24bca8ed5a2fce664cca4afd1db570122d82fe4..d8ab2223ac1dbffed907025a1d8318e805fc7c53 100644 (file)
@@ -130,7 +130,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_Contribution::getSoftContribution($softParams);
+    $softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($softParams);
     if (!empty($softContribution)) {
       foreach($softContribution as &$individualSoftContribution) {
         $individualSoftContribution['softCreditToName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
index 3de0470e79a8bf73932beed44c0895732d670b75..3eb438a3c90d99368998c7173871c53adc1a2a3a 100644 (file)
@@ -387,7 +387,7 @@ class CRM_Contribute_Import_Parser_Contribution extends CRM_Contribute_Import_Pa
               'contact_id' => $formatted['soft_credit_to'],
               'contribution_id' => $ids['contribution'],
             );
-            $existingSoftCredit = CRM_Contribute_BAO_Contribution::getSoftContribution($dupeSoftCredit);
+            $existingSoftCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($dupeSoftCredit);
             if (CRM_Utils_Array::value('soft_credit_id', $existingSoftCredit)) {
               $formatted['softID'] = $existingSoftCredit['soft_credit_id'];
             }
index 0cf65a2860a984e0823298531eeaadcce6b2c770..85a969589e1e6e7563a6c8ef484bd1c6bd788180 100644 (file)
@@ -237,7 +237,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
     }
     $this->assign('isTest', $isTest);
 
-    $softCreditList = CRM_Contribute_BAO_Contribution::getSoftContributionList($this->_contactId, $isTest);
+    $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, $isTest);
 
     if (!empty($softCreditList)) {
       $softCreditTotals = array();
@@ -245,7 +245,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
       list($softCreditTotals['amount'],
         $softCreditTotals['avg'],
         $softCreditTotals['currency']
-      ) = CRM_Contribute_BAO_Contribution::getSoftContributionTotals($this->_contactId, $isTest);
+      ) = CRM_Contribute_BAO_ContributionSoft::getSoftContributionTotals($this->_contactId, $isTest);
 
       $this->assign('softCredit', TRUE);
       $this->assign('softCreditRows', $softCreditList);
index 71b42849edf954d882f6dd75471fd9ce4ced99c5..65b006cd41fd5b75cf6dd888f860bcd6d6d4e41a 100644 (file)
@@ -200,7 +200,7 @@ function civicrm_api3_contribution_get($params) {
     //CRM-8662
     $contribution_details = $query->store ( $dao );
     $soft_params = array('contribution_id' => $dao->contribution_id);
-    $soft_contribution = CRM_Contribute_BAO_Contribution::getSoftContribution ( $soft_params , true);
+    $soft_contribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution ( $soft_params , true);
     $contribution [$dao->contribution_id] = array_merge($contribution_details, $soft_contribution);
   }
   return civicrm_api3_create_success($contribution, $params, 'contribution', 'get', $dao);