Skip to content
Extraits de code Groupes Projets
Valider 3d8f3ce8 rédigé par mattab's avatar mattab
Parcourir les fichiers

Fixes #6562

parent 7ab9fddb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -73,16 +73,8 @@ class Sort extends BaseFilter
*/
public function numberSort($a, $b)
{
$valA = $a->getColumn($this->columnToSort);
$valB = $b->getColumn($this->columnToSort);
if ($valA === false) {
$valA = null;
}
if ($valB === false) {
$valB = null;
}
$valA = $this->getColumnValue($a);
$valB = $this->getColumnValue($b);
return !isset($valA)
&& !isset($valB)
......@@ -118,16 +110,8 @@ class Sort extends BaseFilter
*/
function naturalSort($a, $b)
{
$valA = $a->getColumn($this->columnToSort);
$valB = $b->getColumn($this->columnToSort);
if ($valA === false) {
$valA = null;
}
if ($valB === false) {
$valB = null;
}
$valA = $this->getColumnValue($a);
$valB = $this->getColumnValue($b);
return !isset($valA)
&& !isset($valB)
......@@ -153,16 +137,8 @@ class Sort extends BaseFilter
*/
function sortString($a, $b)
{
$valA = $a->getColumn($this->columnToSort);
$valB = $b->getColumn($this->columnToSort);
if ($valA === false) {
$valA = null;
}
if ($valB === false) {
$valB = null;
}
$valA = $this->getColumnValue($a);
$valB = $this->getColumnValue($b);
return !isset($valA)
&& !isset($valB)
......@@ -179,6 +155,18 @@ class Sort extends BaseFilter
);
}
protected function getColumnValue(Row $table )
{
$value = $table->getColumn($this->columnToSort);
if ($value === false
|| is_array($value)
) {
return null;
}
return $value;
}
/**
* Sets the column to be used for sorting
*
......
......@@ -12,6 +12,9 @@ use Piwik\DataTable\Filter\Sort;
use Piwik\DataTable;
use Piwik\DataTable\Row;
/**
* @group SortTest
*/
class DataTable_Filter_SortTest extends \PHPUnit_Framework_TestCase
{
/**
......@@ -169,4 +172,20 @@ class DataTable_Filter_SortTest extends \PHPUnit_Framework_TestCase
$filter->filter($table);
$this->assertTrue(DataTable::isEqual($table, $expectedtableReverse));
}
public function test_sortingArrayValues_doesNotError()
{
$table = new DataTable();
$table->addRowsFromArray(array(
array(Row::COLUMNS => array('label' => 'ask', 'count_array' => array(100, 1, 2) )),
array(Row::COLUMNS => array('label' => 'nintendo', 'count_array' => array(0, 'hello'))),
array(Row::COLUMNS => array('label' => 'yahoo', 'count_array' => array(10, 'test'))
)));
$tableOriginal = clone $table;
$filter = new Sort($table, 'count_array', 'desc');
$filter->filter($table);
$this->assertTrue(DataTable::isEqual($tableOriginal, $table));
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter