From a0cbe4fad7649eff91dfa9cf676869eedd440101 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Fri, 14 Aug 2015 12:47:39 +0530 Subject: [PATCH] CRM-17022 fix - Bug introduced in 4.6.6 breaks Grant Search https://issues.civicrm.org/jira/browse/CRM-17022 --- CRM/Activity/Form/Search.php | 3 +- CRM/Contact/BAO/Query.php | 4 ++- CRM/Grant/BAO/Query.php | 68 +++++------------------------------- CRM/Member/Form/Search.php | 11 ------ 4 files changed, 13 insertions(+), 73 deletions(-) diff --git a/CRM/Activity/Form/Search.php b/CRM/Activity/Form/Search.php index c58751dfa4..fa0a9db5d8 100644 --- a/CRM/Activity/Form/Search.php +++ b/CRM/Activity/Form/Search.php @@ -211,9 +211,8 @@ class CRM_Activity_Form_Search extends CRM_Core_Form_Search { if (is_array($value)) { if ($element == 'status_id') { unset($this->_formValues[$element]); - $element = 'activity_' . $element; + $this->_formValues['activity_' . $element] = $value; } - $this->_formValues[$element] = array('IN' => $value); } else { $this->_formValues[$element] = array('LIKE' => "%$value%"); diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 29f7dba93b..cad962f148 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1601,7 +1601,9 @@ class CRM_Contact_BAO_Query { } $result = array($id, 'IN', $values, 0, 0); } - elseif ($id == 'contact_type') { + elseif ($id == 'contact_type' || + (!empty($values) && is_array($values) && !in_array(key($values), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) + ) { $result = array($id, 'IN', $values, 0, $wildcard); } else { diff --git a/CRM/Grant/BAO/Query.php b/CRM/Grant/BAO/Query.php index 1a514166a4..3dae2c4ee2 100644 --- a/CRM/Grant/BAO/Query.php +++ b/CRM/Grant/BAO/Query.php @@ -184,72 +184,22 @@ class CRM_Grant_BAO_Query { case 'grant_type_id': case 'grant_type': - $grantTypes = CRM_Core_OptionGroup::values('grant_type'); - if (is_array($value)) { - foreach ($value as $k => $v) { - if ($v) { - $val[] = $v; - } - } - if (count($val) > 0) { - // Overwrite $value so it works with an IN where statement. - $op = 'IN'; - $value = '(' . implode(',', $val) . ')'; - } - } - if (!empty($val)) { - foreach ($val as $id) { - $names[] = CRM_Utils_Array::value($id, $grantTypes); - } - } - else { - if (!empty($value)) { - $names[] = $grantTypes[$value]; - } - } - - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause('civicrm_grant.grant_type_id', $op, $value, "Integer"); - - $query->_qill[$grouping][] = ts('Grant Type %2 %1', array( - 1 => implode(' ' . ts('or') . ' ', $names), - 2 => $op, - )); - $query->_tables['civicrm_grant'] = $query->_whereTables['civicrm_grant'] = 1; - - return; - case 'grant_status_id': case 'grant_status': - $grantStatus = CRM_Core_OptionGroup::values('grant_status'); - if (is_array($value)) { - foreach ($value as $k => $v) { - if ($v) { - $val[] = $v; - } - } - if (count($val) > 0) { - // Overwrite $value so it works with an IN where statement. - $op = 'IN'; - $value = '(' . implode(',', $val) . ')'; - } - } - if (!empty($val)) { - foreach ($val as $id) { - $names[] = CRM_Utils_Array::value($id, $grantStatus); - } + + if (strstr($name, 'type')) { + $name = 'grant_type_id'; + $label = 'Grant Type(s)'; } else { - if (!empty($value)) { - $names[] = $grantStatus[$value]; - } + $name = 'status_id'; + $label = 'Grant Status(s)'; } - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause('civicrm_grant.status_id', $op, $value, "Integer"); + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_grant.$name", $op, $value, "Integer"); - $query->_qill[$grouping][] = ts('Grant Status %2 %1', array( - 1 => implode(' ' . ts('or') . ' ', $names), - 2 => $op, - )); + list($qillop, $qillVal) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Grant_DAO_Grant', $name, $value, $op); + $query->_qill[$grouping][] = ts("%1 %2 %3", array(1 => $label, 2 => $qillop, 3 => $qillVal)); $query->_tables['civicrm_grant'] = $query->_whereTables['civicrm_grant'] = 1; return; diff --git a/CRM/Member/Form/Search.php b/CRM/Member/Form/Search.php index ff21324f5f..61b9921002 100644 --- a/CRM/Member/Form/Search.php +++ b/CRM/Member/Form/Search.php @@ -209,17 +209,6 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search { $this->_formValues["member_test"] = 0; } - $specialParams = array( - 'membership_status_id', - 'membership_type_id', - ); - foreach ($specialParams as $element) { - $value = CRM_Utils_Array::value($element, $this->_formValues); - if (!empty($value) && is_array($value)) { - $this->_formValues[$element] = array('IN' => $value); - } - } - CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues); $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); -- 2.25.1