diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index c7b2bf851a60..a4618da916a8 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1013,7 +1013,7 @@ public function addHierarchicalElements() { return; } - $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); + $locationTypes = CRM_Core_DAO_Address::buildOptions('location_type_id', 'validate'); $processed = array(); $index = 0; @@ -2374,7 +2374,7 @@ public static function getLocationTableName(&$where, &$locType) { list($tbName, $fldName) = explode(".", $where); //get the location name - $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); + $locationType = CRM_Core_DAO_Address::buildOptions('location_type_id', 'validate'); $specialFields = array('email', 'im', 'phone', 'openid', 'phone_ext'); if (in_array($locType[0], $specialFields)) { //hack to fix / special handing for phone_ext @@ -2800,7 +2800,7 @@ public static function fromClause(&$tables, $inner = NULL, $right = NULL, $prima if ($locationTypeName) { //we have a join on an location table - possibly in conjunction with search builder - CRM-14263 $parts = explode('-', $name); - $locationTypes = CRM_Core_BAO_Address::buildOptions('location_type_id', 'get'); + $locationTypes = CRM_Core_DAO_Address::buildOptions('location_type_id', 'validate'); foreach ($locationTypes as $locationTypeID => $locationType) { if ($parts[0] == str_replace(' ', '_', $locationType)) { $locationID = $locationTypeID; diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index 2efc534d0f7d..abe5af175039 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -416,7 +416,7 @@ public function &getColumnHeaders($action = NULL, $output = NULL) { ), ); - $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); + $locationTypes = CRM_Core_DAO_Address::buildOptions('location_type_id', 'validate'); foreach ($this->_fields as $name => $field) { if (!empty($field['in_selector']) && @@ -492,7 +492,16 @@ public function &getColumnHeaders($action = NULL, $output = NULL) { if (trim($phoneType) && !is_numeric($phoneType) && strtolower($phoneType) != $fld) { $title .= "-{$phoneType}"; } - $title .= " ($loc)"; + // fetch Location type label from name as $loc, which will be later used in column header + $title .= sprintf("(%s)", + CRM_Core_PseudoConstant::getLabel( + 'CRM_Core_DAO_Address', + 'location_type_id', + CRM_Core_PseudoConstant::getKey('CRM_Core_DAO_Address', 'location_type_id', $loc) + ) + ); + // use field name instead of table alias + $prop = $fld; } elseif (isset($this->_query->_fields[$prop]) && isset($this->_query->_fields[$prop]['title'])) { $title = $this->_query->_fields[$prop]['title']; diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index 65a8ba51f53e..1764cd572f1a 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -1130,7 +1130,7 @@ public static function &returnProperties(&$params) { return $fields; } - $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); + $locationTypes = CRM_Core_DAO_Address::buildOptions('location_type_id', 'validate'); foreach ($params['mapper'] as $key => $value) { foreach ($value as $k => $v) { if (isset($v[1])) { diff --git a/tests/phpunit/CRM/Contact/SelectorTest.php b/tests/phpunit/CRM/Contact/SelectorTest.php index aabf86b7aec1..b847498a1c1c 100644 --- a/tests/phpunit/CRM/Contact/SelectorTest.php +++ b/tests/phpunit/CRM/Contact/SelectorTest.php @@ -274,6 +274,67 @@ public function testContactIDQuery() { $searchOBJ->contactIDQuery($params, '1_u'); } + /** + * Test the Search Builder using Non ASCII location type for email filter + */ + public function testSelectorQueryOnNonASCIIlocationType() { + $contactID = $this->individualCreate(); + $locationType = $this->locationTypeCreate([ + 'name' => 'Non ASCII Location Type', + 'display_name' => 'Дом Location type', + 'vcard_name' => 'Non ASCII Location Type', + 'is_active' => 1, + ]); + $this->callAPISuccess('Email', 'create', [ + 'contact_id' => $contactID, + 'location_type_id' => $locationType->id, + 'email' => 'test@test.com', + ]); + + $selector = new CRM_Contact_Selector( + 'CRM_Contact_Selector', + ['email' => ['IS NOT NULL' => 1]], + [[ + 0 => 'email-' . $locationType->id, + 1 => 'IS NOT NULL', + 2 => NULL, + 3 => 1, + 4 => 0, + ]], + [ + 'contact_type' => 1, + 'contact_sub_type' => 1, + 'sort_name' => 1, + 'location' => [ + 'Non ASCII Location Type' => [ + 'location_type' => $locationType->id, + 'email' => 1, + ], + ], + ], + CRM_Core_Action::NONE, + NULL, + FALSE, + 'builder' + ); + + $sql = $selector->getQueryObject()->query(); + + $expectedQuery = [ + 0 => "SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, contact_a.contact_sub_type as `contact_sub_type`, contact_a.sort_name as `sort_name`, `Non_ASCII_Location_Type-location_type`.id as `Non_ASCII_Location_Type-location_type_id`, `Non_ASCII_Location_Type-location_type`.name as `Non_ASCII_Location_Type-location_type`, `Non_ASCII_Location_Type-email`.id as `Non_ASCII_Location_Type-email_id`, `Non_ASCII_Location_Type-email`.email as `Non_ASCII_Location_Type-email`", + // @TODO these FROM clause doesn't matches due to extra spaces or special character + 2 => "WHERE ( ( LOWER(`Non_ASCII_Location_Type-email`.email) IS NOT NULL ) ) AND (contact_a.is_deleted = 0)", + ]; + foreach ($expectedQuery as $index => $queryString) { + $this->assertEquals($this->strWrangle($queryString), $this->strWrangle($sql[$index])); + } + + $rows = $selector->getRows(CRM_Core_Action::VIEW, 0, TRUE, NULL); + $this->assertEquals(1, count($rows)); + $this->assertEquals($contactID, key($rows)); + $this->assertEquals('test@test.com', $rows[$contactID]['Non_ASCII_Location_Type-email']); + } + /** * Test if custom table is added in from clause when * search results are ordered by a custom field.