Skip to content
Extraits de code Groupes Projets
Valider 5526d13d rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

fix most tests, we still need to sort report metadata although the reports are...

fix most tests, we still need to sort report metadata although the reports are already sorted. but as one report can export multiple reportMetadata having different orderIds there is no way around this right now
parent 7924f103
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -39,7 +39,7 @@ class Report ...@@ -39,7 +39,7 @@ class Report
protected $isSubtableReport = null; protected $isSubtableReport = null;
protected $parameters = null; protected $parameters = null;
private static $orderOfReports = array( public static $orderOfReports = array(
'General_MultiSitesSummary', 'General_MultiSitesSummary',
'VisitsSummary_VisitsSummary', 'VisitsSummary_VisitsSummary',
'Goals_Ecommerce', 'Goals_Ecommerce',
...@@ -316,7 +316,7 @@ class Report ...@@ -316,7 +316,7 @@ class Report
* @param Report $b * @param Report $b
* @return int * @return int
*/ */
public static function sort($a, $b) private static function sort($a, $b)
{ {
return ($category = strcmp(array_search($a->category, self::$orderOfReports), array_search($b->category, self::$orderOfReports))) == 0 return ($category = strcmp(array_search($a->category, self::$orderOfReports), array_search($b->category, self::$orderOfReports))) == 0
? ($a->order < $b->order ? -1 : 1) ? ($a->order < $b->order ? -1 : 1)
......
...@@ -245,6 +245,9 @@ class ProcessedReport ...@@ -245,6 +245,9 @@ class ProcessedReport
*/ */
Piwik::postEvent('API.getReportMetadata.end', array(&$availableReports, $parameters)); Piwik::postEvent('API.getReportMetadata.end', array(&$availableReports, $parameters));
// Sort results to ensure consistent order
usort($availableReports, array('self', 'sortReports'));
// Add the magic API.get report metadata aggregating all plugins API.get API calls automatically // Add the magic API.get report metadata aggregating all plugins API.get API calls automatically
$this->addApiGetMetdata($availableReports); $this->addApiGetMetdata($availableReports);
...@@ -314,6 +317,28 @@ class ProcessedReport ...@@ -314,6 +317,28 @@ class ProcessedReport
return array_values($availableReports); // make sure array has contiguous key values 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 array $a
* @param array $b
* @return int
*/
private static function sortReports($a, $b)
{
static $order = null;
if (is_null($order)) {
$order = array();
foreach (Report::$orderOfReports as $category) {
$order[] = Piwik::translate($category);
}
}
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 * Add the metadata for the API.get report
* In other plugins, this would hook on 'API.getReportMetadata' * In other plugins, this would hook on 'API.getReportMetadata'
......
...@@ -47,11 +47,16 @@ class Goals extends \Piwik\Plugin ...@@ -47,11 +47,16 @@ class Goals extends \Piwik\Plugin
public static function sortGoalDimensionsByModule($a, $b) public static function sortGoalDimensionsByModule($a, $b)
{ {
$order = array( static $order = null;
Piwik::translate('Referrers_Referrers'),
Piwik::translate('General_Visit'), if (is_null($order)) {
Piwik::translate('VisitTime_ColumnServerTime'), $order = array(
); Piwik::translate('Referrers_Referrers'),
Piwik::translate('General_Visit'),
Piwik::translate('VisitTime_ColumnServerTime'),
);
}
$orderA = array_search($a, $order); $orderA = array_search($a, $order);
$orderB = array_search($b, $order); $orderB = array_search($b, $order);
return $orderA > $orderB; return $orderA > $orderB;
...@@ -161,7 +166,7 @@ class Goals extends \Piwik\Plugin ...@@ -161,7 +166,7 @@ class Goals extends \Piwik\Plugin
foreach ($reports as &$apiReportToUpdate) { foreach ($reports as &$apiReportToUpdate) {
if ($apiReportToUpdate['module'] == $reportWithGoals['module'] if ($apiReportToUpdate['module'] == $reportWithGoals['module']
&& $apiReportToUpdate['action'] == $reportWithGoals['action'] && $apiReportToUpdate['action'] == $reportWithGoals['action']
) { && empty($apiReportToUpdate['parameters'])) {
$apiReportToUpdate['metricsGoal'] = $goalMetrics; $apiReportToUpdate['metricsGoal'] = $goalMetrics;
$apiReportToUpdate['processedMetricsGoal'] = $goalProcessedMetrics; $apiReportToUpdate['processedMetricsGoal'] = $goalProcessedMetrics;
break; break;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter