From 221b74d38a006b0cede71423bbc1d98d82066539 Mon Sep 17 00:00:00 2001 From: Timo Besenreuther Date: Mon, 8 Apr 2013 16:31:44 +0200 Subject: [PATCH] refs #3158 row evolution * bug fix: the export beneath row evolution graphs didn't work. the reason was that it passed an expanded=1 and a label parameter to the API. solution: ignore expanded parameter if label parameter is set. * small code improvements --- core/API/DataTableManipulator/LabelFilter.php | 8 ++------ core/API/Request.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/core/API/DataTableManipulator/LabelFilter.php b/core/API/DataTableManipulator/LabelFilter.php index f2aa0020dae..550781bd18b 100644 --- a/core/API/DataTableManipulator/LabelFilter.php +++ b/core/API/DataTableManipulator/LabelFilter.php @@ -17,11 +17,6 @@ * The labels passed to this class should be urlencoded. * Some reports use recursive labels (e.g. action reports). Use > to join them. * - * This filter does not work when expanded=1 is set because it is designed to load - * only the subtables on the path, not all existing subtables (which would happen with - * expanded=1). Also, the aim of this filter is to return only the row matching the - * label. With expanded=1, the subtables of the matching row would be returned as well. - * * @package Piwik * @subpackage Piwik_API */ @@ -69,6 +64,7 @@ private function doFilterRecursiveDescend($labelParts, $dataTable) // search for the first part of the tree search $labelPart = array_shift($labelParts); + $row = false; foreach ($this->getLabelVariations($labelPart) as $labelPart) { $row = $dataTable->getRowFromLabel($labelPart); if ($row !== false) { @@ -141,7 +137,7 @@ private function getLabelVariations($label) protected function manipulateDataTable($dataTable) { $result = $dataTable->getEmptyClone(); - foreach ($this->labels as $labelIdx => $label) { + foreach ($this->labels as $label) { $row = null; foreach ($this->getLabelVariations($label) as $labelVariation) { $labelVariation = explode(self::SEPARATOR_RECURSIVE_LABEL, $labelVariation); diff --git a/core/API/Request.php b/core/API/Request.php index e0147bb58da..1ce66abf379 100644 --- a/core/API/Request.php +++ b/core/API/Request.php @@ -85,6 +85,23 @@ static public function getRequestArrayFromString($request) function __construct($request = null) { $this->request = self::getRequestArrayFromString($request); + $this->sanitizeRequest(); + } + + /** + * Make sure that the request contains no logical errors + */ + private function sanitizeRequest() + { + // The label filter does not work with expanded=1 because the data table IDs have a different meaning + // depending on whether the table has been loaded yet. expanded=1 causes all tables to be loaded, which + // is why the label filter can't descend when a recursive label has been requested. + // To fix this, we remove the expanded parameter if a label parameter is set. + if (isset($this->request['label']) && !empty($this->request['label']) + && isset($this->request['expanded']) && $this->request['expanded'] + ) { + unset($this->request['expanded']); + } } /**