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
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@gmail.com>2015-03-16 06:17:17 +0300
committerThomas Steur <thomas.steur@gmail.com>2015-03-16 06:17:17 +0300
commit78d546f15ec66319dafbc547aabaa813c5b67a65 (patch)
tree230c47a3ccb977425cd764013cd0ac91c5ccf5bf /core/DataTable/Filter/Sort.php
parent54ac2bf9d949d45eb756768003a0d4e0008e0a61 (diff)
fixed a couple of bugs in DataTable\Sort.
* make sure to select correct column (the column value might be false which is valid, meaning column actually exists whereas we assumed before it does not exist) * use correct sort algorithm (if value of first column was false we picked under circumstances a string comparison instead of number) * If we sort by label, use always a string or natural comparison even if the label is numeric
Diffstat (limited to 'core/DataTable/Filter/Sort.php')
-rw-r--r--core/DataTable/Filter/Sort.php27
1 files changed, 19 insertions, 8 deletions
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.
*