From dc7b39dfba6b570eb6a013695f6984251320e986 Mon Sep 17 00:00:00 2001 From: Johan Vervloet Date: Thu, 8 Sep 2016 12:24:45 +0200 Subject: [PATCH] CRM-19325 - enable search for contributions that are not in any batch. --- CRM/Contact/BAO/Query.php | 6 ++++++ CRM/Contribute/BAO/Query.php | 9 ++++++++- CRM/Contribute/Form/Search.php | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 2f76936e54..d605ca5bb8 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1744,6 +1744,12 @@ class CRM_Contact_BAO_Query { ) { $result = array($id, 'IN', $values, 0, $wildcard); } + // Hack for CRM-19325. This is ugly because it creates a dependency + // to the form, that returns the string 'NULL' if the user wants + // contributions that are not contained in any batch. + else if ($id == 'contribution_batch_id' && $values == 'NULL') { + $result = array($id, 'IS', 'NULL', 0, 0); + } else { $result = array($id, '=', $values, 0, $wildcard); } diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 85f1f32cdb..d8c601f4df 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -568,6 +568,9 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { case 'contribution_batch_id': $batches = CRM_Contribute_PseudoConstant::batch(); + // The key 'NULL' indicates that the user is looking for contributions + // that are not contained in a batch, see CRM-19325. + $batches['NULL'] = ts('(none)'); $query->_where[$grouping][] = " civicrm_entity_batch.batch_id $op $value"; $query->_qill[$grouping][] = ts('Batch Name %1 %2', array(1 => $op, 2 => $batches[$value])); $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1; @@ -1123,7 +1126,11 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { if (!empty($batches)) { $form->add('select', 'contribution_batch_id', ts('Batch Name'), - array('' => ts('- any -')) + $batches, + array( + '' => ts('- any -'), + // CRM-19325 + 'NULL' => ts('None'), + ) + $batches, FALSE, array('class' => 'crm-select2') ); } diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index a2b8b89861..016ef856ff 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -337,6 +337,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { ); } + // Why is this called twice? (see line 317) $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector = new CRM_Contribute_Selector_Search($this->_queryParams, $this->_action, -- 2.25.1