diff --git a/core/Plugin/Report.php b/core/Plugin/Report.php index af80dd6be637d3d4d3eb571d0265e766dba5a9f8..c47f2ce5ec2471c62b79042829c95e2480e69e2b 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 9f239d716190246bbdb1e88ef65f755ce8256cac..b8c73d8d94621b227026176cbfa7920ae68740c2 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 8e0390fe283079be0bc819150dde1dfe317c58b1..97b8129af11813dcd67655c4b03932b2dc78fc5d 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;