diff options
author | diosmosis <benaka@piwik.pro> | 2014-09-21 02:34:52 +0400 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2014-09-21 03:02:41 +0400 |
commit | 96895068207ec39e0c110307a0d2f987970752e5 (patch) | |
tree | 677966c4c99e910116351e05756921f9696400f7 /core/DataTable/Filter/PivotByDimension.php | |
parent | 33cc6c77bc789a6d957272b1fec4a15a7d6ffb2b (diff) |
Refs #6078, prepend numeral index to each column in pivotted datatable.
Diffstat (limited to 'core/DataTable/Filter/PivotByDimension.php')
-rw-r--r-- | core/DataTable/Filter/PivotByDimension.php | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/core/DataTable/Filter/PivotByDimension.php b/core/DataTable/Filter/PivotByDimension.php index ba4f0220f6..fd176f8cf5 100644 --- a/core/DataTable/Filter/PivotByDimension.php +++ b/core/DataTable/Filter/PivotByDimension.php @@ -215,7 +215,7 @@ class PivotByDimension extends BaseFilter $others = Piwik::translate('General_Others'); $defaultRow = $this->getPivotTableDefaultRowFromColumnSummary($columnSet, $others); - Log::debug("PivotByDimension::%s: processed pivoted columns: %s", __FUNCTION__, $defaultRow); + Log::debug("PivotByDimension::%s: un-prepended default row: %s", __FUNCTION__, $defaultRow); // post process pivoted datatable foreach ($table->getRows() as $row) { @@ -238,6 +238,18 @@ class PivotByDimension extends BaseFilter $table->clearQueuedFilters(); // TODO: shouldn't clear queued filters, but we can't wait for them to be run // since generic filters are run before them. remove after refactoring // processed metrics. + + // prepend numerals to columns in a queued filter (this way, disable_queued_filters can be used + // to get machine readable data from the API if needed) + $prependedColumnNames = $this->getOrderedColumnsWithPrependedNumerals($defaultRow, $others); + + Log::debug("PivotByDimension::%s: prepended column name mapping: %s", __FUNCTION__, $prependedColumnNames); + + $table->queueFilter(function (DataTable $table) use ($prependedColumnNames) { + foreach ($table->getRows() as $row) { + $row->setColumns(array_combine($prependedColumnNames, $row->getColumns())); + } + }); } /** @@ -445,6 +457,27 @@ class PivotByDimension extends BaseFilter return $columnSet; } + private function getOrderedColumnsWithPrependedNumerals($defaultRow, $othersRowLabel) + { + $result = array(); + + $currentIndex = 1; + foreach ($defaultRow as $columnName => $ignore) { + if ($columnName == $othersRowLabel + || $columnName == 'label' + ) { + $result[] = $columnName; + } else { + $modifiedColumnName = $currentIndex . '. ' . $columnName; + $result[] = $modifiedColumnName; + + ++$currentIndex; + } + } + + return $result; + } + /** * Returns true if pivoting by subtable is supported for a report. Will return true if the report * has a subtable dimension and if the subtable dimension is different than the report's dimension. |