From 140e25ee42d056c73b72f3ea2c7cdd7c187d2713 Mon Sep 17 00:00:00 2001 From: Yashodha Chaku Date: Fri, 1 Sep 2017 08:45:07 +0530 Subject: [PATCH] CRM-21130 - Search builder throws error if location type has space (#10928) * CRM-21130 - Search builder throws error if location type has space * minor fixes --- CRM/Contact/BAO/Query.php | 7 ++++++- CRM/Contact/Selector.php | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index f711c2c1b3..dabb838b84 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -2791,7 +2791,12 @@ class CRM_Contact_BAO_Query { if ($locationTypeName) { //we have a join on an location table - possibly in conjunction with search builder - CRM-14263 $parts = explode('-', $name); - $locationID = array_search($parts[0], CRM_Core_BAO_Address::buildOptions('location_type_id', 'get', array('name' => $parts[0]))); + $locationTypes = CRM_Core_BAO_Address::buildOptions('location_type_id', 'get'); + foreach ($locationTypes as $locationTypeID => $locationType) { + if ($parts[0] == str_replace(' ', '_', $locationType)) { + $locationID = $locationTypeID; + } + } $from .= " $side JOIN civicrm_{$locationTypeName} `{$name}` ON ( contact_a.id = `{$name}`.contact_id ) and `{$name}`.location_type_id = $locationID "; } else { diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index 9d1ceb8f69..a34e8a32f8 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -1248,6 +1248,7 @@ SELECT DISTINCT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', cont foreach ($value as $n => $v) { foreach ($v as $n1 => $v1) { if (!strpos('_id', $n1) && $n1 != 'location_type') { + $n = str_replace(' ', '_', $n); $properties[] = "{$n}-{$n1}"; } } -- 2.25.1