Revert "SimpleQuery: Make compare() alias aware"

This reverts commit 6612e4c1ae79c2bc3a5cd08e1594fc152107618e.
This commit is contained in:
Johannes Meyer 2015-05-05 07:30:42 +02:00
parent 271e350faa
commit d71df6a9b8

View File

@ -43,15 +43,6 @@ class SimpleQuery implements QueryInterface
*/ */
protected $columns = array(); protected $columns = array();
/**
* The columns and their aliases flipped in order to handle aliased sort columns
*
* Supposed to be used and populated by $this->compare *only*.
*
* @var array
*/
protected $flippedColumns;
/** /**
* The columns you're using to sort the query result * The columns you're using to sort the query result
* *
@ -228,42 +219,32 @@ class SimpleQuery implements QueryInterface
return $this; return $this;
} }
/** public function compare($a, $b, $col_num = 0)
* Compare $a with $b based on this query's sort rules and column aliases
*
* @param object $a
* @param object $b
* @param int $orderIndex
*
* @return int
*/
public function compare($a, $b, $orderIndex = 0)
{ {
if (! array_key_exists($orderIndex, $this->order)) { // Last column to sort reached, rows are considered being equal
return 0; // Last column to sort reached, rows are considered being equal if (! array_key_exists($col_num, $this->order)) {
return 0;
}
$col = $this->order[$col_num][0];
$dir = $this->order[$col_num][1];
// TODO: throw Exception if column is missing
//$res = strnatcmp(strtolower($a->$col), strtolower($b->$col));
$res = @strcmp(strtolower($a->$col), strtolower($b->$col));
if ($res === 0) {
// return $this->compare($a, $b, $col_num++);
if (array_key_exists(++$col_num, $this->order)) {
return $this->compare($a, $b, $col_num);
} else {
return 0;
}
} }
if ($this->flippedColumns === null) { if ($dir === self::SORT_ASC) {
$this->flippedColumns = array_flip($this->columns); return $res;
}
$column = $this->order[$orderIndex][0];
if (array_key_exists($column, $this->flippedColumns)) {
$column = $this->flippedColumns[$column];
}
// TODO: throw Exception if column is missing
//$res = strnatcmp(strtolower($a->$column), strtolower($b->$column));
$result = @strcmp(strtolower($a->$column), strtolower($b->$column));
if ($result === 0) {
return $this->compare($a, $b, $orderIndex);
}
$direction = $this->order[$orderIndex][1];
if ($direction === self::SORT_ASC) {
return $result;
} else { } else {
return $result * -1; return $res * -1;
} }
} }
@ -445,7 +426,6 @@ class SimpleQuery implements QueryInterface
public function columns(array $columns) public function columns(array $columns)
{ {
$this->columns = $columns; $this->columns = $columns;
$this->flippedColumns = null; // Reset, due to updated columns
return $this; return $this;
} }