diff options
Diffstat (limited to 'core/Plugin/Visualization.php')
-rw-r--r-- | core/Plugin/Visualization.php | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/core/Plugin/Visualization.php b/core/Plugin/Visualization.php index e3a8b51bb1..1695bd04cd 100644 --- a/core/Plugin/Visualization.php +++ b/core/Plugin/Visualization.php @@ -12,6 +12,7 @@ namespace Piwik\Plugin; use Piwik\API\DataTablePostProcessor; use Piwik\API\Proxy; use Piwik\API\Request; +use Piwik\API\Request as ApiRequest; use Piwik\API\ResponseBuilder; use Piwik\Common; use Piwik\Container\StaticContainer; @@ -25,11 +26,12 @@ use Piwik\Option; use Piwik\Period; use Piwik\Piwik; use Piwik\Plugins\API\API as ApiApi; +use Piwik\Plugins\API\Filter\DataComparisonFilter; use Piwik\Plugins\PrivacyManager\PrivacyManager; +use Piwik\SettingsPiwik; use Piwik\View; use Piwik\ViewDataTable\Manager as ViewDataTableManager; use Piwik\Plugin\Manager as PluginManager; -use Piwik\API\Request as ApiRequest; use Psr\Log\LoggerInterface; /** @@ -247,6 +249,17 @@ class Visualization extends ViewDataTable $view->footerIcons = $this->config->footer_icons; $view->isWidget = Common::getRequestVar('widget', 0, 'int'); $view->notifications = []; + $view->isComparing = $this->isComparing(); + + if (!$this->supportsComparison() + && DataComparisonFilter::isCompareParamsPresent() + && empty($view->dataTableHasNoData) + ) { + if (empty($view->properties['show_footer_message'])) { + $view->properties['show_footer_message'] = ''; + } + $view->properties['show_footer_message'] .= '<br/>' . Piwik::translate('General_VisualizationDoesNotSupportComparison'); + } if (empty($this->dataTable) || !$this->hasAnyData($this->dataTable)) { /** @@ -405,6 +418,19 @@ class Visualization extends ViewDataTable $hasNbVisits = in_array('nb_visits', $columns); $hasNbUniqVisitors = in_array('nb_uniq_visitors', $columns); + // if any comparison period doesn't support unique visitors, we can't display it for the main table + if ($this->isComparing()) { + $request = $this->getRequestArray(); + if (!empty($request['comparePeriods'])) { + foreach ($request['comparePeriods'] as $comparePeriod) { + if (!SettingsPiwik::isUniqueVisitorsEnabled($comparePeriod)) { + $hasNbUniqVisitors = false; + break; + } + } + } + } + // default columns_to_display to label, nb_uniq_visitors/nb_visits if those columns exist in the // dataset. otherwise, default to all columns in dataset. if (empty($this->config->columns_to_display)) { @@ -492,7 +518,6 @@ class Visualization extends ViewDataTable foreach ($self->config->getPresentationFilters() as $filter) { $dataTable->queueFilter($filter[0], $filter[1]); } - }); $this->dataTable = $postProcessor->process($this->dataTable); @@ -668,6 +693,10 @@ class Visualization extends ViewDataTable $javascriptVariablesToSet['segment'] = $rawSegment; } + if (isset($javascriptVariablesToSet['compareSegments'])) { + $javascriptVariablesToSet['compareSegments'] = Common::unsanitizeInputValues($javascriptVariablesToSet['compareSegments']); + } + return $javascriptVariablesToSet; } @@ -801,8 +830,7 @@ class Visualization extends ViewDataTable */ public function buildApiRequestArray() { - $requestArray = $this->request->getRequestArray(); - $request = ApiRequest::getRequestArrayFromString($requestArray); + $request = $this->getRequestArray(); if (false === $this->config->enable_sort) { $request['filter_sort_column'] = ''; @@ -817,6 +845,10 @@ class Visualization extends ViewDataTable unset($request['disable_queued_filters']); } + if ($this->isComparing()) { + $request['compare'] = '1'; + } + return $request; } } |