Skip to content

Commit

Permalink
fixes #4299 - set site name in past data label column so CalculateEvo…
Browse files Browse the repository at this point in the history
…lutionFilter can lookup divisor
  • Loading branch information
julienmoumne committed Nov 16, 2013
1 parent 9793994 commit 0fafe1b
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions plugins/MultiSites/API.php
Expand Up @@ -213,21 +213,7 @@ private function buildDataTable($idSitesOrIdSite, $period, $date, $segment, $_re
// $dataTable instanceOf Set
$dataTable = $archive->getDataTableFromNumeric($fieldsToGet);

// get rid of the DataTable\Map that is created by the IndexedBySite archive type
if ($dataTable instanceof DataTable\Map
&& $multipleWebsitesRequested
) {
$dataTable = $dataTable->mergeChildren();
} else {
if (!($dataTable instanceof DataTable\Map)
&& $dataTable->getRowsCount() > 0
) {
$firstSite = is_array($idSitesOrIdSite) ? reset($idSitesOrIdSite) : $idSitesOrIdSite;

$firstDataTableRow = $dataTable->getFirstRow();
$firstDataTableRow->setColumn('label', $firstSite);
}
}
$dataTable= $this->mergeDataTableMapAndPopulateLabel($idSitesOrIdSite, $multipleWebsitesRequested, $dataTable);

if ($dataTable instanceof DataTable\Map) {
foreach ($dataTable->getDataTables() as $table) {
Expand All @@ -243,21 +229,21 @@ private function buildDataTable($idSitesOrIdSite, $period, $date, $segment, $_re
// if the period isn't a range & a lastN/previousN date isn't used, we get the same
// data for the last period to show the evolution of visits/actions/revenue
list($strLastDate, $lastPeriod) = Range::getLastDate($date, $period);

if ($strLastDate !== false) {

if ($lastPeriod !== false) {
// NOTE: no easy way to set last period date metadata when range of dates is requested.
// will be easier if DataTable\Map::metadata is removed, and metadata that is
// put there is put directly in DataTable::metadata.
$dataTable->setMetadata(self::getLastPeriodMetadataName('date'), $lastPeriod);
}

$pastArchive = Archive::build($idSitesOrIdSite, $period, $strLastDate, $segment, $_restrictSitesToLogin);

$pastData = $pastArchive->getDataTableFromNumeric($fieldsToGet);

if ($pastData instanceof DataTable\Map
&& $multipleWebsitesRequested
) {
$pastData = $pastData->mergeChildren();
}
$pastData = $this->mergeDataTableMapAndPopulateLabel($idSitesOrIdSite, $multipleWebsitesRequested, $pastData);

// use past data to calculate evolution percentages
$this->calculateEvolutionPercentages($dataTable, $pastData, $apiMetrics);
Expand Down Expand Up @@ -521,5 +507,27 @@ private function removeEcommerceRelatedMetricsOnNonEcommercePiwikSites($dataTabl
}
}
}

private function mergeDataTableMapAndPopulateLabel($idSitesOrIdSite, $multipleWebsitesRequested, $dataTable)
{
// get rid of the DataTable\Map that is created by the IndexedBySite archive type
if ($dataTable instanceof DataTable\Map && $multipleWebsitesRequested) {

return $dataTable->mergeChildren();

} else {

if (!$dataTable instanceof DataTable\Map && $dataTable->getRowsCount() > 0) {

$firstSite = is_array($idSitesOrIdSite) ? reset($idSitesOrIdSite) : $idSitesOrIdSite;

$firstDataTableRow = $dataTable->getFirstRow();

$firstDataTableRow->setColumn('label', $firstSite);
}
}

return $dataTable;
}
}

0 comments on commit 0fafe1b

Please sign in to comment.