diff options
4 files changed, 126 insertions, 1 deletions
diff --git a/core/DataTable/Filter/PivotByDimension.php b/core/DataTable/Filter/PivotByDimension.php index bc5c6cca46..ce3ac98ec5 100644 --- a/core/DataTable/Filter/PivotByDimension.php +++ b/core/DataTable/Filter/PivotByDimension.php @@ -17,9 +17,11 @@ use Piwik\DataTable\BaseFilter; use Piwik\DataTable\Row; use Piwik\Log; use Piwik\Metrics; +use Piwik\Period; use Piwik\Piwik; use Piwik\Plugin\Report; use Piwik\Plugin\Segment; +use Piwik\Site; /** * DataTable filter that creates a pivot table from a report. @@ -421,15 +423,22 @@ class PivotByDimension extends BaseFilter 'hideColumns' => '' ); + /** @var Site $site */ $site = $table->getMetadata('site'); if (!empty($site)) { $params['idSite'] = $site->getId(); } + /** @var Period $period */ $period = $table->getMetadata('period'); if (!empty($period)) { - $params['date'] = $period->getDateStart()->toString(); $params['period'] = $period->getLabel(); + + if ($params['period'] == 'range') { + $params['date'] = $period->getRangeString(); + } else { + $params['date'] = $period->getDateStart()->toString(); + } } return $params; diff --git a/tests/PHPUnit/System/PivotByQueryParamTest.php b/tests/PHPUnit/System/PivotByQueryParamTest.php index f46813e879..e07ab83280 100644 --- a/tests/PHPUnit/System/PivotByQueryParamTest.php +++ b/tests/PHPUnit/System/PivotByQueryParamTest.php @@ -56,6 +56,16 @@ class PivotByQueryParamTest extends SystemTestCase )); } + public function test_PivotBySubtableDimension_CreatesCorrectPivotTable_WhenPeriodIsDateRange() + { + $this->assertApiResponseEqualsExpected("Referrers.getKeywords", array( + 'idSite' => self::$fixture->idSite, + 'date' => '2009-12-29,2010-01-10', + 'period' => 'range', + 'pivotBy' => 'Referrers.SearchEngine' + )); + } + public function test_PivotBySegment_CreatesCorrectPivotTable() { $this->assertApiResponseEqualsExpected("Referrers.getKeywords", array( @@ -81,6 +91,16 @@ class PivotByQueryParamTest extends SystemTestCase )); } + public function test_PivotBySegment_CreatesCorrectPivotTable_WhenPeriodIsRange() + { + $this->assertApiResponseEqualsExpected("Referrers.getKeywords", array( + 'idSite' => self::$fixture->idSite, + 'date' => '2009-12-29,2010-01-10', + 'period' => 'range', + 'pivotBy' => 'UserCountry.City' + )); + } + public function test_PivotByParam_PlaysNiceWithOtherQueryParams() { $this->assertApiResponseEqualsExpected("Referrers.getKeywords", array( diff --git a/tests/PHPUnit/System/expected/test_PivotByQueryParamTest_test_PivotBySegment_CreatesCorrectPivotTable_WhenPeriodIsRange__Referrers.getKeywords_range.xml b/tests/PHPUnit/System/expected/test_PivotByQueryParamTest_test_PivotBySegment_CreatesCorrectPivotTable_WhenPeriodIsRange__Referrers.getKeywords_range.xml new file mode 100644 index 0000000000..8112e991f5 --- /dev/null +++ b/tests/PHPUnit/System/expected/test_PivotByQueryParamTest_test_PivotBySegment_CreatesCorrectPivotTable_WhenPeriodIsRange__Referrers.getKeywords_range.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <col name="label">this search term</col> + <col name="1. Toronto, Ontario, Canada">0</col> + <col name="2. Yokohama, Kanagawa, Japan">1</col> + <col name="3. Melbourne, Victoria, Australia">2</col> + </row> + <row> + <col name="label">search term 2</col> + <col name="1. Toronto, Ontario, Canada">0</col> + <col name="2. Yokohama, Kanagawa, Japan">2</col> + <col name="3. Melbourne, Victoria, Australia">0</col> + </row> + <row> + <col name="label">search term 3</col> + <col name="1. Toronto, Ontario, Canada">2</col> + <col name="2. Yokohama, Kanagawa, Japan">0</col> + <col name="3. Melbourne, Victoria, Australia">0</col> + </row> + <row> + <col name="label">search term 4</col> + <col name="1. Toronto, Ontario, Canada">2</col> + <col name="2. Yokohama, Kanagawa, Japan">0</col> + <col name="3. Melbourne, Victoria, Australia">0</col> + </row> + <row> + <col name="label">that search term</col> + <col name="1. Toronto, Ontario, Canada">0</col> + <col name="2. Yokohama, Kanagawa, Japan">0</col> + <col name="3. Melbourne, Victoria, Australia">2</col> + </row> + <row> + <col name="label">search term 1</col> + <col name="1. Toronto, Ontario, Canada">0</col> + <col name="2. Yokohama, Kanagawa, Japan">1</col> + <col name="3. Melbourne, Victoria, Australia">0</col> + </row> +</result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_PivotByQueryParamTest_test_PivotBySubtableDimension_CreatesCorrectPivotTable_WhenPeriodIsDateRange__Referrers.getKeywords_range.xml b/tests/PHPUnit/System/expected/test_PivotByQueryParamTest_test_PivotBySubtableDimension_CreatesCorrectPivotTable_WhenPeriodIsDateRange__Referrers.getKeywords_range.xml new file mode 100644 index 0000000000..6ab5630422 --- /dev/null +++ b/tests/PHPUnit/System/expected/test_PivotByQueryParamTest_test_PivotBySubtableDimension_CreatesCorrectPivotTable_WhenPeriodIsDateRange__Referrers.getKeywords_range.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <col name="label">this search term</col> + <col name="1. Google">1</col> + <col name="2. Yahoo!">1</col> + <col name="3. Ask">1</col> + <col name="4. Bing">0</col> + <col name="5. Alexa">0</col> + <col name="6. Babylon">0</col> + </row> + <row> + <col name="label">search term 2</col> + <col name="1. Google">0</col> + <col name="2. Yahoo!">0</col> + <col name="3. Ask">0</col> + <col name="4. Bing">0</col> + <col name="5. Alexa">1</col> + <col name="6. Babylon">1</col> + </row> + <row> + <col name="label">search term 3</col> + <col name="1. Google">1</col> + <col name="2. Yahoo!">0</col> + <col name="3. Ask">1</col> + <col name="4. Bing">0</col> + <col name="5. Alexa">0</col> + <col name="6. Babylon">0</col> + </row> + <row> + <col name="label">search term 4</col> + <col name="1. Google">0</col> + <col name="2. Yahoo!">1</col> + <col name="3. Ask">0</col> + <col name="4. Bing">1</col> + <col name="5. Alexa">0</col> + <col name="6. Babylon">0</col> + </row> + <row> + <col name="label">that search term</col> + <col name="1. Google">1</col> + <col name="2. Yahoo!">1</col> + <col name="3. Ask">0</col> + <col name="4. Bing">0</col> + <col name="5. Alexa">0</col> + <col name="6. Babylon">0</col> + </row> + <row> + <col name="label">search term 1</col> + <col name="1. Google">0</col> + <col name="2. Yahoo!">0</col> + <col name="3. Ask">0</col> + <col name="4. Bing">1</col> + <col name="5. Alexa">0</col> + <col name="6. Babylon">0</col> + </row> +</result>
\ No newline at end of file |