diff options
-rw-r--r-- | core/Plugin/Report.php | 20 | ||||
-rw-r--r-- | core/ViewDataTable/Factory.php | 9 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/ReportTest.php | 11 |
3 files changed, 38 insertions, 2 deletions
diff --git a/core/Plugin/Report.php b/core/Plugin/Report.php index df28f450c9..24887fb4c0 100644 --- a/core/Plugin/Report.php +++ b/core/Plugin/Report.php @@ -318,6 +318,26 @@ class Report } /** + * + * Processing a uniqueId for each report, can be used by UIs as a key to match a given report + * @return string + */ + public function getId() + { + $params = $this->getParameters(); + + $paramsKey = $this->getModule() . '.' . $this->getAction(); + + if (!empty($params)) { + foreach ($params as $key => $value) { + $paramsKey .= '_' . $key . '--' . $value; + } + } + + return $paramsKey; + } + + /** * lets you add any amount of widgets for this report. If a report defines a {@link $categoryId} and a * {@link $subcategoryId} a widget will be generated automatically. * diff --git a/core/ViewDataTable/Factory.php b/core/ViewDataTable/Factory.php index 90a44281e4..b9b166b963 100644 --- a/core/ViewDataTable/Factory.php +++ b/core/ViewDataTable/Factory.php @@ -106,12 +106,17 @@ class Factory $params = array(); - if(is_null($loadViewDataTableParametersForUser)) { + if (!isset($loadViewDataTableParametersForUser)) { $loadViewDataTableParametersForUser = ('0' == Common::getRequestVar('widget', '0', 'string')); } + if ($loadViewDataTableParametersForUser) { $login = Piwik::getCurrentUserLogin(); - $params = Manager::getViewDataTableParameters($login, $controllerAction); + $paramsKey = $controllerAction; + if (!empty($report) && $controllerAction === $apiAction) { + $paramsKey = $report->getId(); + } + $params = Manager::getViewDataTableParameters($login, $paramsKey); } if (!self::isDefaultViewTypeForReportFixed($report)) { diff --git a/tests/PHPUnit/Integration/ReportTest.php b/tests/PHPUnit/Integration/ReportTest.php index 2aed43693b..adfd973c73 100644 --- a/tests/PHPUnit/Integration/ReportTest.php +++ b/tests/PHPUnit/Integration/ReportTest.php @@ -329,6 +329,17 @@ class ReportTest extends IntegrationTestCase $this->assertEquals($action, $report->getAction()); } + public function test_getId_ShouldReturnOnlyReturnModuleAndActionWhenNoParametersSet() + { + $report = new GetExampleReport(); + $this->assertEquals('ExampleReport.getExampleReport', $report->getId()); + } + + public function test_getId_ShouldReturnIncludeParamsIfSet() + { + $this->assertEquals('TestPlugin.getAdvancedReport_idGoal--1', $this->advancedReport->getId()); + } + public function test_getSubtableDimension_ShouldReturnNullIfNoSubtableActionExists() { $report = new GetExampleReport(); |