Skip to content
Extraits de code Groupes Projets
Valider c91a6034 rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Fixes #3897, make sure filter_limit limits the number of labels returned when...

Fixes #3897, make sure filter_limit limits the number of labels returned when no labels are specified with multi-row evolution and make sure it has no effect in all other row evolution cases.
parent a8420c06
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -1176,12 +1176,23 @@ class Piwik_API_API ...@@ -1176,12 +1176,23 @@ class Piwik_API_API
} }
$labels = array_values(array_unique($labels)); $labels = array_values(array_unique($labels));
// if the filter_limit query param is set, treat it as a request to limit
// the number of labels used
$limit = Piwik_Common::getRequestVar('filter_limit', false);
if ($limit != false
&& $limit >= 0
) {
$labels = array_slice($labels, 0, $limit);
}
// set label index metadata // set label index metadata
$labelsToIndex = array_flip($labels); $labelsToIndex = array_flip($labels);
foreach ($dataTable->getArray() as $table) { foreach ($dataTable->getArray() as $table) {
foreach ($table->getRows() as $row) { foreach ($table->getRows() as $row) {
$label = $row->getColumn('label'); $label = $row->getColumn('label');
$row->setMetadata('label_index', $labelsToIndex[$label]); if (isset($labelsToIndex[$label])) {
$row->setMetadata('label_index', $labelsToIndex[$label]);
}
} }
} }
} }
...@@ -1324,6 +1335,9 @@ class Piwik_API_API ...@@ -1324,6 +1335,9 @@ class Piwik_API_API
'serialize' => '0', 'serialize' => '0',
'segment' => $segment, 'segment' => $segment,
'idGoal' => $idGoal, 'idGoal' => $idGoal,
// data for row evolution should NOT be limited
'filter_limit' => -1,
// if more than one label is used, we add metadata to ensure we know which // if more than one label is used, we add metadata to ensure we know which
// row corresponds with which label (since the labels can change, and rows // row corresponds with which label (since the labels can change, and rows
...@@ -1564,9 +1578,10 @@ class Piwik_API_API ...@@ -1564,9 +1578,10 @@ class Piwik_API_API
*/ */
private function getRowEvolutionRowFromLabelIdx($table, $labelIdx) private function getRowEvolutionRowFromLabelIdx($table, $labelIdx)
{ {
$labelIdx = (int)$labelIdx;
foreach ($table->getRows() as $row) foreach ($table->getRows() as $row)
{ {
if ($row->getMetadata('label_index') == $labelIdx) if ($row->getMetadata('label_index') === $labelIdx)
{ {
return $row; return $row;
} }
......
...@@ -75,6 +75,7 @@ class Test_Piwik_Integration_RowEvolution extends IntegrationTestCase ...@@ -75,6 +75,7 @@ class Test_Piwik_Integration_RowEvolution extends IntegrationTestCase
. ',Google>' . urlencode(strtolower($keywords[2])); . ',Google>' . urlencode(strtolower($keywords[2]));
// Test multiple labels search engines, Google should also have a 'logo' entry // Test multiple labels search engines, Google should also have a 'logo' entry
$config['otherRequestParameters']['label'] = urlencode($keywordsStr . ",Google"); $config['otherRequestParameters']['label'] = urlencode($keywordsStr . ",Google");
$config['otherRequestParameters']['filter_limit'] = 1; // should have no effect
$return[] = array('API.getRowEvolution', $config); $return[] = array('API.getRowEvolution', $config);
// Actions > Pages titles, standard label // Actions > Pages titles, standard label
...@@ -83,6 +84,7 @@ class Test_Piwik_Integration_RowEvolution extends IntegrationTestCase ...@@ -83,6 +84,7 @@ class Test_Piwik_Integration_RowEvolution extends IntegrationTestCase
$config['otherRequestParameters']['apiModule'] = 'Actions'; $config['otherRequestParameters']['apiModule'] = 'Actions';
$config['otherRequestParameters']['apiAction'] = 'getPageTitles'; $config['otherRequestParameters']['apiAction'] = 'getPageTitles';
$config['otherRequestParameters']['label'] = urlencode('incredible title 0'); $config['otherRequestParameters']['label'] = urlencode('incredible title 0');
$config['otherRequestParameters']['filter_limit'] = 1; // should have no effect
$return[] = array('API.getRowEvolution', $config); $return[] = array('API.getRowEvolution', $config);
// Actions > Page titles, multiple labels // Actions > Page titles, multiple labels
...@@ -154,6 +156,21 @@ class Test_Piwik_Integration_RowEvolution extends IntegrationTestCase ...@@ -154,6 +156,21 @@ class Test_Piwik_Integration_RowEvolution extends IntegrationTestCase
) )
)); ));
// test multi row evolution w/ filter_limit to limit all available labels
$return[] = array('API.getRowEvolution', array(
'testSuffix' => '_multiWithFilterLimit',
'periods' => 'day',
'idSite' => $idSite,
'date' => $today,
'otherRequestParameters' => array(
'date' => '2010-03-01,2010-03-06',
'period' => 'day',
'apiModule' => 'Referers',
'apiAction' => 'getWebsites',
'filter_limit' => 3, // only 3 labels should show up
)
));
// (non-rowevolution test) test flattener w/ search engines to make sure // (non-rowevolution test) test flattener w/ search engines to make sure
// queued filters are not applied twice // queued filters are not applied twice
$return[] = array('Referers.getSearchEngines', array( $return[] = array('Referers.getSearchEngines', array(
......
<?xml version="1.0" encoding="utf-8" ?>
<result>
<column>nb_visits</column>
<reportData>
<result date="2010-03-01">
<row>
<nb_visits_0>1</nb_visits_0>
<nb_visits_1>0</nb_visits_1>
<nb_visits_2>0</nb_visits_2>
</row>
</result>
<result date="2010-03-02">
<row>
<nb_visits_0>0</nb_visits_0>
<nb_visits_1>1</nb_visits_1>
<nb_visits_2>0</nb_visits_2>
</row>
</result>
<result date="2010-03-03">
<row>
<nb_visits_0>0</nb_visits_0>
<nb_visits_1>0</nb_visits_1>
<nb_visits_2>1</nb_visits_2>
</row>
</result>
<result date="2010-03-04">
<row>
<nb_visits_0>0</nb_visits_0>
<nb_visits_1>0</nb_visits_1>
<nb_visits_2>0</nb_visits_2>
</row>
</result>
<result date="2010-03-05">
<row>
<nb_visits_0>0</nb_visits_0>
<nb_visits_1>0</nb_visits_1>
<nb_visits_2>0</nb_visits_2>
</row>
</result>
<result date="2010-03-06">
<row>
<nb_visits_0>1</nb_visits_0>
<nb_visits_1>0</nb_visits_1>
<nb_visits_2>0</nb_visits_2>
</row>
</result>
</reportData>
<metadata>
<metrics>
<nb_visits_0>
<name>www.referrer0.com (Visits)</name>
<min>0</min>
<max>1</max>
<change>0%</change>
</nb_visits_0>
<nb_visits_1>
<name>www.referrer4.com (Visits)</name>
<min>0</min>
<max>1</max>
</nb_visits_1>
<nb_visits_2>
<name>www.referrer3.com (Visits)</name>
<min>0</min>
<max>1</max>
</nb_visits_2>
</metrics>
<dimension>Website</dimension>
<columns>
<nb_visits>Visits</nb_visits>
<nb_uniq_visitors>Unique visitors</nb_uniq_visitors>
<nb_actions>Actions</nb_actions>
<nb_actions_per_visit>Actions per Visit</nb_actions_per_visit>
<avg_time_on_site>Avg. Time on Website</avg_time_on_site>
<bounce_rate>Bounce Rate</bounce_rate>
</columns>
</metadata>
</result>
\ No newline at end of file
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