From 6c5a6215ef4ac8f44cc2c0133688dda73a9c498a Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 12 Mar 2015 18:11:06 +0100 Subject: [PATCH] Render search results based on their priority refs #8668 --- library/Icinga/Web/Widget/SearchDashboard.php | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/library/Icinga/Web/Widget/SearchDashboard.php b/library/Icinga/Web/Widget/SearchDashboard.php index 16c2b66d6..c5e1ad8db 100644 --- a/library/Icinga/Web/Widget/SearchDashboard.php +++ b/library/Icinga/Web/Widget/SearchDashboard.php @@ -18,13 +18,6 @@ class SearchDashboard extends Dashboard { const SEARCH_PANE = 'search'; - /** - * All searchUrls provided by Modules - * - * @var array - */ - protected $searchUrls = array(); - /** * Load all available search dashlets from modules * @@ -64,9 +57,22 @@ class SearchDashboard extends Dashboard $this->activate(self::SEARCH_PANE); $manager = Icinga::app()->getModuleManager(); + $searchUrls = array(); foreach ($manager->getLoadedModules() as $module) { - $this->addSearchDashletsFromModule($searchString, $module, $pane); + $moduleSearchUrls = $module->getSearchUrls(); + if (! empty($moduleSearchUrls)) { + $searchUrls = array_merge($searchUrls, $moduleSearchUrls); + } + } + + usort($searchUrls, array($this, 'compareSearchUrls')); + + foreach (array_reverse($searchUrls) as $searchUrl) { + $pane->addDashlet( + $searchUrl->title . ': ' . $searchString, + Url::fromPath($searchUrl->url, array('q' => $searchString)) + ); } if ($searchString === '' && $pane->hasDashlets()) { @@ -77,24 +83,18 @@ class SearchDashboard extends Dashboard } /** - * Add available search dashlets to the pane + * Compare search URLs based on their priority * - * @param string $searchString - * @param Module $module - * @param Pane $pane + * @param object $a + * @param object $b + * + * @return int */ - protected function addSearchDashletsFromModule($searchString, $module, $pane) + private function compareSearchUrls($a, $b) { - $searchUrls = $module->getSearchUrls(); - - if (! empty($searchUrls)) { - $this->searchUrls[] = $module->getSearchUrls(); - foreach ($searchUrls as $search) { - $pane->addDashlet( - $search->title . ': ' . $searchString, - Url::fromPath($search->url, array('q' => $searchString)) - ); - } + if ($a->priority === $b->priority) { + return 0; } + return ($a->priority < $b->priority) ? -1 : 1; } }