From 83ee5a47ebf6227d7e0b898d506f230f07d9d815 Mon Sep 17 00:00:00 2001 From: Thomas Steur <thomas.steur@googlemail.com> Date: Fri, 13 Jun 2014 04:34:15 +0200 Subject: [PATCH] by sorting the reports before returning them we make sure the widgets will be added in the correct order which again makes sure the dashboard ui tests adds the widgets in the right order --- core/Plugin/Report.php | 39 ++++++++++++++++++++++++++++ plugins/API/ProcessedReport.php | 33 +---------------------- plugins/Referrers/Reports/GetAll.php | 4 ++- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/core/Plugin/Report.php b/core/Plugin/Report.php index af80dd6be6..c47f2ce5ec 100644 --- a/core/Plugin/Report.php +++ b/core/Plugin/Report.php @@ -214,7 +214,46 @@ class Report $instances[] = new $report(); } + usort($instances, array('self', 'sort')); + return $instances; } + /** + * API metadata are sorted by category/name, + * with a little tweak to replicate the standard Piwik category ordering + * + * @param array|Report $a + * @param array|Report $b + * @return int + */ + public static function sort($a, $b) + { + static $order = null; + if (is_null($order)) { + $order = array( + Piwik::translate('General_MultiSitesSummary'), + Piwik::translate('VisitsSummary_VisitsSummary'), + Piwik::translate('Goals_Ecommerce'), + Piwik::translate('General_Actions'), + Piwik::translate('Events_Events'), + Piwik::translate('Actions_SubmenuSitesearch'), + Piwik::translate('Referrers_Referrers'), + Piwik::translate('Goals_Goals'), + Piwik::translate('General_Visitors'), + Piwik::translate('DevicesDetection_DevicesDetection'), + Piwik::translate('UserSettings_VisitorSettings'), + ); + } + + $catA = is_object($a) ? $a->category : $a['category']; + $catB = is_object($b) ? $b->category : $b['category']; + + $orderA = is_object($a) ? $a->order : @$a['order']; + $orderB = is_object($b) ? $b->order : @$b['order']; + + return ($category = strcmp(array_search($catA, $order), array_search($catB, $order))) == 0 + ? ($orderA < $orderB ? -1 : 1) + : $category; + } } diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php index 9f239d7161..b8c73d8d94 100644 --- a/plugins/API/ProcessedReport.php +++ b/plugins/API/ProcessedReport.php @@ -249,7 +249,7 @@ class ProcessedReport Piwik::postEvent('API.getReportMetadata.end', array(&$availableReports, $parameters)); // Sort results to ensure consistent order - usort($availableReports, array($this, 'sort')); + usort($availableReports, array('\Piwik\Plugin\Report', 'sort')); // Add the magic API.get report metadata aggregating all plugins API.get API calls automatically $this->addApiGetMetdata($availableReports); @@ -320,37 +320,6 @@ class ProcessedReport return array_values($availableReports); // make sure array has contiguous key values } - /** - * API metadata are sorted by category/name, - * with a little tweak to replicate the standard Piwik category ordering - * - * @param string $a - * @param string $b - * @return int - */ - private function sort($a, $b) - { - static $order = null; - if (is_null($order)) { - $order = array( - Piwik::translate('General_MultiSitesSummary'), - Piwik::translate('VisitsSummary_VisitsSummary'), - Piwik::translate('Goals_Ecommerce'), - Piwik::translate('General_Actions'), - Piwik::translate('Events_Events'), - Piwik::translate('Actions_SubmenuSitesearch'), - Piwik::translate('Referrers_Referrers'), - Piwik::translate('Goals_Goals'), - Piwik::translate('General_Visitors'), - Piwik::translate('DevicesDetection_DevicesDetection'), - Piwik::translate('UserSettings_VisitorSettings'), - ); - } - return ($category = strcmp(array_search($a['category'], $order), array_search($b['category'], $order))) == 0 - ? (@$a['order'] < @$b['order'] ? -1 : 1) - : $category; - } - /** * Add the metadata for the API.get report * In other plugins, this would hook on 'API.getReportMetadata' diff --git a/plugins/Referrers/Reports/GetAll.php b/plugins/Referrers/Reports/GetAll.php index 8e0390fe28..97b8129af1 100644 --- a/plugins/Referrers/Reports/GetAll.php +++ b/plugins/Referrers/Reports/GetAll.php @@ -12,6 +12,7 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable; use Piwik\Plugins\Referrers\Columns\Referrer; +use Piwik\Plugins\Referrers\Referrers; class GetAll extends Base { @@ -27,7 +28,8 @@ class GetAll extends Base public function configureView(ViewDataTable $view) { - $setGetAllHtmlPrefix = array($this, 'setGetAllHtmlPrefix'); + $referrers = new Referrers(); + $setGetAllHtmlPrefix = array($referrers, 'setGetAllHtmlPrefix'); $view->config->show_exclude_low_population = false; $view->config->show_goals = true; -- GitLab