From 13b2708deb2e69fef4caca0c75a2893fece22a30 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 27 May 2015 14:36:06 +0100 Subject: [PATCH] Proposed fix for searching similar multi select values CRM-16575 --- CRM/Core/BAO/CustomQuery.php | 17 ++++++++++++++--- CRM/Report/Form.php | 8 ++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CRM/Core/BAO/CustomQuery.php b/CRM/Core/BAO/CustomQuery.php index 512b7595c4..717c50fe37 100644 --- a/CRM/Core/BAO/CustomQuery.php +++ b/CRM/Core/BAO/CustomQuery.php @@ -400,9 +400,20 @@ SELECT label, value else { $val = CRM_Utils_Type::escape($strtolower(trim($value)), 'String'); - if ($wildcard) { - $val = $strtolower(CRM_Core_DAO::escapeString($val)); - $val = "%$val%"; + $specialHTMLType = array( + 'CheckBox', + 'Multi-Select', + 'AdvMulti-Select', + 'Multi-Select State/Province', + 'Multi-Select Country', + ); + + if (in_array($field['html_type'], $specialHTMLType)) { + $val = "[[:cntrl:]]".$val."[[:cntrl:]]"; + $op = 'RLIKE'; + + } elseif ($wildcard) { + $val = "[[:cntrl:]]%$val%[[:cntrl:]]"; $op = 'LIKE'; } diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index fa6ee910f8..8f252b3264 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -1739,8 +1739,8 @@ class CRM_Report_Form extends CRM_Core_Form { if ($value !== NULL && count($value) > 0) { $sqlOP = $this->getSQLOperator($op); $clause - = "{$field['dbAlias']} REGEXP '[[:<:]]" . implode('|', $value) . - "[[:>:]]'"; + = "{$field['dbAlias']} REGEXP '[[:cntrl:]]" . implode('|', $value) . + "[[:cntrl:]]'"; } break; @@ -1749,8 +1749,8 @@ class CRM_Report_Form extends CRM_Core_Form { if ($value !== NULL && count($value) > 0) { $sqlOP = $this->getSQLOperator($op); $clause - = "( {$field['dbAlias']} NOT REGEXP '[[:<:]]" . implode('|', $value) . - "[[:>:]]' OR {$field['dbAlias']} IS NULL )"; + = "( {$field['dbAlias']} NOT REGEXP '[[:cntrl:]]" . implode('|', $value) . + "[[:cntrl:]]' OR {$field['dbAlias']} IS NULL )"; } break; -- 2.25.1