From ff85e96bd08673c998fc84031aa1a7cafbd4e7d1 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 21 Dec 2023 19:35:33 +1300 Subject: [PATCH] Clean up search settings page --- CRM/Admin/Form/Setting/Search.php | 12 --------- CRM/Admin/Form/SettingTrait.php | 43 +++++++++++++++++++++---------- settings/Core.setting.php | 4 +-- settings/Search.setting.php | 19 ++++++++++++-- 4 files changed, 48 insertions(+), 30 deletions(-) diff --git a/CRM/Admin/Form/Setting/Search.php b/CRM/Admin/Form/Setting/Search.php index 268674e0a9..06a6dff0ca 100644 --- a/CRM/Admin/Form/Setting/Search.php +++ b/CRM/Admin/Form/Setting/Search.php @@ -21,18 +21,6 @@ */ class CRM_Admin_Form_Setting_Search extends CRM_Admin_Form_Setting { - protected $_settings = [ - 'includeWildCardInName' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, - 'includeEmailInName' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, - 'searchPrimaryDetailsOnly' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, - 'includeNickNameInName' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, - 'includeAlphabeticalPager' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, - 'includeOrderByClause' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, - 'defaultSearchProfileID' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, - 'smartGroupCacheTimeout' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, - 'quicksearch_options' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, - ]; - /** * Build the form object. */ diff --git a/CRM/Admin/Form/SettingTrait.php b/CRM/Admin/Form/SettingTrait.php index eb8d592cf7..f30c9c219b 100644 --- a/CRM/Admin/Form/SettingTrait.php +++ b/CRM/Admin/Form/SettingTrait.php @@ -70,6 +70,9 @@ trait CRM_Admin_Form_SettingTrait { // This array_merge re-orders to the key order of $this->_settings. $this->settingsMetadata = array_merge($this->_settings, $this->settingsMetadata); } + uasort($this->settingsMetadata, function ($a, $b) { + return $this->isWeightHigher($a, $b); + }); return $this->settingsMetadata; } @@ -150,6 +153,7 @@ trait CRM_Admin_Form_SettingTrait { */ protected function getSettingsOrderedByWeight() { $settingMetaData = $this->getSettingsMetaData(); + // Probably unnessary to do this again. $settingMetaData = $this->filterMetadataByWeight($settingMetaData); return $settingMetaData; @@ -404,22 +408,33 @@ trait CRM_Admin_Form_SettingTrait { * @return array */ protected function filterMetadataByWeight(array $settingMetaData): array { - $filter = $this->getSettingPageFilter(); - - usort($settingMetaData, function ($a, $b) use ($filter) { - // Handle cases in which a comparison is impossible. Such will be considered ties. - if ( - // A comparison can't be made unless both setting weights are declared. - !isset($a['settings_pages'][$filter]['weight'], $b['settings_pages'][$filter]['weight']) - // A pair of settings might actually have the same weight. - || $a['settings_pages'][$filter]['weight'] === $b['settings_pages'][$filter]['weight'] - ) { - return 0; - } - - return $a['settings_pages'][$filter]['weight'] > $b['settings_pages'][$filter]['weight'] ? 1 : -1; + usort($settingMetaData, function ($a, $b) { + return $this->isWeightHigher($a, $b); }); return $settingMetaData; } + /** + * Is the relevant weight of b higher than a. + * + * @param array $a + * @param array $b + * + * @return int + */ + protected function isWeightHigher(array $a, array $b): int { + $filter = $this->getSettingPageFilter(); + // Handle cases in which a comparison is impossible. Such will be considered ties. + if ( + // A comparison can't be made unless both setting weights are declared. + !isset($a['settings_pages'][$filter]['weight'], $b['settings_pages'][$filter]['weight']) + // A pair of settings might actually have the same weight. + || $a['settings_pages'][$filter]['weight'] === $b['settings_pages'][$filter]['weight'] + ) { + return 0; + } + + return $a['settings_pages'][$filter]['weight'] > $b['settings_pages'][$filter]['weight'] ? 1 : -1; + } + } diff --git a/settings/Core.setting.php b/settings/Core.setting.php index 9f2177c621..f97d92bd43 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -321,7 +321,7 @@ return [ 'help_text' => NULL, 'serialize' => CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, 'validate_callback' => 'CRM_Admin_Form_Setting_Search::enableOptionOne', - 'settings_pages' => ['search' => ['weight' => 80]], + 'settings_pages' => ['search' => ['weight' => 120]], ], 'contact_reference_options' => [ 'group_name' => 'CiviCRM Preferences', @@ -341,7 +341,7 @@ return [ 'help_text' => NULL, 'serialize' => CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, 'validate_callback' => 'CRM_Admin_Form_Setting_Search::enableOptionOne', - 'settings_pages' => ['search' => ['weight' => 90]], + 'settings_pages' => ['search' => ['weight' => 130]], ], 'contact_smart_group_display' => [ 'group_name' => 'CiviCRM Preferences', diff --git a/settings/Search.setting.php b/settings/Search.setting.php index dfdbb46de9..8e80962739 100644 --- a/settings/Search.setting.php +++ b/settings/Search.setting.php @@ -17,6 +17,8 @@ /* * Settings metadata file */ +$optimizationSeeAlso = '
' . ts('See also: Search Optimization', [1 => 'https://docs.civicrm.org/sysadmin/en/latest/setup/optimizations/" target="_blank"']); +$searchConfigSeeAlso = '
' . ts('See also: Search Configuration Options', [1 => 'https://docs.civicrm.org/en/user/latest/initial-set-up/customizing-the-user-interface/#customizing-search-preferences" target="_blank"']); return [ 'search_autocomplete_count' => [ 'group_name' => 'Search Preferences', @@ -32,6 +34,7 @@ return [ 'is_contact' => 0, 'description' => ts('The maximum number of contacts to show at a time when typing in an autocomplete field.'), 'help_text' => NULL, + 'settings_pages' => ['search' => ['weight' => 150]], ], 'includeOrderByClause' => [ 'group_name' => 'Search Preferences', @@ -46,6 +49,7 @@ return [ 'is_contact' => 0, 'description' => ts('If disabled, the search results will not be ordered. This may improve response time on search results on large datasets.'), 'help_text' => NULL, + 'settings_pages' => ['search' => ['weight' => 60]], ], 'includeWildCardInName' => [ 'group_name' => 'Search Preferences', @@ -60,6 +64,7 @@ return [ 'is_contact' => 0, 'description' => ts("If enabled, wildcards are automatically added to the beginning AND end of the search term when users search for contacts by Name. EXAMPLE: Searching for 'ada' will return any contact whose name includes those letters - e.g. 'Adams, Janet', 'Nadal, Jorge', etc. If disabled, a wildcard is added to the end of the search term only. EXAMPLE: Searching for 'ada' will return any contact whose last name begins with those letters - e.g. 'Adams, Janet' but NOT 'Nadal, Jorge'. Disabling this feature will speed up search significantly for larger databases, but users must manually enter wildcards ('%' or '_') to the beginning of the search term if they want to find all records which contain those letters. EXAMPLE: '%ada' will return 'Nadal, Jorge'."), 'help_text' => NULL, + 'settings_pages' => ['search' => ['weight' => 10]], ], 'includeEmailInName' => [ 'group_name' => 'Search Preferences', @@ -74,6 +79,7 @@ return [ 'is_contact' => 0, 'description' => 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.'), 'help_text' => NULL, + 'settings_pages' => ['search' => ['weight' => 20]], ], 'includeNickNameInName' => [ 'group_name' => 'Search Preferences', @@ -88,6 +94,7 @@ return [ 'is_contact' => 0, 'description' => ts('If enabled, nicknames are automatically included when users search by Name.'), 'help_text' => NULL, + 'settings_pages' => ['search' => ['weight' => 40]], ], 'includeAlphabeticalPager' => [ 'group_name' => 'Search Preferences', @@ -102,6 +109,7 @@ return [ 'is_contact' => 0, 'description' => ts('If disabled, the alphabetical pager will not be displayed on the search screens. This will improve response time on search results on large datasets.'), 'help_text' => NULL, + 'settings_pages' => ['search' => ['weight' => 50]], ], 'smartGroupCacheTimeout' => [ 'group_name' => 'Search Preferences', @@ -115,8 +123,9 @@ return [ 'title' => ts('Smart group cache timeout'), 'is_domain' => 1, 'is_contact' => 0, - 'description' => ts('The number of minutes to cache smart group contacts. We strongly recommend that this value be greater than zero, since a value of zero means no caching at all. If your contact data changes frequently, you should set this value to at least 5 minutes.'), - 'help_text' => NULL, + 'description' => ts('The number of minutes to cache smart group contacts. The best value will depend on your site and the complexity of the groups and acls you use. A value of zero means no caching at all. You may need to experiment with this.') . $optimizationSeeAlso, + 'help_text' => '', + 'settings_pages' => ['search' => ['weight' => 80]], ], 'defaultSearchProfileID' => [ 'group_name' => 'Search Preferences', @@ -138,6 +147,7 @@ return [ 'is_contact' => 0, 'description' => ts('If set, this will be the default profile used for contact search.'), 'help_text' => NULL, + 'settings_pages' => ['search' => ['weight' => 70]], ], 'prevNextBackend' => [ 'group_name' => 'Search Preferences', @@ -159,6 +169,9 @@ return [ ], 'description' => ts('When performing a search, how should the search-results be cached?'), 'help_text' => '', + // Not exposed in UI as breakage possible. As with the SmartGroupCache time out a different page + // might make more sense. + 'settings_pages' => [], ], 'searchPrimaryDetailsOnly' => [ 'group_name' => 'Search Preferences', @@ -173,6 +186,7 @@ return [ 'is_contact' => 0, 'description' => ts('If enabled, only primary details (eg contact\'s primary email, phone, etc) will be included in Basic and Advanced Search results. Disabling this feature will allow users to match contacts using any email, phone etc detail.'), 'help_text' => NULL, + 'settings_pages' => ['search' => ['weight' => 30]], ], 'quicksearch_options' => [ 'group_name' => 'Search Preferences', @@ -203,6 +217,7 @@ return [ 'is_contact' => 0, 'description' => ts("Which fields can be searched on in the menubar quicksearch box? Don't see your custom field here? Make sure it is marked as Searchable."), 'help_text' => NULL, + 'settings_pages' => ['search' => ['weight' => 90]], ], 'default_pager_size' => [ 'group_name' => 'Search Preferences', -- 2.25.1