Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new PivotByDimension DataTable filter that can pivot a report by (almost) any dimension. #6243

Merged
merged 30 commits into from
Sep 21, 2014
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
41fabcb
Adding new PivotByDimension DataTable filter that can pivot a report …
Sep 18, 2014
bda5356
Fixing build.
Sep 19, 2014
5076ef5
Fixing build.
Sep 19, 2014
eebd6dc
Fix XML rendering regression.
Sep 19, 2014
1ad956d
Add public Report::isSubtableReport() method so it can be used in clo…
Sep 19, 2014
71dfe38
Make sure PivotByDimension respects original segment query parameter …
Sep 19, 2014
1eefab5
Fix another closure access error in PHP 5.3 for tests.
Sep 19, 2014
3d90430
Cleaning up PivotByDimensionTest a bit.
Sep 19, 2014
a318e24
Refs #6078, allow default column limit to be specified through INI co…
Sep 19, 2014
eab8210
Refs #6078, add report metadata for Event subtable reports and make s…
Sep 19, 2014
b5196b8
Refs #6078, remove pivotBy param when switching between related reports.
Sep 19, 2014
cc74e8e
Refs #6078, allow plugins to set what metric gets displayed in pivot …
Sep 19, 2014
88e6f0b
call clearQueuedFilters()
Sep 20, 2014
a173c6d
Refs #6078, fix bug where reloading report does not persist pivot and…
Sep 20, 2014
07fce41
Refs #6078, #5355 only display expand/contract tooltip if row has sub…
Sep 20, 2014
7524b71
Refs #6078, make sure cog icon is highlighted when table is pivotted.
Sep 20, 2014
74dad07
Refs #6078, make pivot option use the pivot by dimension's name.
Sep 20, 2014
fbb3303
Refs #6078, do not pivot table when getting siteSummary data.
Sep 20, 2014
b196894
Refs #6078, change default maximum column limit to 10.
Sep 20, 2014
8d0205e
Refs #6078, order pivot table columns by sum, descending and aggregat…
Sep 20, 2014
56b798c
Refs #6078, make sure visualizations default sort to first non-label …
Sep 20, 2014
33cc6c7
Refs #6078, make sure sorting doesn't break if column has special cha…
Sep 20, 2014
9689506
Refs #6078, prepend numeral index to each column in pivotted datatable.
Sep 20, 2014
3101516
Refs #6078,set pivotByColumnLimit explicitly in export link so user c…
Sep 20, 2014
89ce428
Refs #6078, remove dead code & refactor dimension equality checks in …
Sep 20, 2014
fcbb47d
Refs #6078, make sure pivot option does not display if table is not p…
Sep 20, 2014
3dfe724
Refs #6078, rename test methods.
Sep 20, 2014
72272d7
Refs #6078, make sure $this->dataTable is instance of DataTable befor…
Sep 21, 2014
fbbf12a
Refs #6078, fix sorting on pivot table columns when columns use &nbsp…
Sep 21, 2014
3d04d15
Refs #6078, fix regression in last commit and only send one request t…
Sep 21, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config/global.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,17 @@
; If set to 0 it also disables the "sent plugin update emails" feature in general and the related setting in the UI.
enable_update_communication = 1

; This controls whether the pivotBy query parameter can be used with any dimension or just subtable
; dimensions. If set to 1, it will fetch a report with a segment for each row of the table being pivoted.
; At present, this is very inefficient, so it is disabled by default.
pivot_by_filter_enable_fetch_by_segment = 0

; This controls the default maximum number of columns to display in a pivot table. Since a pivot table displays
; a table's rows as columns, the number of columns can become very large, which will affect webpage layouts.
; Set to -1 to specify no limit. Note: The pivotByColumnLimit query parameter can be used to override this default
; on a per-request basis;
pivot_by_filter_default_column_limit = 7

[Tracker]
; Piwik uses first party cookies by default. If set to 1,
; the visit ID cookie will be set on the Piwik server domain as well
Expand Down
3 changes: 3 additions & 0 deletions core/API/DocumentationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ public function getExampleUrl($class, $methodName, $parametersToSet = array())
$aParameters['hideColumns'] = false;
$aParameters['showColumns'] = false;
$aParameters['filter_pattern_recursive'] = false;
$aParameters['pivotBy'] = false;
$aParameters['pivotByColumn'] = false;
$aParameters['pivotByColumnLimit'] = false;

$moduleName = Proxy::getInstance()->getModuleNameFromClassName($class);
$aParameters = array_merge(array('module' => 'API', 'method' => $moduleName . '.' . $methodName), $aParameters);
Expand Down
14 changes: 13 additions & 1 deletion core/API/ResponseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Piwik\API\DataTableManipulator\ReportTotalsCalculator;
use Piwik\Common;
use Piwik\DataTable;
use Piwik\DataTable\Filter\PivotByDimension;
use Piwik\DataTable\Renderer;
use Piwik\DataTable\DataTableInterface;
use Piwik\DataTable\Filter\ColumnDelete;
Expand Down Expand Up @@ -157,10 +158,21 @@ private function formatExceptionMessage(Exception $exception)
return Renderer::formatValueXml($message);
}

protected function handleDataTable($datatable)
protected function handleDataTable(DataTableInterface $datatable)
{
$label = $this->getLabelFromRequest($this->request);

// handle pivot by dimension filter
$pivotBy = Common::getRequestVar('pivotBy', false, 'string', $this->request);
if (!empty($pivotBy)) {
$reportId = $this->apiModule . '.' . $this->apiMethod;
$pivotByColumn = Common::getRequestVar('pivotByColumn', false, 'string', $this->request);
$pivotByColumnLimit = Common::getRequestVar('pivotByColumnLimit', false, 'int', $this->request);

$datatable->filter('PivotByDimension', array($reportId, $pivotBy, $pivotByColumn, $pivotByColumnLimit,
PivotByDimension::isSegmentFetchingEnabledInConfig()));
}

// if requested, flatten nested tables
if (Common::getRequestVar('flat', '0', 'string', $this->request) == '1') {
$flattener = new Flattener($this->apiModule, $this->apiMethod, $this->request);
Expand Down
21 changes: 20 additions & 1 deletion core/Columns/Dimension.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,29 @@ public static function getAllDimensions()
* @return Dimension|null The created instance or null if there is no Dimension for
* $dimensionId or if the plugin that contains the Dimension is
* not loaded.
* @api
*/
public static function factory($dimensionId)
{
list($module, $dimension) = explode('.', $dimensionId);
return ComponentFactory::factory($module, $dimension, __CLASS__);
}
}

/**
* Returns the name of the plugin that contains this Dimension.
*
* @return string
* @throws Exception if the Dimension is not located within a Plugin module.
* @api
*/
public function getModule()
{
$id = $this->getId();
if (empty($id)) {
throw new Exception("Invalid dimension ID: '$id'.");
}

$parts = explode('.', $id);
return reset($parts);
}
}
8 changes: 8 additions & 0 deletions core/DataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,14 @@ protected function aggregateRowFromSimpleTable($row)
$thisRow->sumRow($row, $copyMeta = true, $this->getMetadata(self::COLUMN_AGGREGATION_OPS_METADATA_NAME));
}

/**
* Unsets all queued filters.
*/
public function clearQueuedFilters()
{
$this->queuedFilters = array();
}

/**
* @return \ArrayIterator|Row[]
*/
Expand Down
Loading