PHP Class Piwik\DataTable\Filter\PivotByDimension
A pivot table is a table that displays one metric value for two dimensions. The rows of
the table represent one dimension and the columns another.
This filter can pivot any report by any dimension as long as either:
- the pivot-by dimension is the dimension of the report's subtable
- or, the pivot-by dimension has an associated report, and the report to pivot has a dimension with
a segment
Reports are pivoted by iterating over the rows of the report, fetching the pivot-by report
for the current row, and setting the columns of row to the rows of the pivot-by report. For example:
to pivot Referrers.getKeywords by UserCountry.City, we first loop through the Referrers.getKeywords
report's rows. For each row, we take the label (which is the referrer keyword), and get the
UserCountry.getCity report using the referrerKeyword=... segment. If the row's label were 'abcdefg',
we would use the 'referrerKeyword==abcdefg' segment.
The UserCountry.getCity report we find is the report on visits by country, but only for the visits
for the specific row. We take this report's row labels and add them as columns for the Referrers.getKeywords
table.
Implementation details:
Fetching intersected table can be done by segment or subtable. If the requested pivot by
dimension is the report's subtable dimension, then the subtable is used regardless, since it
is much faster than fetching by segment.
Also, by default, fetching by segment is disabled in the config (see the
'[General] pivot_by_filter_enable_fetch_by_segment' option).
Mostrar archivo
Open project: piwik/piwik
Class Usage Examples
Public Methods
Method |
Description |
|
__construct ( DataTable $table, string $report, string $pivotByDimension, string | false $pivotColumn, false | integer $pivotByColumnLimit = false, boolean $isFetchingBySegmentEnabled = true ) |
Constructor. |
|
filter ( DataTable $table ) |
Pivots to table. |
|
getDefaultColumnLimit ( ) : integer |
Returns the default maximum number of columns to allow in a pivot table from the INI config. |
|
isPivotingReportBySubtableSupported ( Report $report ) : boolean |
Returns true if pivoting by subtable is supported for a report. Will return true if the report
has a subtable dimension and if the subtable dimension is different than the report's dimension. |
|
isSegmentFetchingEnabledInConfig ( ) : boolean |
Returns true if fetching intersected tables by segment is enabled in the INI config, false if otherwise. |
|
Private Methods
Method Details
__construct()
public method
public __construct ( DataTable $table, string $report, string $pivotByDimension, string | false $pivotColumn, false | integer $pivotByColumnLimit = false, boolean $isFetchingBySegmentEnabled = true ) |
$table |
Piwik\DataTable |
The table to pivot. |
$report |
string |
The ID of the report being pivoted, eg, `'Referrers.getKeywords'`. |
$pivotByDimension |
string |
The ID of the dimension to pivot by, eg, `'Referrers.Keyword'`. |
$pivotColumn |
string | false |
The metric that should be displayed in the pivot table, eg, `'nb_visits'`.
If `false`, the first non-label column is used. |
$pivotByColumnLimit |
false | integer |
The number of columns to limit the pivot table to. |
$isFetchingBySegmentEnabled |
boolean |
Whether to allow fetching by segment. |
public filter ( DataTable $table ) |
$table |
Piwik\DataTable |
The table to manipulate. |
getDefaultColumnLimit()
public static method
Uses the **pivot_by_filter_default_column_limit** INI config option.
isPivotingReportBySubtableSupported()
public static method
Returns true if pivoting by subtable is supported for a report. Will return true if the report
has a subtable dimension and if the subtable dimension is different than the report's dimension.
isSegmentFetchingEnabledInConfig()
public static method
Returns true if fetching intersected tables by segment is enabled in the INI config, false if otherwise.