From 3086e282fefab459375894e610f7cc9d8b15c6b1 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Fri, 2 Dec 2016 15:06:58 +0530 Subject: [PATCH] optimization --- CRM/Contact/BAO/Query.php | 31 +++++++++++++++++-------------- CRM/Contribute/BAO/Query.php | 11 ++++------- CRM/Contribute/Form/Search.php | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index a4f81271c1..8d62303e79 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1744,12 +1744,6 @@ 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. - elseif ($id == 'contribution_batch_id' && $values == 'NULL') { - $result = array($id, 'IS', 'NULL', 0, 0); - } else { $result = array($id, '=', $values, 0, $wildcard); } @@ -5950,6 +5944,13 @@ AND displayRelType.is_active = 1 ) { $qillOperators = CRM_Core_SelectValues::getSearchBuilderOperators(); + //API usually have fieldValue format as array(operator => array(values)), + //so we need to separate operator out of fieldValue param + if (is_array($fieldValue) && in_array(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { + $op = key($fieldValue); + $fieldValue = $fieldValue[$op]; + } + // if Operator chosen is NULL/EMPTY then if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) { return array(CRM_Utils_Array::value($op, $qillOperators, $op), ''); @@ -5976,17 +5977,13 @@ AND displayRelType.is_active = 1 elseif ($daoName == 'CRM_Contact_DAO_Group' && $fieldName == 'id') { $pseudoOptions = CRM_Core_PseudoConstant::group(); } + elseif ($daoName == 'CRM_Batch_BAO_EntityBatch' && $fieldName == 'batch_id') { + $pseudoOptions = CRM_Contribute_PseudoConstant::batch(); + } elseif ($daoName) { $pseudoOptions = CRM_Core_PseudoConstant::get($daoName, $fieldName, $pseudoExtraParam); } - //API usually have fieldValue format as array(operator => array(values)), - //so we need to separate operator out of fieldValue param - if (is_array($fieldValue) && in_array(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { - $op = key($fieldValue); - $fieldValue = $fieldValue[$op]; - } - if (is_array($fieldValue)) { $qillString = array(); if (!empty($pseudoOptions)) { @@ -6061,6 +6058,9 @@ AND displayRelType.is_active = 1 * Array of fields whose name should be changed */ public static function processSpecialFormValue(&$formValues, $specialFields, $changeNames = array()) { + // Array of special fields whose value are considered only for NULL or EMPTY operators + $nullableFields = array('contribution_batch_id'); + foreach ($specialFields as $element) { $value = CRM_Utils_Array::value($element, $formValues); if ($value) { @@ -6071,7 +6071,10 @@ AND displayRelType.is_active = 1 } $formValues[$element] = array('IN' => $value); } - else { + elseif (in_array($value, array('IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY'))) { + $formValues[$element] = array($value => 1); + } + elseif (!in_array($element, $nullableFields)) { // if wildcard is already present return searchString as it is OR append and/or prepend with wildcard $isWilcard = strstr($value, '%') ? FALSE : CRM_Core_Config::singleton()->includeWildCardInName; $formValues[$element] = array('LIKE' => self::getWildCardedValue($isWilcard, 'LIKE', $value)); diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index d8c601f4df..b152dedf5c 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -567,12 +567,9 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { return; 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])); + list($qillOp, $qillValue) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Batch_BAO_EntityBatch', 'batch_id', $value, $op); + $query->_qill[$grouping][] = ts('Batch Name %1 %2', array(1 => $qillOp, 2 => $qillValue)); + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause('civicrm_entity_batch.batch_id', $op, $value); $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1; $query->_tables['contribution_batch'] = $query->_whereTables['contribution_batch'] = 1; return; @@ -1129,7 +1126,7 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { array( '' => ts('- any -'), // CRM-19325 - 'NULL' => ts('None'), + 'IS NULL' => ts('None'), ) + $batches, FALSE, array('class' => 'crm-select2') ); diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index 016ef856ff..8b78f7c092 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -280,6 +280,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { 'contribution_product_id', 'invoice_id', 'payment_instrument_id', + 'contribution_batch_id', ); CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, $specialParams); @@ -337,7 +338,6 @@ 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