Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorMatthieu Aubry <matt@piwik.org>2015-03-17 06:26:20 +0300
committerMatthieu Aubry <matt@piwik.org>2015-03-17 06:26:20 +0300
commitf1894a1aee763f840a6d541aec6db9ca2c05337e (patch)
tree22247e12b1413df298f6b804311abe9678d41daa /core
parentf3d61fc73967d06ac0bfb9d4aa998c89db2a8191 (diff)
parentb7f3f7bd6d6d12a505b50d2740c47007d2d82985 (diff)
Merge pull request #7452 from piwik/7388
Fix Sort filters are sometimes applied multiple times
Diffstat (limited to 'core')
-rw-r--r--core/API/DataTableGenericFilter.php31
-rw-r--r--core/API/DataTablePostProcessor.php2
-rw-r--r--core/DataTable/Filter/Sort.php27
-rw-r--r--core/Plugin/Report.php15
4 files changed, 63 insertions, 12 deletions
diff --git a/core/API/DataTableGenericFilter.php b/core/API/DataTableGenericFilter.php
index 46274b0c31..ff49491642 100644
--- a/core/API/DataTableGenericFilter.php
+++ b/core/API/DataTableGenericFilter.php
@@ -10,7 +10,6 @@ namespace Piwik\API;
use Exception;
use Piwik\Common;
-use Piwik\DataTable\Filter\AddColumnsProcessedMetricsGoal;
use Piwik\DataTable;
use Piwik\Plugin\ProcessedMetric;
use Piwik\Plugin\Report;
@@ -25,13 +24,24 @@ class DataTableGenericFilter
private $disabledFilters = array();
/**
+ * @var Report
+ */
+ private $report;
+
+ /**
+ * @var array
+ */
+ private $request;
+
+ /**
* Constructor
*
* @param $request
*/
- function __construct($request)
+ function __construct($request, $report)
{
$this->request = $request;
+ $this->report = $report;
}
/**
@@ -102,6 +112,21 @@ class DataTableGenericFilter
);
}
+ private function getGenericFiltersHavingDefaultValues()
+ {
+ $filters = self::getGenericFiltersInformation();
+
+ if ($this->report && $this->report->getDefaultSortColumn()) {
+ foreach ($filters as $index => $filter) {
+ if ($filter[0] === 'Sort') {
+ $filters[$index][1]['filter_sort_column'] = array('string', $this->report->getDefaultSortColumn());
+ }
+ }
+ }
+
+ return $filters;
+ }
+
/**
* Apply generic filters to the DataTable object resulting from the API Call.
* Disable this feature by setting the parameter disable_generic_filters to 1 in the API call request.
@@ -119,7 +144,7 @@ class DataTableGenericFilter
return;
}
- $genericFilters = self::getGenericFiltersInformation();
+ $genericFilters = $this->getGenericFiltersHavingDefaultValues();
$filterApplied = false;
foreach ($genericFilters as $filterMeta) {
diff --git a/core/API/DataTablePostProcessor.php b/core/API/DataTablePostProcessor.php
index dfa0434da6..8d936e6779 100644
--- a/core/API/DataTablePostProcessor.php
+++ b/core/API/DataTablePostProcessor.php
@@ -207,7 +207,7 @@ class DataTablePostProcessor
if (0 == Common::getRequestVar('disable_generic_filters', '0', 'string', $this->request)) {
$this->applyProcessedMetricsGenericFilters($dataTable);
- $genericFilter = new DataTableGenericFilter($this->request);
+ $genericFilter = new DataTableGenericFilter($this->request, $this->report);
$self = $this;
$report = $this->report;
diff --git a/core/DataTable/Filter/Sort.php b/core/DataTable/Filter/Sort.php
index 3da11b4119..7e91bb338d 100644
--- a/core/DataTable/Filter/Sort.php
+++ b/core/DataTable/Filter/Sort.php
@@ -163,8 +163,8 @@ Sort extends BaseFilter
*/
protected function selectColumnToSort($row)
{
- $value = $row->getColumn($this->columnToSort);
- if ($value !== false) {
+ $value = $row->hasColumn($this->columnToSort);
+ if ($value) {
return $this->columnToSort;
}
@@ -172,9 +172,9 @@ Sort extends BaseFilter
// sorting by "nb_visits" but the index is Metrics::INDEX_NB_VISITS in the table
if (isset($columnIdToName[$this->columnToSort])) {
$column = $columnIdToName[$this->columnToSort];
- $value = $row->getColumn($column);
+ $value = $row->hasColumn($column);
- if ($value !== false) {
+ if ($value) {
return $column;
}
}
@@ -182,8 +182,8 @@ Sort extends BaseFilter
// eg. was previously sorted by revenue_per_visit, but this table
// doesn't have this column; defaults with nb_visits
$column = Metrics::INDEX_NB_VISITS;
- $value = $row->getColumn($column);
- if ($value !== false) {
+ $value = $row->hasColumn($column);
+ if ($value) {
return $column;
}
@@ -220,8 +220,9 @@ Sort extends BaseFilter
$this->columnToSort = $this->selectColumnToSort($row);
- $value = $row->getColumn($this->columnToSort);
- if (is_numeric($value)) {
+ $value = $this->getFirstValueFromDataTable($table);
+
+ if (is_numeric($value) && $this->columnToSort !== 'label') {
$methodToUse = "numberSort";
} else {
if ($this->naturalSort) {
@@ -234,6 +235,16 @@ Sort extends BaseFilter
$this->sort($table, $methodToUse);
}
+ private function getFirstValueFromDataTable($table)
+ {
+ foreach ($table->getRows() as $row) {
+ $value = $this->getColumnValue($row);
+ if (!is_null($value)) {
+ return $value;
+ }
+ }
+ }
+
/**
* Sorts the DataTable rows using the supplied callback function.
*
diff --git a/core/Plugin/Report.php b/core/Plugin/Report.php
index b9c407e10e..dfbe6e50cf 100644
--- a/core/Plugin/Report.php
+++ b/core/Plugin/Report.php
@@ -189,6 +189,13 @@ class Report
protected $recursiveLabelSeparator = ' - ';
/**
+ * Default sort column. Either a column name or a column id.
+ *
+ * @var string|int
+ */
+ protected $defaultSortColumn = '';
+
+ /**
* @var array
* @ignore
*/
@@ -579,6 +586,14 @@ class Report
}
/**
+ * @ignore
+ */
+ public function getDefaultSortColumn()
+ {
+ return $this->defaultSortColumn;
+ }
+
+ /**
* Get the list of related reports if there are any. They will be displayed for instance below a report as a
* recommended related report.
*