Newer
Older
Benaka Moorthi
a validé
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik
* @package Piwik
*/
namespace Piwik\Plugins\CoreVisualizations\Visualizations;
Benaka Moorthi
a validé
Benaka Moorthi
a validé
use Piwik\DataTable\Row;
use Piwik\DataTable;
use Piwik\Piwik;
Thomas Steur
a validé
use Piwik\Plugin\Visualization;
Benaka Moorthi
a validé
/**
* This is an abstract visualization that should be the base of any 'graph' visualization.
* This class defines certain visualization properties that are specific to all graph types.
* Derived visualizations can decide for themselves whether they should support individual
* properties.
Benaka Moorthi
a validé
*/
Benaka Moorthi
a validé
abstract class Graph extends Visualization
Benaka Moorthi
a validé
{
const ID = 'graph';
Thomas Steur
a validé
public $selectableRows = array();
Benaka Moorthi
a validé
Thomas Steur
a validé
public function getDefaultConfig()
{
return new Graph\Config();
}
Benaka Moorthi
a validé
Thomas Steur
a validé
public function getDefaultRequestConfig()
{
$config = parent::getDefaultRequestConfig();
$config->addPropertiesThatShouldBeAvailableClientSide(array('columns'));
Benaka Moorthi
a validé
Thomas Steur
a validé
return $config;
}
Thomas Steur
a validé
public function configureVisualization()
{
Thomas Steur
a validé
if ($this->config->show_goals) {
$this->config->translations['nb_conversions'] = Piwik::translate('Goals_ColumnConversions');
$this->config->translations['revenue'] = Piwik::translate('General_TotalRevenue');
}
Benaka Moorthi
a validé
}
Thomas Steur
a validé
public function beforeLoadDataTable()
Benaka Moorthi
a validé
{
// TODO: this should not be required here. filter_limit should not be a view property, instead HtmlTable should use 'limit' or something,
// and manually set request_parameters_to_modify['filter_limit'] based on that. (same for filter_offset).
$this->requestConfig->request_parameters_to_modify['filter_limit'] = false;
if ($this->config->max_graph_elements) {
$this->requestConfig->request_parameters_to_modify['filter_truncate'] = $this->config->max_graph_elements - 1;
}
/**
* Determines what rows are selectable and stores them in the selectable_rows property in
* a format the SeriesPicker JavaScript class can use.
*/
public function beforeGenericFiltersAreAppliedToLoadedDataTable()
{
if ($this->config->row_picker_match_rows_by === false) {
Benaka Moorthi
a validé
return;
}
// collect all selectable rows
$self = $this;
Thomas Steur
a validé
$properties = $this->config;
Thomas Steur
a validé
$this->dataTable->filter(function ($dataTable) use ($self, $properties) {
Benaka Moorthi
a validé
foreach ($dataTable->getRows() as $row) {
Benaka Moorthi
a validé
$rowLabel = $row->getColumn('label');
if ($rowLabel === false) {
continue;
}
// determine whether row is visible
$isVisible = true;
if ($properties->row_picker_match_rows_by == 'label') {
$isVisible = in_array($rowLabel, $properties->rows_to_display);
Benaka Moorthi
a validé
}
// build config
if (!isset($self->selectableRows[$rowLabel])) {
$self->selectableRows[$rowLabel] = array(
Benaka Moorthi
a validé
'label' => $rowLabel,
'matcher' => $rowLabel,
'displayed' => $isVisible
);
}
}
});
Benaka Moorthi
a validé
}
Thomas Steur
a validé
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**
* Defaults the selectable_columns property if it has not been set and then transforms
* it into something the SeriesPicker JavaScript class can use.
*/
public function afterAllFilteresAreApplied()
{
$this->config->selectable_rows = array_values($this->selectableRows);
$selectableColumns = $this->config->selectable_columns;
// set default selectable columns, if none specified
if ($selectableColumns === false) {
$selectableColumns = array('nb_visits', 'nb_actions');
if (in_array('nb_uniq_visitors', $this->dataTable->getColumns())) {
$selectableColumns[] = 'nb_uniq_visitors';
}
}
if ($this->config->show_goals) {
$goalMetrics = array('nb_conversions', 'revenue');
$selectableColumns = array_merge($selectableColumns, $goalMetrics);
}
$transformed = array();
foreach ($selectableColumns as $column) {
$transformed[] = array(
'column' => $column,
'translation' => @$this->config->translations[$column],
'displayed' => in_array($column, $this->config->columns_to_display)
);
}
$this->config->selectable_columns = $transformed;
}