Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Giehl <stefan@piwik.org>2017-03-29 11:09:18 +0300
committerMatthieu Aubry <mattab@users.noreply.github.com>2017-03-29 11:09:18 +0300
commit5d46f802f0485c504c3923aa625032ca998048cf (patch)
tree6f36e18d37c80dc00bfd2480ee1607b1df9b1fe5
parentf9c555e5c1ac3bfc49559386f3a7c9d12703a762 (diff)
Make it possible to disable flattening for an report (#11529)
* use report property to enable/disable flattener * update tests * Update changelog [ci skip] * minor renamings
-rw-r--r--CHANGELOG.md1
-rw-r--r--core/API/DataTablePostProcessor.php6
-rw-r--r--core/DataTable/Filter/RemoveSubtables.php47
-rw-r--r--core/Plugin/Report.php17
-rw-r--r--core/ViewDataTable/Config.php10
-rw-r--r--plugins/Referrers/Reports/GetReferrerType.php1
-rw-r--r--plugins/UserId/Reports/GetUsers.php12
-rw-r--r--tests/PHPUnit/System/expected/test_reportLimiting_flattened__Referrers.getReferrerType_day.xml62
-rw-r--r--tests/UI/expected-screenshots/UIIntegrationTest_metric_tooltip.png4
9 files changed, 100 insertions, 60 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7a0c7a7ba4..4e71995db5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ The Product Changelog at **[piwik.org/changelog](http://piwik.org/changelog)** l
### Breaking Changes
* New config setting `enable_plugin_upload` lets you enable uploading and installing a Piwik plugin ZIP file by a Super User. This used to be enabled by default, but it is now disabled by default now for security reasons.
+* New Report class property `Report::$supportsFlatten` lets you define if a report supports flattening (defaults to `true`). If set to `false` it will also set `ViewDataTable\Config::$show_flatten_table` to `false`
### New APIs
* A new event `Controller.triggerAdminNotifications` has been added to let plugins know when they are supposed to trigger notifications in the admin.
diff --git a/core/API/DataTablePostProcessor.php b/core/API/DataTablePostProcessor.php
index c2fdd1569c..c4eb7441d0 100644
--- a/core/API/DataTablePostProcessor.php
+++ b/core/API/DataTablePostProcessor.php
@@ -170,6 +170,12 @@ class DataTablePostProcessor
public function applyFlattener($dataTable)
{
if (Common::getRequestVar('flat', '0', 'string', $this->request) == '1') {
+ // skip flattening if not supported by report and remove subtables only
+ if ($this->report && !$this->report->supportsFlatten()) {
+ $dataTable->filter('RemoveSubtables');
+ return $dataTable;
+ }
+
$flattener = new Flattener($this->apiModule, $this->apiMethod, $this->request);
if (Common::getRequestVar('include_aggregate_rows', '0', 'string', $this->request) == '1') {
$flattener->includeAggregateRows();
diff --git a/core/DataTable/Filter/RemoveSubtables.php b/core/DataTable/Filter/RemoveSubtables.php
new file mode 100644
index 0000000000..e84244119c
--- /dev/null
+++ b/core/DataTable/Filter/RemoveSubtables.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\BaseFilter;
+
+/**
+ * Delete all existing subtables from rows.
+ *
+ * **Basic example usage**
+ *
+ * $dataTable->filter('RemoveSubtables');
+ *
+ * @api
+ */
+class RemoveSubtables extends BaseFilter
+{
+ /**
+ * Constructor.
+ *
+ * @param DataTable $table The DataTable that will be filtered eventually.
+ */
+ public function __construct($table)
+ {
+ parent::__construct($table);
+ }
+
+ /**
+ * See {@link Limit}.
+ *
+ * @param DataTable $table
+ */
+ public function filter($table)
+ {
+ $rows = $table->getRows();
+ foreach ($rows as $row) {
+ $row->removeSubtable();
+ }
+ }
+}
diff --git a/core/Plugin/Report.php b/core/Plugin/Report.php
index 7bdbf0710e..df28f450c9 100644
--- a/core/Plugin/Report.php
+++ b/core/Plugin/Report.php
@@ -120,6 +120,14 @@ class Report
protected $hasGoalMetrics = false;
/**
+ * Set this property to false in case your report can't/shouldn't be flattened.
+ * In this case, flattener won't be applied even if parameter is provided in a request
+ * @var bool
+ * @api
+ */
+ protected $supportsFlatten = true;
+
+ /**
* Set it to boolean `true` if your report always returns a constant count of rows, for instance always 24 rows
* for 1-24 hours.
* @var bool
@@ -494,6 +502,15 @@ class Report
}
/**
+ * @return bool
+ * @ignore
+ */
+ public function supportsFlatten()
+ {
+ return $this->supportsFlatten;
+ }
+
+ /**
* If the report is enabled the report metadata for this report will be built and added to the list of available
* reports. Overwrite this method and leave it empty in case you do not want your report to be added to the report
* metadata. In this case your report won't be visible for instance in the mobile app and scheduled reports
diff --git a/core/ViewDataTable/Config.php b/core/ViewDataTable/Config.php
index 2ccd975c7b..0eb99aa9f5 100644
--- a/core/ViewDataTable/Config.php
+++ b/core/ViewDataTable/Config.php
@@ -502,6 +502,7 @@ class Config
$this->loadDocumentation();
$this->setShouldShowPivotBySubtable();
+ $this->setShouldShowFlattener();
}
/** Load documentation from the API */
@@ -755,6 +756,15 @@ class Config
}
}
+ private function setShouldShowFlattener()
+ {
+ $report = ReportsProvider::factory($this->controllerName, $this->controllerAction);
+
+ if ($report && !$report->supportsFlatten()) {
+ $this->show_flatten_table = false;
+ }
+ }
+
public function disablePivotBySubtableIfTableHasNoSubtables(DataTable $table)
{
foreach ($table->getRows() as $row) {
diff --git a/plugins/Referrers/Reports/GetReferrerType.php b/plugins/Referrers/Reports/GetReferrerType.php
index 16a11d295b..dea44ccb5a 100644
--- a/plugins/Referrers/Reports/GetReferrerType.php
+++ b/plugins/Referrers/Reports/GetReferrerType.php
@@ -37,6 +37,7 @@ class GetReferrerType extends Base
$this->hasGoalMetrics = true;
$this->order = 1;
$this->subcategoryId = 'Referrers_WidgetGetAll';
+ $this->supportsFlatten = false;
}
public function getDefaultTypeViewDataTable()
diff --git a/plugins/UserId/Reports/GetUsers.php b/plugins/UserId/Reports/GetUsers.php
index 776c29e02f..7fba70f472 100644
--- a/plugins/UserId/Reports/GetUsers.php
+++ b/plugins/UserId/Reports/GetUsers.php
@@ -25,11 +25,12 @@ class GetUsers extends Base
{
parent::init();
- $this->name = Piwik::translate('UserId_UserReportTitle');
- $this->subcategoryId = 'UserId_UserReportTitle';
- $this->documentation = '';
- $this->dimension = new UserId();
- $this->metrics = array('label', 'nb_visits', 'nb_actions', 'nb_visits_converted');
+ $this->name = Piwik::translate('UserId_UserReportTitle');
+ $this->subcategoryId = 'UserId_UserReportTitle';
+ $this->documentation = '';
+ $this->dimension = new UserId();
+ $this->metrics = array('label', 'nb_visits', 'nb_actions', 'nb_visits_converted');
+ $this->supportsFlatten = false;
// This defines in which order your report appears in the mobile app, in the menu and in the list of widgets
$this->order = 9;
@@ -60,7 +61,6 @@ class GetUsers extends Base
$view->config->show_related_reports = false;
$view->config->show_insights = false;
$view->config->show_pivot_by_subtable = false;
- $view->config->show_flatten_table = false;
if ($view->isViewDataTableId(HtmlTable::ID)) {
$view->config->disable_row_evolution = false;
diff --git a/tests/PHPUnit/System/expected/test_reportLimiting_flattened__Referrers.getReferrerType_day.xml b/tests/PHPUnit/System/expected/test_reportLimiting_flattened__Referrers.getReferrerType_day.xml
index 2f781c0adb..e8636937d0 100644
--- a/tests/PHPUnit/System/expected/test_reportLimiting_flattened__Referrers.getReferrerType_day.xml
+++ b/tests/PHPUnit/System/expected/test_reportLimiting_flattened__Referrers.getReferrerType_day.xml
@@ -14,68 +14,26 @@
</row>
<row>
<label>Search Engines</label>
- <nb_uniq_visitors>7</nb_uniq_visitors>
- <nb_visits>7</nb_visits>
- <nb_actions>7</nb_actions>
- <nb_users>0</nb_users>
- <max_actions>1</max_actions>
- <sum_visit_length>0</sum_visit_length>
- <bounce_count>7</bounce_count>
- <nb_visits_converted>0</nb_visits_converted>
- </row>
- <row>
- <label>Websites</label>
- <nb_uniq_visitors>3</nb_uniq_visitors>
- <nb_visits>4</nb_visits>
- <nb_actions>4</nb_actions>
- <nb_users>0</nb_users>
- <max_actions>1</max_actions>
- <sum_visit_length>0</sum_visit_length>
- <bounce_count>4</bounce_count>
- <nb_visits_converted>0</nb_visits_converted>
- </row>
- <row>
- <label>Search Engines</label>
- <nb_uniq_visitors>3</nb_uniq_visitors>
- <nb_visits>3</nb_visits>
- <nb_actions>3</nb_actions>
+ <nb_uniq_visitors>12</nb_uniq_visitors>
+ <nb_visits>12</nb_visits>
+ <nb_actions>12</nb_actions>
<nb_users>0</nb_users>
<max_actions>1</max_actions>
<sum_visit_length>0</sum_visit_length>
- <bounce_count>3</bounce_count>
- <nb_visits_converted>0</nb_visits_converted>
- </row>
- <row>
- <label>Search Engines</label>
- <nb_uniq_visitors>2</nb_uniq_visitors>
- <nb_visits>2</nb_visits>
- <nb_actions>2</nb_actions>
- <nb_users>0</nb_users>
- <max_actions>1</max_actions>
- <sum_visit_length>0</sum_visit_length>
- <bounce_count>2</bounce_count>
+ <bounce_count>12</bounce_count>
<nb_visits_converted>0</nb_visits_converted>
+ <segment>referrerType==search</segment>
</row>
<row>
<label>Websites</label>
- <nb_uniq_visitors>2</nb_uniq_visitors>
- <nb_visits>2</nb_visits>
- <nb_actions>2</nb_actions>
- <nb_users>0</nb_users>
- <max_actions>1</max_actions>
- <sum_visit_length>0</sum_visit_length>
- <bounce_count>2</bounce_count>
- <nb_visits_converted>0</nb_visits_converted>
- </row>
- <row>
- <label>Websites</label>
- <nb_uniq_visitors>2</nb_uniq_visitors>
- <nb_visits>2</nb_visits>
- <nb_actions>2</nb_actions>
+ <nb_uniq_visitors>7</nb_uniq_visitors>
+ <nb_visits>8</nb_visits>
+ <nb_actions>8</nb_actions>
<nb_users>0</nb_users>
<max_actions>1</max_actions>
<sum_visit_length>0</sum_visit_length>
- <bounce_count>2</bounce_count>
+ <bounce_count>8</bounce_count>
<nb_visits_converted>0</nb_visits_converted>
+ <segment>referrerType==website</segment>
</row>
</result> \ No newline at end of file
diff --git a/tests/UI/expected-screenshots/UIIntegrationTest_metric_tooltip.png b/tests/UI/expected-screenshots/UIIntegrationTest_metric_tooltip.png
index ace02fe4d0..0bf02f7209 100644
--- a/tests/UI/expected-screenshots/UIIntegrationTest_metric_tooltip.png
+++ b/tests/UI/expected-screenshots/UIIntegrationTest_metric_tooltip.png
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:c133c0a47fe8139277d12e0fd82a5145d84a22d6bfeeff18b4cde7a0e8316b04
-size 168821
+oid sha256:d8ff715f995e7e109653c1c2a774d1ffd0219c5db50c8ac797fac07383c756d6
+size 168384