From 5bbd985a368686a03870d7a4ae394446334789e3 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Wed, 4 Dec 2013 16:30:20 -0500 Subject: [PATCH] CRM-13908 - Contribution - Allow smart group creation from Aggregate Contribution search ---------------------------------------- * CRM-13908: http://issues.civicrm.org/jira/browse/CRM-13908 --- CRM/Contribute/BAO/Query.php | 37 ++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 2fd333a73c..2c59297b3d 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -303,12 +303,45 @@ class CRM_Contribute_BAO_Query { case 'financial_type_id': case 'financial_type': - $cType = $value; + // The financial_type_id might be an array (from aggregate contributions custom search) + // In this case, we need to change the query. + if (is_array($value)) { + $val = array(); + // Rebuild the array to get the data we're interested in as array + // values not array keys. + foreach ($value as $k => $v) { + if ($v) { + $val[] = $k; + } + } + if (count($val) > 1) { + // Overwrite $value so it works with an IN where statement. + $op = 'IN'; + $value = '(' . implode(',', $val) . ')'; + } + else { + // If we somehow have an empty array, just return + return; + } + } + $types = CRM_Contribute_PseudoConstant::financialType(); + + // Ensure we have a sensible string to display to the user. + $names = array(); + if (isset($val) && is_array($val)) { + foreach($val as $id) { + $names[] = $types[$id]; + } + } + else { + $names[] = $types[$value]; + } + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.financial_type_id", $op, $value, "Integer" ); - $query->_qill[$grouping ][] = ts('Financial Type - %1', array(1 => $types[$cType])); + $query->_qill[$grouping][] = ts('Financial Type %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names); $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1; return; -- 2.25.1