Fail more gracefully when attempting to use a soft credit filter but not including...
authoreileen <emcnaughton@wikimedia.org>
Fri, 25 May 2018 00:18:34 +0000 (12:18 +1200)
committereileen <emcnaughton@wikimedia.org>
Tue, 29 May 2018 11:08:54 +0000 (23:08 +1200)
For better or worse this report munges soft credits & contributions in a very wierd way.

It currently hard fails if you try to search for 'contributions only' but include
a soft credit criteria, although there appears to have been an effort to block this in the past.

It might be nice to add that filter but restructuring the report to make it testable
should be a pre-requisite for that - so for now, let's address the fatal

CRM/Report/Form/Contribute/Detail.php

index 8ce9d48a69f21fa6f6dd239ce4d206108c25312f..30bac47671731ec504869329bff513787ca5ce8e 100644 (file)
@@ -478,26 +478,12 @@ GROUP BY {$this->_aliases['civicrm_contribution']}.currency";
    * Soft credit functionality is not currently unit tested for this report.
    */
   public function postProcess() {
+    // @todo in order to make this report testable we need to remove this function override in favour of the
+    // functions called by the reportTemplate.getrows api - this requires a bit of tidy up!
     // get the acl clauses built before we assemble the query
     $this->buildACLClause($this->_aliases['civicrm_contact']);
 
     $this->beginPostProcess();
-    // CRM-18312 - display soft_credits and soft_credits_for column
-    // when 'Contribution or Soft Credit?' column is not selected
-    if (empty($this->_params['fields']['contribution_or_soft'])) {
-      $this->_params['fields']['contribution_or_soft'] = 1;
-      $this->noDisplayContributionOrSoftColumn = TRUE;
-    }
-
-    if (CRM_Utils_Array::value('contribution_or_soft_value', $this->_params) ==
-      'contributions_only' &&
-      !empty($this->_params['fields']['soft_credit_type_id'])
-    ) {
-      unset($this->_params['fields']['soft_credit_type_id']);
-      if (!empty($this->_params['soft_credit_type_id_value'])) {
-        $this->_params['soft_credit_type_id_value'] = array();
-      }
-    }
 
     // 1. use main contribution query to build temp table 1
     $sql = $this->buildQuery();
@@ -577,6 +563,33 @@ UNION ALL
     $this->endPostProcess($rows);
   }
 
+  /**
+   * Shared function for preliminary processing.
+   *
+   * This is called by the api / unit tests and the form layer and is
+   * the right place to do 'initial analysis of input'.
+   */
+  public function beginPostProcessCommon() {
+    // CRM-18312 - display soft_credits and soft_credits_for column
+    // when 'Contribution or Soft Credit?' column is not selected
+    if (empty($this->_params['fields']['contribution_or_soft'])) {
+      $this->_params['fields']['contribution_or_soft'] = 1;
+      $this->noDisplayContributionOrSoftColumn = TRUE;
+    }
+
+    if (CRM_Utils_Array::value('contribution_or_soft_value', $this->_params) ==
+      'contributions_only' &&
+      (!empty($this->_params['fields']['soft_credit_type_id'])
+      || !empty($this->_params['soft_credit_type_id_value']))
+    ) {
+      unset($this->_params['fields']['soft_credit_type_id']);
+      if (!empty($this->_params['soft_credit_type_id_value'])) {
+        $this->_params['soft_credit_type_id_value'] = array();
+        CRM_Core_Session::setStatus(ts('Is it not possible to filter on soft contribution type when not including soft credits.'));
+      }
+    }
+  }
+
   /**
    * Alter display of rows.
    *