update Piwik to version 2.16 (fixes #91)

This commit is contained in:
oliver 2016-04-10 18:55:57 +02:00
commit d885a4baa9
5833 changed files with 418860 additions and 226988 deletions

View file

@ -1,6 +1,6 @@
<?php
/**
* Piwik - Open source web analytics
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
@ -8,52 +8,57 @@
*/
namespace Piwik\ViewDataTable;
use Piwik\API\Request as ApiRequest;
use Piwik\Common;
use Piwik\DataTable;
use Piwik\DataTable\Filter\PivotByDimension;
use Piwik\Metrics;
use Piwik\Plugin\Report;
use Piwik\Plugins\API\API;
/**
* Contains base display properties for {@link Piwik\Plugin\ViewDataTable}s. Manipulating these
* properties in a ViewDataTable instance will change how its report will be displayed.
*
*
* <a name="client-side-properties-desc"></a>
* **Client Side Properties**
*
*
* Client side properties are properties that should be passed on to the browser so
* client side JavaScript can use them. Only affects ViewDataTables that output HTML.
*
* <a name="overridable-properties-desc"></a>
* **Overridable Properties**
*
*
* Overridable properties are properties that can be set via the query string.
* If a request has a query parameter that matches an overridable property, the property
* will be set to the query parameter value.
*
*
* **Reusing base properties**
*
*
* Many of the properties in this class only have meaning for the {@link Piwik\Plugin\Visualization}
* class, but can be set for other visualizations that extend {@link Piwik\Plugin\ViewDataTable}
* class, but can be set for other visualizations that extend {@link Piwik\Plugin\ViewDataTable}
* directly.
*
*
* Visualizations that extend {@link Piwik\Plugin\ViewDataTable} directly and want to re-use these
* properties must make sure the properties are used in the exact same way they are used in
* {@link Piwik\Plugin\Visualization}.
*
*
* **Defining new display properties**
*
*
* If you are creating your own visualization and want to add new display properties for
* it, extend this class and add your properties as fields.
*
*
* Properties are marked as client side properties by calling the
* {@link addPropertiesThatShouldBeAvailableClientSide()} method.
*
*
* Properties are marked as overridable by calling the
* {@link addPropertiesThatCanBeOverwrittenByQueryParams()} method.
*
*
* ### Example
*
*
* **Defining new display properties**
*
*
* class MyCustomVizConfig extends Config
* {
* /**
@ -65,11 +70,11 @@ use Piwik\Plugins\API\API;
* * Another custom property. It is available client side.
* *\/
* public $another_custom_property = true;
*
*
* public function __construct()
* {
* parent::__construct();
*
*
* $this->addPropertiesThatShouldBeAvailableClientSide(array('another_custom_property'));
* $this->addPropertiesThatCanBeOverwrittenByQueryParams(array('my_custom_property'));
* }
@ -83,7 +88,10 @@ class Config
* The list of ViewDataTable properties that are 'Client Side Properties'.
*/
public $clientSideProperties = array(
'show_limit_control'
'show_limit_control',
'pivot_by_dimension',
'pivot_by_column',
'pivot_dimension_name'
);
/**
@ -93,6 +101,7 @@ class Config
'show_goals',
'show_exclude_low_population',
'show_flatten_table',
'show_pivot_by_subtable',
'show_table',
'show_table_all_columns',
'show_footer',
@ -113,7 +122,8 @@ class Config
'show_pagination_control',
'show_offset_information',
'hide_annotations_view',
'export_limit'
'export_limit',
'columns_to_display'
);
/**
@ -159,6 +169,11 @@ class Config
*/
public $show_goals = false;
/**
* Controls whether the 'insights' footer icon is shown.
*/
public $show_insights = true;
/**
* Array property mapping DataTable column names with their internationalized names.
*
@ -179,6 +194,28 @@ class Config
*/
public $show_flatten_table = true;
/**
* Whether to show the 'Pivot by subtable' option (visible in the popup that displays after clicking
* the 'cog' icon).
*/
public $show_pivot_by_subtable;
/**
* The ID of the dimension to pivot by when the 'pivot by subtable' option is clicked. Defaults
* to the subtable dimension of the report being displayed.
*/
public $pivot_by_dimension;
/**
* The column to display in pivot tables. Defaults to the first non-label column if not specified.
*/
public $pivot_by_column = '';
/**
* The human readable name of the pivot dimension.
*/
public $pivot_dimension_name = false;
/**
* Controls whether the footer icon that allows users to switch to the 'normal' DataTable view
* is shown.
@ -442,6 +479,7 @@ class Config
$this->report_id = $controllerName . '.' . $controllerAction;
$this->loadDocumentation();
$this->setShouldShowPivotBySubtable();
}
/** Load documentation from the API */
@ -449,7 +487,28 @@ class Config
{
$this->metrics_documentation = array();
$report = API::getInstance()->getMetadata(0, $this->controllerName, $this->controllerAction);
$idSite = Common::getRequestVar('idSite', 0, 'int');
if ($idSite < 1) {
return;
}
$apiParameters = array();
$idDimension = Common::getRequestVar('idDimension', 0, 'int');
$idGoal = Common::getRequestVar('idGoal', 0, 'int');
if ($idDimension > 0) {
$apiParameters['idDimension'] = $idDimension;
}
if ($idGoal > 0) {
$apiParameters['idGoal'] = $idGoal;
}
$report = API::getInstance()->getMetadata($idSite, $this->controllerName, $this->controllerAction, $apiParameters);
if (empty($report)) {
return;
}
$report = $report[0];
if (isset($report['metricsDocumentation'])) {
@ -464,7 +523,7 @@ class Config
/**
* Marks display properties as client side properties. [Read this](#client-side-properties-desc)
* to learn more.
*
*
* @param array $propertyNames List of property names, eg, `array('show_limit_control', 'show_goals')`.
*/
public function addPropertiesThatShouldBeAvailableClientSide(array $propertyNames)
@ -477,7 +536,7 @@ class Config
/**
* Marks display properties as overridable. [Read this](#overridable-properties-desc) to
* learn more.
*
*
* @param array $propertyNames List of property names, eg, `array('show_limit_control', 'show_goals')`.
*/
public function addPropertiesThatCanBeOverwrittenByQueryParams(array $propertyNames)
@ -490,7 +549,7 @@ class Config
/**
* Returns array of all property values in this config object. Property values are mapped
* by name.
*
*
* @return array eg, `array('show_limit_control' => 0, 'show_goals' => 1, ...)`
*/
public function getProperties()
@ -519,10 +578,21 @@ class Config
$this->columns_to_display = array_filter($columnsToDisplay);
}
public function removeColumnToDisplay($columnToRemove)
{
if (!empty($this->columns_to_display)) {
$key = array_search($columnToRemove, $this->columns_to_display);
if (false !== $key) {
unset($this->columns_to_display[$key]);
}
}
}
/**
* @ignore
*/
public function getFiltersToRun()
private function getFiltersToRun()
{
$priorityFilters = array();
$presentationFilters = array();
@ -546,12 +616,26 @@ class Config
return array($priorityFilters, $presentationFilters);
}
public function getPriorityFilters()
{
$filters = $this->getFiltersToRun();
return $filters[0];
}
public function getPresentationFilters()
{
$filters = $this->getFiltersToRun();
return $filters[1];
}
/**
* Adds a related report to the {@link $related_reports} property. If the report
* references the one that is currently being displayed, it will not be added to the related
* report list.
*
* @param string $relatedReport The plugin and method of the report, eg, `'UserSettings.getBrowser'`.
*
* @param string $relatedReport The plugin and method of the report, eg, `'DevicesDetection.getBrowsers'`.
* @param string $title The report's display name, eg, `'Browsers'`.
* @param array $queryParams Any extra query parameters to set in releated report's URL, eg,
* `array('idGoal' => 'ecommerceOrder')`.
@ -563,7 +647,7 @@ class Config
// don't add the related report if it references this report
if ($this->controllerName == $module
&& $this->controllerAction == $action) {
if(empty($queryParams)) {
if (empty($queryParams)) {
return;
}
}
@ -577,16 +661,16 @@ class Config
* Adds several related reports to the {@link $related_reports} property. If
* any of the reports references the report that is currently being displayed, it will not
* be added to the list. All other reports will still be added though.
*
*
* If you need to make sure the related report URL has some extra query parameters,
* use {@link addRelatedReport()}.
*
*
* @param array $relatedReports Array mapping report IDs with their internationalized display
* titles, eg,
* ```
* array(
* 'UserSettings.getBrowser' => 'Browsers',
* 'UserSettings.getConfiguration' => 'Configurations'
* 'DevicesDetection.getBrowsers' => 'Browsers',
* 'Resolution.getConfiguration' => 'Configurations'
* )
* ```
*/
@ -599,9 +683,9 @@ class Config
/**
* Associates internationalized text with a metric. Overwrites existing mappings.
*
*
* See {@link $translations}.
*
*
* @param string $columnName The name of a column in the report data, eg, `'nb_visits'` or
* `'goal_1_nb_conversions'`.
* @param string $translation The internationalized text, eg, `'Visits'` or `"Conversions for 'My Goal'"`.
@ -613,9 +697,9 @@ class Config
/**
* Associates multiple translations with metrics.
*
*
* See {@link $translations} and {@link addTranslation()}.
*
*
* @param array $translations An array of column name => text mappings, eg,
* ```
* array(
@ -630,4 +714,33 @@ class Config
$this->addTranslation($key, $translation);
}
}
private function setShouldShowPivotBySubtable()
{
$report = Report::factory($this->controllerName, $this->controllerAction);
if (empty($report)) {
$this->show_pivot_by_subtable = false;
$this->pivot_by_dimension = false;
} else {
$this->show_pivot_by_subtable = PivotByDimension::isPivotingReportBySubtableSupported($report);
$subtableDimension = $report->getSubtableDimension();
if (!empty($subtableDimension)) {
$this->pivot_by_dimension = $subtableDimension->getId();
$this->pivot_dimension_name = $subtableDimension->getName();
}
}
}
public function disablePivotBySubtableIfTableHasNoSubtables(DataTable $table)
{
foreach ($table->getRows() as $row) {
if ($row->getIdSubDataTable() !== null) {
return;
}
}
$this->show_pivot_by_subtable = false;
}
}