Skip to content

Commit

Permalink
Refs #4363 display correct row evolution title for actions URL reports.
Browse files Browse the repository at this point in the history
  • Loading branch information
diosmosis committed Dec 9, 2013
1 parent 53005c8 commit 346ef97
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions plugins/API/RowEvolution.php
Expand Up @@ -22,6 +22,7 @@
use Piwik\Period;
use Piwik\Piwik;
use Piwik\Url;
use Piwik\Site;

/**
* This class generates a Row evolution dataset, from input request
Expand All @@ -30,6 +31,13 @@
*/
class RowEvolution
{
private static $actionsUrlReports = array(
'getPageUrls',
'getPageUrlsFollowingSiteSearch',
'getEntryPageUrls',
'getExitPageUrls',
'getPageUrl'
);

public function getRowEvolution($idSite, $period, $date, $apiModule, $apiAction, $label = false, $segment = false, $column = false, $language = false, $idGoal = false, $legendAppendMetric = true, $labelUseAbsoluteUrl = true)
{
Expand Down Expand Up @@ -67,6 +75,7 @@ public function getRowEvolution($idSite, $period, $date, $apiModule, $apiAction,
);
} else {
$data = $this->getSingleRowEvolution(
$idSite,
$dataTable,
$metadata,
$apiModule,
Expand Down Expand Up @@ -132,7 +141,7 @@ protected function getLabelsFromDataTable($dataTable, $labels)
* @param bool $labelUseAbsoluteUrl
* @return array containing report data, metadata, label, logo
*/
private function getSingleRowEvolution($dataTable, $metadata, $apiModule, $apiAction, $label, $labelUseAbsoluteUrl = true)
private function getSingleRowEvolution($idSite, $dataTable, $metadata, $apiModule, $apiAction, $label, $labelUseAbsoluteUrl = true)
{
$metricNames = array_keys($metadata['metrics']);

Expand Down Expand Up @@ -171,7 +180,7 @@ private function getSingleRowEvolution($dataTable, $metadata, $apiModule, $apiAc

// if we have a recursive label and no url, use the path
if (!$urlFound) {
$actualLabel = str_replace(LabelFilter::SEPARATOR_RECURSIVE_LABEL, ' - ', $label);
$actualLabel = $this->formatQueryLabelForDisplay($idSite, $apiModule, $apiAction, $label);
}

$return = array(
Expand All @@ -185,6 +194,25 @@ private function getSingleRowEvolution($dataTable, $metadata, $apiModule, $apiAc
return $return;
}

private function formatQueryLabelForDisplay($idSite, $apiModule, $apiAction, $label)
{
// rows with subtables do not contain URL metadata. this hack makes sure the label titles in row
// evolution popovers look like URLs.
if ($apiModule == 'Actions'
&& in_array($apiAction, self::$actionsUrlReports)
) {
$mainUrl = Site::getMainUrlFor($idSite);
$mainUrlHost = @parse_url($mainUrl, PHP_URL_HOST);

$replaceRegex = "/\\s*" . preg_quote(LabelFilter::SEPARATOR_RECURSIVE_LABEL) . "\\s*/";
$cleanLabel = preg_replace($replaceRegex, '/', $label);

return $mainUrlHost . '/' . $cleanLabel . '/';
} else {
return str_replace(LabelFilter::SEPARATOR_RECURSIVE_LABEL, ' - ', $label);
}
}

/**
* @param Row $row
* @param string $apiModule
Expand Down

0 comments on commit 346ef97

Please sign in to comment.