From 9349bcf79da55322a0cb3ab727422ab47903abed Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Fri, 3 Feb 2017 12:36:10 +0530 Subject: [PATCH] include phone, address, etc --- CRM/Admin/Form/Setting/Search.php | 2 +- CRM/Contact/BAO/Query.php | 26 ++++++++++----------- settings/Search.setting.php | 8 +++---- templates/CRM/Admin/Form/Setting/Search.tpl | 8 +++---- tests/phpunit/CRM/Contact/BAO/QueryTest.php | 6 ++--- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/CRM/Admin/Form/Setting/Search.php b/CRM/Admin/Form/Setting/Search.php index e0f279d2b7..8435da8426 100644 --- a/CRM/Admin/Form/Setting/Search.php +++ b/CRM/Admin/Form/Setting/Search.php @@ -49,7 +49,7 @@ class CRM_Admin_Form_Setting_Search extends CRM_Admin_Form_Setting { 'includeOrderByClause' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, 'smartGroupCacheTimeout' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, 'defaultSearchProfileID' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, - 'searchPrimaryEmailOnly' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, + 'searchPrimaryLocTypes' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, ); /** diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index e3ad0230e4..41c742d4d7 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -2624,31 +2624,29 @@ class CRM_Contact_BAO_Query { } continue; } + $searchPrimary = ''; + if (Civi::settings()->get('searchPrimaryLocTypes') || $apiEntity) { + $searchPrimary = " AND {$name}.is_primary = 1"; + } switch ($name) { case 'civicrm_address': - if ($primaryLocation) { - $from .= " $side JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 )"; - } - else { - //CRM-14263 further handling of address joins further down... - $from .= " $side JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id ) "; + //CRM-14263 further handling of address joins further down... + if (!$primaryLocation) { + $searchPrimary = ''; } + $from .= " $side JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id {$searchPrimary} )"; continue; case 'civicrm_phone': - $from .= " $side JOIN civicrm_phone ON (contact_a.id = civicrm_phone.contact_id AND civicrm_phone.is_primary = 1) "; + $from .= " $side JOIN civicrm_phone ON (contact_a.id = civicrm_phone.contact_id {$searchPrimary}) "; continue; case 'civicrm_email': - $searchPrimary = ''; - if (Civi::settings()->get('searchPrimaryEmailOnly') || $apiEntity) { - $searchPrimary = " AND civicrm_email.is_primary = 1"; - } - $from .= " $side JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id) {$searchPrimary}"; + $from .= " $side JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id {$searchPrimary})"; continue; case 'civicrm_im': - $from .= " $side JOIN civicrm_im ON (contact_a.id = civicrm_im.contact_id AND civicrm_im.is_primary = 1) "; + $from .= " $side JOIN civicrm_im ON (contact_a.id = civicrm_im.contact_id {$searchPrimary}) "; continue; case 'im_provider': @@ -2658,7 +2656,7 @@ class CRM_Contact_BAO_Query { continue; case 'civicrm_openid': - $from .= " $side JOIN civicrm_openid ON ( civicrm_openid.contact_id = contact_a.id AND civicrm_openid.is_primary = 1 )"; + $from .= " $side JOIN civicrm_openid ON ( civicrm_openid.contact_id = contact_a.id {$searchPrimary} )"; continue; case 'civicrm_worldregion': diff --git a/settings/Search.setting.php b/settings/Search.setting.php index 560288635e..d970d08a66 100644 --- a/settings/Search.setting.php +++ b/settings/Search.setting.php @@ -197,18 +197,18 @@ return array( 'description' => 'If set, this will be the default profile used for contact search.', 'help_text' => NULL, ), - 'searchPrimaryEmailOnly' => array( + 'searchPrimaryLocTypes' => array( 'group_name' => 'Search Preferences', 'group' => 'Search Preferences', - 'name' => 'searchPrimaryEmailOnly', + 'name' => 'searchPrimaryLocTypes', 'type' => 'Boolean', 'quick_form_type' => 'YesNo', 'default' => 1, 'add' => '4.7', - 'title' => 'Search Primary Email Only', + 'title' => 'Search Primary Location Types Only', 'is_domain' => 1, 'is_contact' => 0, - 'description' => 'If enabled, only primary email address will be included when users search by Email. Secondary emails will only be displayed in Full Text search results. Disabling this feature will allow searching by any emails attached to the contact.', + 'description' => 'If enabled, only primary location types(email, phone, etc.) will be included in Basic and Advanced Search results. Disabling this feature will allow users to search by any location type values attached to the contact.', 'help_text' => NULL, ), ); diff --git a/templates/CRM/Admin/Form/Setting/Search.tpl b/templates/CRM/Admin/Form/Setting/Search.tpl index ea31c6e4db..5c50ae9183 100644 --- a/templates/CRM/Admin/Form/Setting/Search.tpl +++ b/templates/CRM/Admin/Form/Setting/Search.tpl @@ -37,10 +37,10 @@ {$form.includeEmailInName.html}
{ts}If enabled, email addresses are automatically included when users search by Name. Disabling this feature will speed up search significantly for larger databases, but users will need to use the Email search fields (from Advanced Search, Search Builder, or Profiles) to find contacts by email address.{/ts} - - {$form.searchPrimaryEmailOnly.label} - {$form.searchPrimaryEmailOnly.html}
- {ts}If enabled, only primary email address will be included when users search by Email. Secondary emails will only be included in Full Text search results. Disabling this feature will allow searching by any emails attached to the contact.{/ts} + + {$form.searchPrimaryLocTypes.label} + {$form.searchPrimaryLocTypes.html}
+ {ts}If enabled, only primary location types(email, phone, etc.) will be included in Basic and Advanced Search results. Disabling this feature will allow users to search by any location type values attached to the contact.{/ts} diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php index 965a3a8f8b..f6797c1507 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php @@ -152,9 +152,9 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { } /** - * Test searchByPrimaryEmailOnly setting. + * Test searchPrimaryLocTypes setting. */ - public function testSearchByPrimaryEmailOnly() { + public function testSearchPrimaryLocTypes() { $contactID = $this->individualCreate(); $params = array( 'contact_id' => $contactID, @@ -168,7 +168,7 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { $this->callAPISuccess('email', 'create', $params); foreach (array(0, 1) as $searchPrimary) { - Civi::settings()->set('searchPrimaryEmailOnly', $searchPrimary); + Civi::settings()->set('searchPrimaryLocTypes', $searchPrimary); $params = array( 0 => array( -- 2.25.1