diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-07-21 12:01:35 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-07-21 12:01:36 +0400 |
commit | aca8ec33a85e0a70b818b6227145041717d7a69e (patch) | |
tree | 41377e3a9737d63222522ef93ecf8483f3faddfa /core/DataTable/Filter/Sort.php | |
parent | 0a63210e3eae7562af1a3dbee340eb1ee140db3d (diff) |
Refs #4059 Work in progress: Conversion to use Namespaces: Period*, Metrics, Segment, SegmentExpression, PluginsManager.
Removed some deprecated code.
Diffstat (limited to 'core/DataTable/Filter/Sort.php')
-rw-r--r-- | core/DataTable/Filter/Sort.php | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/core/DataTable/Filter/Sort.php b/core/DataTable/Filter/Sort.php index 014362b45d..72bc433bef 100644 --- a/core/DataTable/Filter/Sort.php +++ b/core/DataTable/Filter/Sort.php @@ -8,22 +8,28 @@ * @category Piwik * @package Piwik */ +namespace Piwik\DataTable\Filter; + +use Piwik\DataTable\Filter; +use Piwik\DataTable\Simple; +use Piwik\DataTable\Row; use Piwik\Metrics; +use Piwik\DataTable; /** * Sort the DataTable based on the value of column $columnToSort ordered by $order. * Possible to specify a natural sorting (see php.net/natsort for details) * * @package Piwik - * @subpackage Piwik_DataTable + * @subpackage DataTable */ -class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter +class Sort extends Filter { protected $columnToSort; protected $order; /** - * @param Piwik_DataTable $table + * @param DataTable $table * @param string $columnToSort name of the column to sort by * @param string $order order (asc|desc) * @param bool $naturalSort use natural sort? @@ -65,27 +71,27 @@ class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter */ public function sort($a, $b) { - return !isset($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]) - && !isset($b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]) + return !isset($a->c[Row::COLUMNS][$this->columnToSort]) + && !isset($b->c[Row::COLUMNS][$this->columnToSort]) ? 0 : ( - !isset($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]) + !isset($a->c[Row::COLUMNS][$this->columnToSort]) ? 1 : ( - !isset($b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]) + !isset($b->c[Row::COLUMNS][$this->columnToSort]) ? -1 - : (($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort] != $b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort] - || !isset($a->c[Piwik_DataTable_Row::COLUMNS]['label'])) + : (($a->c[Row::COLUMNS][$this->columnToSort] != $b->c[Row::COLUMNS][$this->columnToSort] + || !isset($a->c[Row::COLUMNS]['label'])) ? ($this->sign * ( - $a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort] - < $b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort] + $a->c[Row::COLUMNS][$this->columnToSort] + < $b->c[Row::COLUMNS][$this->columnToSort] ? -1 : 1) ) : -1 * $this->sign * strnatcasecmp( - $a->c[Piwik_DataTable_Row::COLUMNS]['label'], - $b->c[Piwik_DataTable_Row::COLUMNS]['label']) + $a->c[Row::COLUMNS]['label'], + $b->c[Row::COLUMNS]['label']) ) ) ); @@ -100,16 +106,16 @@ class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter */ function naturalSort($a, $b) { - return !isset($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]) - && !isset($b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]) + return !isset($a->c[Row::COLUMNS][$this->columnToSort]) + && !isset($b->c[Row::COLUMNS][$this->columnToSort]) ? 0 - : (!isset($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]) + : (!isset($a->c[Row::COLUMNS][$this->columnToSort]) ? 1 - : (!isset($b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]) + : (!isset($b->c[Row::COLUMNS][$this->columnToSort]) ? -1 : $this->sign * strnatcasecmp( - $a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort], - $b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort] + $a->c[Row::COLUMNS][$this->columnToSort], + $b->c[Row::COLUMNS][$this->columnToSort] ) ) ); @@ -124,16 +130,16 @@ class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter */ function sortString($a, $b) { - return !isset($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]) - && !isset($b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]) + return !isset($a->c[Row::COLUMNS][$this->columnToSort]) + && !isset($b->c[Row::COLUMNS][$this->columnToSort]) ? 0 - : (!isset($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]) + : (!isset($a->c[Row::COLUMNS][$this->columnToSort]) ? 1 - : (!isset($b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]) + : (!isset($b->c[Row::COLUMNS][$this->columnToSort]) ? -1 : $this->sign * - strcasecmp($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort], - $b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort] + strcasecmp($a->c[Row::COLUMNS][$this->columnToSort], + $b->c[Row::COLUMNS][$this->columnToSort] ) ) ); @@ -142,7 +148,7 @@ class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter /** * Sets the column to be used for sorting * - * @param Piwik_DataTable_Row $row + * @param Row $row * @return int */ protected function selectColumnToSort($row) @@ -179,12 +185,12 @@ class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter /** * Sorts the given data table by defined column and sorting method * - * @param Piwik_DataTable $table + * @param DataTable $table * @return mixed */ public function filter($table) { - if ($table instanceof Piwik_DataTable_Simple) { + if ($table instanceof Simple) { return; } if (empty($this->columnToSort)) { |