Merge pull request #4637 from eileenmcnaughton/CRM-15670
[civicrm-core.git] / CRM / Contribute / BAO / ContributionSoft.php
index 39436c64091ee6f87b752a7141f818df55619977..c0a7ac8a107ee054d12e0596a284f89ff418ad64 100644 (file)
 class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_ContributionSoft {
 
   /**
-   * construct method
+   * Construct method
    */
   function __construct() {
     parent::__construct();
   }
 
   /**
-   * function to add contribution soft credit record
+   * Add contribution soft credit record
    *
    * @param array  $params (reference ) an assoc array of name/value pairs
    *
@@ -63,16 +63,12 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
   }
 
   /**
-   * Takes a bunch of params that are needed to match certain criteria and
-   * retrieves the relevant objects. Typically the valid params are only
-   * contact_id. We'll tweak this function to be more full featured over a period
-   * of time. This is the inverse function of create. It also stores all the retrieved
-   * values in the default array
+   * Fetch object based on array of properties
    *
    * @param array $params   (reference ) an assoc array of name/value pairs
    * @param array $defaults (reference ) an assoc array to hold the flattened values
    *
-   * @return object CRM_Contribute_BAO_ContributionSoft object
+   * @return CRM_Contribute_BAO_ContributionSoft object
    * @access public
    * @static
    */
@@ -87,9 +83,10 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
   }
 
   /**
-   * Function to delete soft credits
+   * Delete soft credits
+   *
+   * @param array $params
    *
-   * @param int $contributionTypeId
    * @static
    */
   static function del($params) {
@@ -101,6 +98,12 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
     $contributionSoft->delete();
   }
 
+  /**
+   * @param int $contact_id
+   * @param int $isTest
+   *
+   * @return array
+   */
   static function getSoftContributionTotals($contact_id, $isTest = 0) {
     $query = '
     SELECT SUM(amount) as amount, AVG(total_amount) as average, cc.currency
@@ -137,12 +140,13 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
   }
 
   /**
-   *  Function to retrieve soft contributions for contribution record.
-   *  @param array $params an associated array
-   *  @param boolean $all include PCP data
+   * Retrieve soft contributions for contribution record.
    *
-   *  @return array of soft contribution ids, amounts, and associated contact ids
-   *  @static
+   * @param int $contributionID
+   * @param boolean $all include PCP data
+   *
+   * @return array of soft contribution ids, amounts, and associated contact ids
+   * @static
    */
   static function getSoftContribution($contributionID, $all = FALSE) {
     $pcpFields = array(
@@ -193,6 +197,12 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
     return $softContribution;
   }
 
+  /**
+   * @param int $contributionID
+   * @param bool $isPCP
+   *
+   * @return array
+   */
   static function getSoftCreditIds($contributionID , $isPCP = FALSE) {
     $query = "
   SELECT id
@@ -203,6 +213,9 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
     if ($isPCP) {
       $query .= " AND pcp_id IS NOT NULL";
     }
+    else {
+      $query .= " AND pcp_id IS NULL";
+    }
     $params = array(1 => array($contributionID, 'Integer'));
 
     $dao = CRM_Core_DAO::executeQuery($query, $params);
@@ -219,12 +232,15 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
 
   /**
    *  Function to retrieve the list of soft contributions for given contact.
-   *  @param int $contact_id contact id
    *
-   *  @return array
-   *  @static
+   * @param int     $contact_id contact id
+   * @param int     $isTest
+   * @param string  $filter  additional filter criteria, later used in where clause
+   *
+   * @return array
+   * @static
    */
-  static function getSoftContributionList($contact_id, $isTest = 0) {
+  static function getSoftContributionList($contact_id, $filter = NULL, $isTest = 0) {
     $query = '
     SELECT ccs.id, ccs.amount as amount,
            ccs.contribution_id,
@@ -248,8 +264,15 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
       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';
+    ';
+
+    $where = "
+      WHERE cc.is_test = %2 AND ccs.contact_id = %1";
+    if ($filter) {
+      $where .= $filter;
+    }
+
+    $query .= "{$where} ORDER BY cc.receive_date DESC";
 
     $params = array(
       1 => array($contact_id, 'Integer'),
@@ -289,6 +312,12 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
    *  @static
    */
 
+  /**
+   * @param CRM_Core_Form $form
+   * @param array $params
+   * @param int $honoreeprofileId
+   * @param int $honorId
+   */
   static function formatHonoreeProfileFields($form, $params, $honoreeprofileId, $honorId = NULL) {
     $profileContactType = CRM_Core_BAO_UFGroup::getContactType($honoreeprofileId);
     $profileFields = CRM_Core_BAO_UFGroup::getFields($honoreeprofileId);