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;
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
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;
),
);
- $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']) &&
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'];
$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.