Skip to content

Commit

Permalink
by sorting the reports before returning them we make sure the widgets…
Browse files Browse the repository at this point in the history
… will be added in the correct order which again makes sure the dashboard ui tests adds the widgets in the right order
  • Loading branch information
tsteur committed Jun 13, 2014
1 parent 62cfd9d commit 83ee5a4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
39 changes: 39 additions & 0 deletions core/Plugin/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,46 @@ public static function getAllReports()
$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;
}
}
33 changes: 1 addition & 32 deletions plugins/API/ProcessedReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public function getReportMetadata($idSites, $period = false, $date = false, $hid
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);
Expand Down Expand Up @@ -320,37 +320,6 @@ public function getReportMetadata($idSites, $period = false, $date = false, $hid
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'
Expand Down
4 changes: 3 additions & 1 deletion plugins/Referrers/Reports/GetAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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
{
Expand All @@ -27,7 +28,8 @@ protected function init()

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;
Expand Down

0 comments on commit 83ee5a4

Please sign in to comment.