From 399aaeca1fada161c30569ab49fd26fc037a614d Mon Sep 17 00:00:00 2001 From: David Woloszyn Date: Mon, 25 Aug 2025 12:01:29 +1000 Subject: [PATCH] MDL-85518 admin: Assign search match types to improve result sorting --- .upgradenotes/MDL-85518-2025061307102302.yml | 10 ++ .../admin/admin_setting_plugin_manager.php | 3 + public/admin/classes/admin_search.php | 83 +++++++++ .../tool/log/classes/setting_managestores.php | 4 + .../manage_communication_providers_page.php | 11 +- .../admin_setting_registeredplatforms.php | 2 + public/lib/adminlib.php | 163 +++++++++++++----- public/mod/assign/adminlib.php | 4 + .../plugins/admin_page_manage_extensions.php | 2 + .../classes/admin_setting_display_formats.php | 4 + .../admin/manage_qbank_plugins_page.php | 10 +- 11 files changed, 249 insertions(+), 47 deletions(-) create mode 100644 .upgradenotes/MDL-85518-2025061307102302.yml create mode 100644 public/admin/classes/admin_search.php diff --git a/.upgradenotes/MDL-85518-2025061307102302.yml b/.upgradenotes/MDL-85518-2025061307102302.yml new file mode 100644 index 00000000000..b6367511283 --- /dev/null +++ b/.upgradenotes/MDL-85518-2025061307102302.yml @@ -0,0 +1,10 @@ +issueNumber: MDL-85518 +notes: + core_admin: + - message: > + - Added `searchmatchtype` property to `admin_settings` + to track search match type. + - Plugins that extend either `admin_settings` or `admin_externalpage` + are encouraged to specify a search match type from the available + types in `admin_search`. + type: improved diff --git a/public/admin/classes/admin/admin_setting_plugin_manager.php b/public/admin/classes/admin/admin_setting_plugin_manager.php index 632998a603a..13e32205209 100644 --- a/public/admin/classes/admin/admin_setting_plugin_manager.php +++ b/public/admin/classes/admin/admin_setting_plugin_manager.php @@ -19,6 +19,7 @@ namespace core_admin\admin; use admin_setting; use core_plugin_manager; use core_text; +use core_admin\admin_search; /** * Admin setting plugin manager. @@ -98,11 +99,13 @@ class admin_setting_plugin_manager extends admin_setting { foreach (array_keys($plugins) as $plugin) { $plugin = "{$this->plugintype}_{$plugin}"; if (str_contains($plugin, $query)) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; return true; } $pluginname = get_string('pluginname', $plugin); if (strpos(core_text::strtolower($pluginname), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } diff --git a/public/admin/classes/admin_search.php b/public/admin/classes/admin_search.php new file mode 100644 index 00000000000..3bc2e4d8a36 --- /dev/null +++ b/public/admin/classes/admin_search.php @@ -0,0 +1,83 @@ +. + +namespace core_admin; + +/** + * Process admin search results. + * + * @package core_admin + * @copyright 2025 David Woloszyn + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class admin_search { + /** @var string Search match for a page title. */ + const SEARCH_MATCH_PAGE_TITLE = 'title'; + + /** @var string Search match for a setting short name. */ + const SEARCH_MATCH_SETTING_SHORT_NAME = 'shortname'; + + /** @var string Search match for a setting display name. */ + const SEARCH_MATCH_SETTING_DISPLAY_NAME = 'displayname'; + + /** @var string Search match for a setting value. */ + const SEARCH_MATCH_SETTING_VALUE = 'value'; + + /** @var string Search match for a setting helper. */ + const SEARCH_MATCH_SETTING_HELPER = 'helper'; + + /** + * Get a prioritised list of search match types. + * + * The order will determine how results will be displayed. + * Items higher in the list will be displayed first. + * + * @return array The list of priorities. + */ + private static function get_search_match_priorities(): array { + return [ + self::SEARCH_MATCH_PAGE_TITLE, + self::SEARCH_MATCH_SETTING_SHORT_NAME, + self::SEARCH_MATCH_SETTING_DISPLAY_NAME, + self::SEARCH_MATCH_SETTING_VALUE, + self::SEARCH_MATCH_SETTING_HELPER, + ]; + } + + /** + * Sort search results according to a set of priorities. + * + * @param array $results The unsorted results. + * @return array The sorted results. + */ + public static function sort_search_results(array $results): array { + $priorities = self::get_search_match_priorities(); + // If there is no searchmatchype property, use this priority. + $defaultpriority = count($priorities); + uasort($results, function ($a, $b) use ($priorities, $defaultpriority) { + + $prioritya = array_search($a->searchmatchtype, $priorities); + $priorityb = array_search($b->searchmatchtype, $priorities); + + $prioritya = ($prioritya === false) ? $defaultpriority : $prioritya; + $priorityb = ($priorityb === false) ? $defaultpriority : $priorityb; + + return $prioritya <=> $priorityb; + }); + + return $results; + } +} diff --git a/public/admin/tool/log/classes/setting_managestores.php b/public/admin/tool/log/classes/setting_managestores.php index b897eb8c0bf..d51b8f16785 100644 --- a/public/admin/tool/log/classes/setting_managestores.php +++ b/public/admin/tool/log/classes/setting_managestores.php @@ -22,6 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use core_admin\admin_search; + defined('MOODLE_INTERNAL') || die(); require_once("$CFG->libdir/adminlib.php"); @@ -79,10 +81,12 @@ class tool_log_setting_managestores extends admin_setting { $plugins = \tool_log\log\manager::get_store_plugins(); foreach ($plugins as $plugin => $fulldir) { if (strpos(core_text::strtolower($plugin), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; return true; } $localised = get_string('pluginname', $plugin); if (strpos(core_text::strtolower($localised), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } diff --git a/public/communication/classes/admin/manage_communication_providers_page.php b/public/communication/classes/admin/manage_communication_providers_page.php index 1c61f606e45..8db7c24aeba 100644 --- a/public/communication/classes/admin/manage_communication_providers_page.php +++ b/public/communication/classes/admin/manage_communication_providers_page.php @@ -23,6 +23,7 @@ use html_table; use html_table_row; use html_writer; use moodle_url; +use core_admin\admin_search; /** * Communication providers manager. Allow enable/disable communication providers and jump to settings. @@ -127,10 +128,12 @@ class manage_communication_providers_page extends admin_setting { } $types = core_plugin_manager::instance()->get_plugins_of_type('communication'); foreach ($types as $type) { - if ( - strpos($type->component, $query) !== false || - strpos(core_text::strtolower($type->displayname), $query) !== false - ) { + if (strpos($type->component, $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; + return true; + } + if (strpos(core_text::strtolower($type->displayname), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } diff --git a/public/enrol/lti/classes/local/ltiadvantage/admin/admin_setting_registeredplatforms.php b/public/enrol/lti/classes/local/ltiadvantage/admin/admin_setting_registeredplatforms.php index 06f96c3af59..36e3c114fad 100644 --- a/public/enrol/lti/classes/local/ltiadvantage/admin/admin_setting_registeredplatforms.php +++ b/public/enrol/lti/classes/local/ltiadvantage/admin/admin_setting_registeredplatforms.php @@ -16,6 +16,7 @@ namespace enrol_lti\local\ltiadvantage\admin; use enrol_lti\local\ltiadvantage\repository\application_registration_repository; +use core_admin\admin_search; /** * The admin_setting_registeredplatforms class, for rendering a table of platforms which have been registered. @@ -79,6 +80,7 @@ class admin_setting_registeredplatforms extends \admin_setting { $registrations = $appregistrationrepo->find_all(); foreach ($registrations as $reg) { if (stripos($reg->get_name(), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } diff --git a/public/lib/adminlib.php b/public/lib/adminlib.php index 52684fcb781..043bd6ce3f3 100644 --- a/public/lib/adminlib.php +++ b/public/lib/adminlib.php @@ -103,6 +103,7 @@ */ use core_admin\local\settings\linkable_settings_page; +use core_admin\admin_search; defined('MOODLE_INTERNAL') || die(); @@ -1233,6 +1234,9 @@ class admin_externalpage implements part_of_admin_tree, linkable_settings_page { /** @var array list of visible names of page parents */ public $visiblepath; + /** @var string Capture the type of search matched from the query. */ + public $searchmatchtype; + /** * Constructor for adding an external page into the admin tree. * @@ -1304,18 +1308,21 @@ class admin_externalpage implements part_of_admin_tree, linkable_settings_page { */ public function search($query) { $found = false; - if (strpos(strtolower($this->name), $query) !== false) { + if ( + strpos(core_text::strtolower($this->visiblename), $query) !== false || + strpos(strtolower($this->name), $query) !== false + ) { + $type = admin_search::SEARCH_MATCH_PAGE_TITLE; $found = true; - } else if (strpos(core_text::strtolower($this->visiblename), $query) !== false) { - $found = true; - } + } if ($found) { $result = new stdClass(); - $result->page = $this; - $result->settings = array(); - return array($this->name => $result); + $result->page = $this; + $result->settings = []; + $result->searchmatchtype = $type; + return [$this->name => $result]; } else { - return array(); + return []; } } @@ -1530,35 +1537,43 @@ class admin_settingpage implements part_of_admin_tree, linkable_settings_page { * @return array */ public function search($query) { - $found = array(); + $found = false; + // Prioritise matching the page title. + if ( + strpos(core_text::strtolower($this->visiblename), $query) !== false || + strpos(strtolower($this->name), $query) !== false + ) { + $type = admin_search::SEARCH_MATCH_PAGE_TITLE; + $found = true; + } + if ($found) { + $result = new stdClass(); + $result->page = $this; + $result->settings = []; + $result->searchmatchtype = $type; + return [$this->name => $result]; + } + // Search related settings. + $foundrelated = []; foreach ($this->settings as $setting) { if ($setting->is_related($query)) { - $found[] = $setting; + $foundrelated[] = $setting; } } - if ($found) { + if (!empty($foundrelated)) { + $sortedresults = admin_search::sort_search_results($foundrelated); + $result = new stdClass(); - $result->page = $this; - $result->settings = $found; - return array($this->name => $result); + $result->page = $this; + $result->settings = $sortedresults; + // Multiple related matches may have been found. Get the highest priority one. + $result->searchmatchtype = reset($sortedresults)->searchmatchtype; + return [$this->name => $result]; } - $found = false; - if (strpos(strtolower($this->name), $query) !== false) { - $found = true; - } else if (strpos(core_text::strtolower($this->visiblename), $query) !== false) { - $found = true; - } - if ($found) { - $result = new stdClass(); - $result->page = $this; - $result->settings = array(); - return array($this->name => $result); - } else { - return array(); - } + return []; } /** @@ -1730,6 +1745,8 @@ abstract class admin_setting { protected $customcontrol = false; /** @var mixed int means PARAM_XXX type, string is a allowed format in regex */ public $paramtype; + /** @var string Capture the type of search matched from the query. */ + public $searchmatchtype; /** * Constructor @@ -2086,18 +2103,22 @@ abstract class admin_setting { */ public function is_related($query) { if (strpos(strtolower($this->name), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; return true; } if (strpos(core_text::strtolower($this->visiblename), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } if (strpos(core_text::strtolower($this->description), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_HELPER; return true; } $current = $this->get_setting(); if (!is_null($current)) { if (is_string($current)) { if (strpos(core_text::strtolower($current), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_VALUE; return true; } } @@ -2106,6 +2127,7 @@ abstract class admin_setting { if (!is_null($default)) { if (is_string($default)) { if (strpos(core_text::strtolower($default), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_HELPER; return true; } } @@ -3210,6 +3232,7 @@ class admin_setting_configmulticheckbox extends admin_setting { foreach ($this->choices as $desc) { if (strpos(core_text::strtolower($desc), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_VALUE; return true; } } @@ -3479,9 +3502,11 @@ class admin_setting_configselect extends admin_setting { } foreach ($this->choices as $key=>$value) { if (strpos(core_text::strtolower($key), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_VALUE; return true; } if (strpos(core_text::strtolower($value), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_VALUE; return true; } } @@ -3714,6 +3739,7 @@ class admin_setting_configmultiselect extends admin_setting_configselect { foreach ($this->choices as $desc) { if (strpos(core_text::strtolower($desc), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_VALUE; return true; } } @@ -6669,11 +6695,13 @@ class admin_page_managemods extends admin_externalpage { continue; } if (strpos($module->name, $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; $found = true; break; } $strmodulename = get_string('modulename', $module->name); if (strpos(core_text::strtolower($strmodulename), $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; $found = true; break; } @@ -6683,6 +6711,7 @@ class admin_page_managemods extends admin_externalpage { $result = new stdClass(); $result->page = $this; $result->settings = array(); + $result->searchmatchtype = $type; return array($this->name => $result); } else { return array(); @@ -6750,9 +6779,11 @@ class admin_setting_manageenrols extends admin_setting { foreach ($enrols as $name=>$enrol) { $localised = get_string('pluginname', 'enrol_'.$name); if (strpos(core_text::strtolower($name), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; return true; } if (strpos(core_text::strtolower($localised), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } @@ -6950,11 +6981,13 @@ class admin_page_manageblocks extends admin_externalpage { continue; } if (strpos($block->name, $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; $found = true; break; } $strblockname = get_string('pluginname', 'block_'.$block->name); if (strpos(core_text::strtolower($strblockname), $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; $found = true; break; } @@ -6964,6 +6997,7 @@ class admin_page_manageblocks extends admin_externalpage { $result = new stdClass(); $result->page = $this; $result->settings = array(); + $result->searchmatchtype = $type; return array($this->name => $result); } else { return array(); @@ -7007,11 +7041,13 @@ class admin_page_managemessageoutputs extends admin_externalpage { continue; } if (strpos($processor->name, $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; $found = true; break; } $strprocessorname = get_string('pluginname', 'message_'.$processor->name); if (strpos(core_text::strtolower($strprocessorname), $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; $found = true; break; } @@ -7021,6 +7057,7 @@ class admin_page_managemessageoutputs extends admin_externalpage { $result = new stdClass(); $result->page = $this; $result->settings = array(); + $result->searchmatchtype = $type; return array($this->name => $result); } else { return array(); @@ -7061,6 +7098,7 @@ class admin_page_manageqbehaviours extends admin_externalpage { foreach (core_component::get_plugin_list('qbehaviour') as $behaviour => $notused) { if (strpos(core_text::strtolower(question_engine::get_behaviour_name($behaviour)), $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; $found = true; break; } @@ -7069,6 +7107,7 @@ class admin_page_manageqbehaviours extends admin_externalpage { $result = new stdClass(); $result->page = $this; $result->settings = array(); + $result->searchmatchtype = $type; return array($this->name => $result); } else { return array(); @@ -7108,6 +7147,7 @@ class admin_page_manageqtypes extends admin_externalpage { require_once($CFG->dirroot . '/question/engine/bank.php'); foreach (question_bank::get_all_qtypes() as $qtype) { if (strpos(core_text::strtolower($qtype->local_name()), $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; $found = true; break; } @@ -7116,6 +7156,7 @@ class admin_page_manageqtypes extends admin_externalpage { $result = new stdClass(); $result->page = $this; $result->settings = array(); + $result->searchmatchtype = $type; return array($this->name => $result); } else { return array(); @@ -7149,6 +7190,7 @@ class admin_page_manageportfolios extends admin_externalpage { $portfolios = core_component::get_plugin_list('portfolio'); foreach ($portfolios as $p => $dir) { if (strpos($p, $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; $found = true; break; } @@ -7157,6 +7199,7 @@ class admin_page_manageportfolios extends admin_externalpage { foreach (portfolio_instances(false, false) as $instance) { $title = $instance->get('name'); if (strpos(core_text::strtolower($title), $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; $found = true; break; } @@ -7167,6 +7210,7 @@ class admin_page_manageportfolios extends admin_externalpage { $result = new stdClass(); $result->page = $this; $result->settings = array(); + $result->searchmatchtype = $type; return array($this->name => $result); } else { return array(); @@ -7200,6 +7244,7 @@ class admin_page_managerepositories extends admin_externalpage { $repositories= core_component::get_plugin_list('repository'); foreach ($repositories as $p => $dir) { if (strpos($p, $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; $found = true; break; } @@ -7208,6 +7253,7 @@ class admin_page_managerepositories extends admin_externalpage { foreach (repository::get_types() as $instance) { $title = $instance->get_typename(); if (strpos(core_text::strtolower($title), $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; $found = true; break; } @@ -7218,6 +7264,7 @@ class admin_page_managerepositories extends admin_externalpage { $result = new stdClass(); $result->page = $this; $result->settings = array(); + $result->searchmatchtype = $type; return array($this->name => $result); } else { return array(); @@ -7282,11 +7329,13 @@ class admin_setting_manageauths extends admin_setting { $authsavailable = core_component::get_plugin_list('auth'); foreach ($authsavailable as $auth => $dir) { if (strpos($auth, $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; return true; } $authplugin = get_auth_plugin($auth); $authtitle = $authplugin->get_title(); if (strpos(core_text::strtolower($authtitle), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } @@ -7510,9 +7559,11 @@ class admin_setting_manageantiviruses extends admin_setting { $antivirusesavailable = \core\antivirus\manager::get_available(); foreach ($antivirusesavailable as $antivirus => $antivirusstr) { if (strpos($antivirus, $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; return true; } if (strpos(core_text::strtolower($antivirusstr), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } @@ -7687,8 +7738,12 @@ class admin_setting_manageformats extends admin_setting { } $formats = core_plugin_manager::instance()->get_plugins_of_type('format'); foreach ($formats as $format) { - if (strpos($format->component, $query) !== false || - strpos(core_text::strtolower($format->displayname), $query) !== false) { + if (strpos($format->component, $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; + return true; + } + if (strpos(core_text::strtolower($format->displayname), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } @@ -7837,8 +7892,12 @@ class admin_setting_managecustomfields extends admin_setting { } $formats = core_plugin_manager::instance()->get_plugins_of_type('customfield'); foreach ($formats as $format) { - if (strpos($format->component, $query) !== false || - strpos(core_text::strtolower($format->displayname), $query) !== false) { + if (strpos($format->component, $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; + return true; + } + if (strpos(core_text::strtolower($format->displayname), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } @@ -7961,8 +8020,12 @@ class admin_setting_managedataformats extends admin_setting { } $formats = core_plugin_manager::instance()->get_plugins_of_type('dataformat'); foreach ($formats as $format) { - if (strpos($format->component, $query) !== false || - strpos(core_text::strtolower($format->displayname), $query) !== false) { + if (strpos($format->component, $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; + return true; + } + if (strpos(core_text::strtolower($format->displayname), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } @@ -8092,11 +8155,13 @@ class admin_page_managefilters extends admin_externalpage { $found = false; $filternames = filter_get_all_installed(); foreach ($filternames as $path => $strfiltername) { - if (strpos(core_text::strtolower($strfiltername), $query) !== false) { + if (strpos($path, $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; $found = true; break; } - if (strpos($path, $query) !== false) { + if (strpos(core_text::strtolower($strfiltername), $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; $found = true; break; } @@ -8106,6 +8171,7 @@ class admin_page_managefilters extends admin_externalpage { $result = new stdClass; $result->page = $this; $result->settings = array(); + $result->searchmatchtype = $type; return array($this->name => $result); } else { return array(); @@ -8215,9 +8281,11 @@ abstract class admin_setting_manage_plugins extends admin_setting { foreach ($plugins as $name => $plugin) { $localised = $plugin->displayname; if (strpos(core_text::strtolower($name), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; return true; } if (strpos(core_text::strtolower($localised), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } @@ -8399,9 +8467,11 @@ class admin_setting_managemediaplayers extends admin_setting { foreach ($plugins as $name => $plugin) { $localised = $plugin->displayname; if (strpos(core_text::strtolower($name), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; return true; } if (strpos(core_text::strtolower($localised), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } @@ -8618,8 +8688,12 @@ class admin_setting_managecontentbankcontenttypes extends admin_setting { } $types = core_plugin_manager::instance()->get_plugins_of_type('contenttype'); foreach ($types as $type) { - if (strpos($type->component, $query) !== false || - strpos(core_text::strtolower($type->displayname), $query) !== false) { + if (strpos($type->component, $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; + return true; + } + if (strpos(core_text::strtolower($type->displayname), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } @@ -9086,9 +9160,11 @@ function admin_search_settings_html($query) { 'sesskey' => sesskey(), ]; - foreach ($findings as $found) { - $page = $found->page; - $settings = $found->settings; + $sortedresults = admin_search::sort_search_results($findings); + + foreach ($sortedresults as $result) { + $page = $result->page; + $settings = $result->settings; if ($page->is_hidden()) { // hidden pages are not displayed in search results continue; @@ -9488,12 +9564,14 @@ class admin_setting_managerepository extends admin_setting { $repositories= core_component::get_plugin_list('repository'); foreach ($repositories as $p => $dir) { if (strpos($p, $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; return true; } } foreach (repository::get_types() as $instance) { $title = $instance->get_typename(); if (strpos(core_text::strtolower($title), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } @@ -9884,6 +9962,7 @@ class admin_setting_manageexternalservices extends admin_setting { $services = $DB->get_records('external_services', array(), 'id, name'); foreach ($services as $service) { if (strpos(core_text::strtolower($service->name), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } @@ -10336,10 +10415,12 @@ class admin_setting_managewebserviceprotocols extends admin_setting { $protocols = core_component::get_plugin_list('webservice'); foreach ($protocols as $protocol=>$location) { if (strpos($protocol, $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; return true; } $protocolstr = get_string('pluginname', 'webservice_'.$protocol); if (strpos(core_text::strtolower($protocolstr), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } diff --git a/public/mod/assign/adminlib.php b/public/mod/assign/adminlib.php index 9320e79d51d..19f90c23b62 100644 --- a/public/mod/assign/adminlib.php +++ b/public/mod/assign/adminlib.php @@ -22,6 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use core_admin\admin_search; + defined('MOODLE_INTERNAL') || die(); require_once($CFG->libdir . '/adminlib.php'); @@ -67,6 +69,7 @@ class assign_admin_page_manage_assign_plugins extends admin_externalpage { foreach (core_component::get_plugin_list($this->subtype) as $name => $notused) { if (strpos(core_text::strtolower(get_string('pluginname', $this->subtype . '_' . $name)), $query) !== false) { + $type = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; $found = true; break; } @@ -75,6 +78,7 @@ class assign_admin_page_manage_assign_plugins extends admin_externalpage { $result = new stdClass(); $result->page = $this; $result->settings = array(); + $result->searchmatchtype = $type; return array($this->name => $result); } else { return array(); diff --git a/public/mod/bigbluebuttonbn/classes/local/plugins/admin_page_manage_extensions.php b/public/mod/bigbluebuttonbn/classes/local/plugins/admin_page_manage_extensions.php index a305ea8dfeb..0e862ab6a9e 100644 --- a/public/mod/bigbluebuttonbn/classes/local/plugins/admin_page_manage_extensions.php +++ b/public/mod/bigbluebuttonbn/classes/local/plugins/admin_page_manage_extensions.php @@ -25,6 +25,7 @@ use core_component; use core_text; use mod_bigbluebuttonbn\extension; use moodle_url; +use core_admin\admin_search; /** * Admin external page that displays a list of the installed extension plugins. @@ -72,6 +73,7 @@ class admin_page_manage_extensions extends admin_externalpage { $result = (object)[ 'page' => $this, 'settings' => [], + 'searchmatchtype' => admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME, ]; return [$this->name => $result]; } diff --git a/public/mod/glossary/classes/admin_setting_display_formats.php b/public/mod/glossary/classes/admin_setting_display_formats.php index 7e374348dc3..b40c91a63b6 100644 --- a/public/mod/glossary/classes/admin_setting_display_formats.php +++ b/public/mod/glossary/classes/admin_setting_display_formats.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +use core_admin\admin_search; + defined('MOODLE_INTERNAL') || die(); /** @@ -78,10 +80,12 @@ class mod_glossary_admin_setting_display_formats extends admin_setting { $formats = $DB->get_records("glossary_formats"); foreach ($formats as $format) { if (strpos(core_text::strtolower($format->name), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; return true; } $localised = get_string("displayformat$format->name", "glossary"); if (strpos(core_text::strtolower($localised), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } } diff --git a/public/question/classes/admin/manage_qbank_plugins_page.php b/public/question/classes/admin/manage_qbank_plugins_page.php index 8d63df12d14..8c08b481c41 100644 --- a/public/question/classes/admin/manage_qbank_plugins_page.php +++ b/public/question/classes/admin/manage_qbank_plugins_page.php @@ -25,6 +25,8 @@ namespace core_question\admin; +use core_admin\admin_search; + /** * Class manage_qbank_plugins_page. * @@ -62,8 +64,12 @@ class manage_qbank_plugins_page extends \admin_setting { } $types = \core_plugin_manager::instance()->get_plugins_of_type('qbank'); foreach ($types as $type) { - if (strpos($type->component, $query) !== false || - strpos(\core_text::strtolower($type->displayname), $query) !== false) { + if (strpos($type->component, $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_SHORT_NAME; + return true; + } + if (strpos(\core_text::strtolower($type->displayname), $query) !== false) { + $this->searchmatchtype = admin_search::SEARCH_MATCH_SETTING_DISPLAY_NAME; return true; } }