diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-03-16 08:03:39 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2015-03-18 03:15:08 +0300 |
commit | 0bbbdc851366a1b5cd7179a7de313caa655a6fda (patch) | |
tree | 1fd3d8c8a8369f25f4b45ff7b7b06b731c9f225a /core/DataTable/Filter/Sort.php | |
parent | f1894a1aee763f840a6d541aec6db9ca2c05337e (diff) |
Various performance improvements and bugfixes.
Imporves performance for Archiving and Range dates. Makes all kind of
reports faster as well. Fixed bugs in labelFilter, reports total calculation
and more.
Diffstat (limited to 'core/DataTable/Filter/Sort.php')
-rw-r--r-- | core/DataTable/Filter/Sort.php | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/core/DataTable/Filter/Sort.php b/core/DataTable/Filter/Sort.php index 7e91bb338d..3b11ec370c 100644 --- a/core/DataTable/Filter/Sort.php +++ b/core/DataTable/Filter/Sort.php @@ -21,11 +21,14 @@ use Piwik\Metrics; * * @api */ -class -Sort extends BaseFilter +class Sort extends BaseFilter { protected $columnToSort; protected $order; + protected $sign; + + const ORDER_DESC = 'desc'; + const ORDER_ASC = 'asc'; /** * Constructor. @@ -36,7 +39,7 @@ Sort extends BaseFilter * @param bool $naturalSort Whether to use a natural sort or not (see {@link http://php.net/natsort}). * @param bool $recursiveSort Whether to sort all subtables or not. */ - public function __construct($table, $columnToSort, $order = 'desc', $naturalSort = true, $recursiveSort = false) + public function __construct($table, $columnToSort, $order = 'desc', $naturalSort = true, $recursiveSort = true) { parent::__construct($table); @@ -68,8 +71,8 @@ Sort extends BaseFilter /** * Sorting method used for sorting numbers * - * @param Row $a - * @param Row $b + * @param array $rowA array[0 => value of column to sort, 1 => label] + * @param array $rowB array[0 => value of column to sort, 1 => label] * @return int */ public function numberSort($rowA, $rowB) @@ -80,20 +83,20 @@ Sort extends BaseFilter } else { return -1 * $this->sign * strnatcasecmp($rowA[1], $rowB[1]); } - } elseif (!isset($rowB[0])) { - return -1; + } elseif (!isset($rowB[0]) && !isset($rowA[0])) { + return -1 * $this->sign * strnatcasecmp($rowA[1], $rowB[1]); } elseif (!isset($rowA[0])) { return 1; } - return 0; + return -1; } /** * Sorting method used for sorting values natural * - * @param mixed $a - * @param mixed $b + * @param array $rowA array[0 => value of column to sort, 1 => label] + * @param array $rowB array[0 => value of column to sort, 1 => label] * @return int */ function naturalSort($rowA, $rowB) @@ -119,8 +122,8 @@ Sort extends BaseFilter /** * Sorting method used for sorting values * - * @param mixed $a - * @param mixed $b + * @param array $rowA array[0 => value of column to sort, 1 => label] + * @param array $rowB array[0 => value of column to sort, 1 => label] * @return int */ function sortString($rowA, $rowB) @@ -208,12 +211,11 @@ Sort extends BaseFilter return; } - $rows = $table->getRows(); - if (count($rows) == 0) { + if (!$table->getRowsCount()) { return; } - $row = current($rows); + $row = $table->getFirstRow(); if ($row === false) { return; } @@ -268,10 +270,10 @@ Sort extends BaseFilter $sortedRows = array(); foreach ($values as $key => $value) { - $sortedRows[$key] = $rows[$key]; + $sortedRows[] = $rows[$key]; } - $table->setRows(array_values($sortedRows)); + $table->setRows($sortedRows); unset($rows); unset($sortedRows); |