Skip to content

Commit

Permalink
Fail more gracefully when attempting to use a soft credit filter but …
Browse files Browse the repository at this point in the history
…not including soft credits.

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
  • Loading branch information
eileenmcnaughton committed May 29, 2018
1 parent f6e74a0 commit a9cf37f
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions CRM/Report/Form/Contribute/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,26 +478,12 @@ public function statistics(&$rows) {
* 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();
Expand Down Expand Up @@ -577,6 +563,33 @@ public function postProcess() {
$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.
*
Expand Down

0 comments on commit a9cf37f

Please sign in to comment.