From 4d4cbf4412e050ad1d29633b1d06d0cac97ca59b Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Wed, 20 Nov 2013 20:16:37 +0000 Subject: [PATCH] refs #1816 this should set the correct value in case we are dealing with dataTable\maps, probably there will be still an issue with idSubtables --- core/API/DataTableManipulator/Totals.php | 24 ++++++++++++------------ plugins/API/ProcessedReport.php | 20 ++++++++++++++++---- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/core/API/DataTableManipulator/Totals.php b/core/API/DataTableManipulator/Totals.php index 309844b8be1..86d1a8796b2 100644 --- a/core/API/DataTableManipulator/Totals.php +++ b/core/API/DataTableManipulator/Totals.php @@ -59,18 +59,18 @@ protected function manipulateDataTable($dataTable) return $dataTable; } - if (empty($this->totalValues)) { - $metricsToCalculate = Metrics::getMetricIdsToProcessRatio(); - $parentTable = $this->getFirstLevelDataTable($dataTable); - - foreach ($metricsToCalculate as $metricId) { - if (!$this->hasDataTableMetric($parentTable, $metricId)) { - continue; - } - - foreach ($parentTable->getRows() as $row) { - $this->addColumnValueToTotal($row, $metricId); - } + $this->totalValues = array(); + + $metricsToCalculate = Metrics::getMetricIdsToProcessRatio(); + $parentTable = $this->getFirstLevelDataTable($dataTable); + + foreach ($metricsToCalculate as $metricId) { + if (!$this->hasDataTableMetric($parentTable, $metricId)) { + continue; + } + + foreach ($parentTable->getRows() as $row) { + $this->addColumnValueToTotal($row, $metricId); } } diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php index 10209b113b0..9e2be1e330a 100644 --- a/plugins/API/ProcessedReport.php +++ b/plugins/API/ProcessedReport.php @@ -405,6 +405,7 @@ private function handleTableReport($idSite, $dataTable, &$reportMetadata, $showR } $columns = $this->hideShowMetrics($columns); + $totals = array(); // $dataTable is an instance of Set when multiple periods requested if ($dataTable instanceof DataTable\Map) { @@ -426,15 +427,26 @@ private function handleTableReport($idSite, $dataTable, &$reportMetadata, $showR $period = $simpleDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLocalizedLongString(); $newReport->addTable($enhancedSimpleDataTable, $period); $rowsMetadata->addTable($rowMetadata, $period); + + if ($simpleDataTable->getMetadata('totals')) { + $simpleTotals = $this->hideShowMetrics($simpleDataTable->getMetadata('totals')); + + foreach ($simpleTotals as $metric => $value) { + if (!array_key_exists($metric, $totals)) { + $totals[$metric] = $value; + } else { + $totals[$metric] += $value; + } + } + } } } else { $this->removeEmptyColumns($columns, $reportMetadata, $dataTable); list($newReport, $rowsMetadata) = $this->handleSimpleDataTable($idSite, $dataTable, $columns, $hasDimension, $showRawMetrics); - } - $totals = array(); - if ($dataTable->getMetadata('totals')) { - $totals = $this->hideShowMetrics($dataTable->getMetadata('totals')); + if ($dataTable->getMetadata('totals')) { + $totals = $this->hideShowMetrics($dataTable->getMetadata('totals')); + } } return array(