CRM-21130 - Search builder throws error if location type has space (#10928)
authorYashodha Chaku <yashodha@cividesk.com>
Fri, 1 Sep 2017 03:15:07 +0000 (08:45 +0530)
committerEileen McNaughton <eileen@mcnaughty.com>
Fri, 1 Sep 2017 03:15:07 +0000 (15:15 +1200)
* CRM-21130 - Search builder throws error if location type has space

* minor fixes

CRM/Contact/BAO/Query.php
CRM/Contact/Selector.php

index f711c2c1b39947f08b8563a9afb615b9112ac865..dabb838b848836b2501965d3c209c4c05ce59257 100644 (file)
@@ -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 {
index 9d1ceb8f69c0a426ddf3a3bd9fa37f917c200c44..a34e8a32f836f2b6af03d8c5e4cf00cb8a27645b 100644 (file)
@@ -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}";
             }
           }