diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-11-03 00:55:32 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2015-11-04 23:02:10 +0300 |
commit | 8c970d3ecd5ee10825882eee2dfaf60f92a3a6ea (patch) | |
tree | 264a701b99ef0b77ade9ef7bdbacfe85d12a2318 /core | |
parent | 89eb98b2fdaf3fa72a4a038daa050764f904ecc6 (diff) |
changed look of custom variables screen, merge metadata when specified
Diffstat (limited to 'core')
-rw-r--r-- | core/DataTable/Row.php | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/core/DataTable/Row.php b/core/DataTable/Row.php index 973974033c..ad8a850ca0 100644 --- a/core/DataTable/Row.php +++ b/core/DataTable/Row.php @@ -479,7 +479,7 @@ class Row implements \ArrayAccess, \IteratorAggregate } if ($enableCopyMetadata) { - $this->sumRowMetadata($rowToSum); + $this->sumRowMetadata($rowToSum, $aggregationOperations); } } @@ -506,6 +506,19 @@ class Row implements \ArrayAccess, \IteratorAggregate case 'sum': $newValue = $this->sumRowArray($thisColumnValue, $columnToSumValue); break; + case 'uniquearraymerge': + if (is_array($thisColumnValue) && is_array($columnToSumValue)) { + foreach ($columnToSumValue as $columnSum) { + if (!in_array($columnSum, $thisColumnValue)) { + $thisColumnValue[] = $columnSum; + } + } + } elseif (!is_array($thisColumnValue) && is_array($columnToSumValue)) { + $thisColumnValue = $columnToSumValue; + } + + $newValue = $thisColumnValue; + break; default: throw new Exception("Unknown operation '$operation'."); } @@ -516,12 +529,29 @@ class Row implements \ArrayAccess, \IteratorAggregate * Sums the metadata in `$rowToSum` with the metadata in `$this` row. * * @param Row $rowToSum + * @param array $aggregationOperations */ - public function sumRowMetadata($rowToSum) + public function sumRowMetadata($rowToSum, $aggregationOperations = array()) { if (!empty($rowToSum->metadata) && !$this->isSummaryRow() ) { + $aggregatedMetadata = array(); + + if (is_array($aggregationOperations)) { + // we need to aggregate value before value is overwritten by maybe another row + foreach ($aggregationOperations as $columnn => $operation) { + $thisMetadata = $this->getMetadata($columnn); + $sumMetadata = $rowToSum->getMetadata($columnn); + + if ($thisMetadata === false && $sumMetadata === false) { + continue; + } + + $aggregatedMetadata[$columnn] = $this->getColumnValuesMerged($operation, $thisMetadata, $sumMetadata); + } + } + // We shall update metadata, and keep the metadata with the _most visits or pageviews_, rather than first or last seen $visits = max($rowToSum->getColumn(Metrics::INDEX_PAGE_NB_HITS) || $rowToSum->getColumn(Metrics::INDEX_NB_VISITS), // Old format pre-1.2, @see also method doSumVisitsMetrics() @@ -532,6 +562,11 @@ class Row implements \ArrayAccess, \IteratorAggregate $this->maxVisitsSummed = $visits; $this->metadata = $rowToSum->metadata; } + + foreach ($aggregatedMetadata as $column => $value) { + // we need to make sure aggregated value is used, and not metadata from $rowToSum + $this->setMetadata($column, $value); + } } } |