diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2017-01-04 01:53:07 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2017-01-04 01:53:07 +0300 |
commit | 28730ab87628034aeda3fe01b1ee7523e2a3c244 (patch) | |
tree | 97e75378811bf24d7f057f6e7437bf53a688669f /plugins/MultiSites | |
parent | 193a9bb8b13bfdce69731181d3dad102f7e14f6b (diff) |
added new event for totals calculation (#11139)
Diffstat (limited to 'plugins/MultiSites')
-rwxr-xr-x | plugins/MultiSites/API.php | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/plugins/MultiSites/API.php b/plugins/MultiSites/API.php index 8e2ce0c1a3..2312ebfec3 100755 --- a/plugins/MultiSites/API.php +++ b/plugins/MultiSites/API.php @@ -440,7 +440,11 @@ class API extends \Piwik\Plugin\API $totals[$label] = 0; } - foreach ($dataTable->getRows() as $row) { + $rows = $dataTable->getRows(); + + $rows = $this->filterRowsForTotalsCalculation($rows); + + foreach ($rows as $row) { foreach ($apiMetrics as $totalMetadataName => $recordName) { $totals[$totalMetadataName] += $row->getColumn($recordName); } @@ -462,7 +466,10 @@ class API extends \Piwik\Plugin\API $total = 0; $metric = 'nb_visits'; - foreach ($pastTable->getRows() as $row) { + $rows = $pastTable->getRows(); + $rows = $this->filterRowsForTotalsCalculation($rows); + + foreach ($rows as $row) { $total += $row->getColumn($metric); } @@ -470,6 +477,34 @@ class API extends \Piwik\Plugin\API } } + /** + * @param Row[] $rows + * @return mixed + */ + private function filterRowsForTotalsCalculation($rows) + { + /** + * Triggered to filter / restrict which rows should be included in the MultiSites (All Websites Dashboard) + * totals calculation + * + * **Example** + * + * public function filterMultiSitesRows(&$rows) + * { + * foreach ($rows as $index => $row) { + * if ($row->getColumn('label') === 5) { + * unset($rows[$index]); // remove idSite 5 from totals + * } + * } + * } + * + * @param Row[] &$rows An array containing rows, one row for each site. The label columns equals the idSite. + */ + Piwik::postEvent('MultiSites.filterRowsForTotalsCalculation', array(&$rows)); + + return $rows; + } + private static function getTotalMetadataName($name) { return 'total_' . $name; |