BUGFIX: Make TableListField sort checking use SQLQuery::canSortBy() to let SSReprot_FakeQuery work.

ENHANCEMENT: Allow sort descending as well as ascending. (from r96054)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@98132 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-02-04 03:44:12 +00:00
parent 1434fae6cf
commit 55423c1547

View File

@ -319,10 +319,13 @@ JS
if($this->form) {
$sortLink = $this->Link();
$sortLink = HTTP::setGetVar("ctf[{$this->Name()}][sort]", $fieldName, $sortLink);
if(isset($_REQUEST['ctf'][$this->Name()]['dir'])) {
$XML_sort = (isset($_REQUEST['ctf'][$this->Name()]['dir'])) ? Convert::raw2xml($_REQUEST['ctf'][$this->Name()]['dir']) : null;
$sortLink = HTTP::setGetVar("ctf[{$this->Name()}][dir]", $XML_sort, $sortLink);
}
// Apply sort direction
$dir = isset($_REQUEST['ctf'][$this->Name()]['dir']) ? $_REQUEST['ctf'][$this->Name()]['dir'] : null;
$dir = trim(strtolower($dir));
$newDir = ($dir == 'desc') ? null : 'desc';
$sortLink = HTTP::setGetVar("ctf[{$this->Name()}][dir]", Convert::raw2xml($newDir), $sortLink);
if(isset($_REQUEST['ctf'][$this->Name()]['search']) && is_array($_REQUEST['ctf'][$this->Name()]['search'])) {
foreach($_REQUEST['ctf'][$this->Name()]['search'] as $parameter => $value) {
$XML_search = Convert::raw2xml($value);
@ -480,13 +483,13 @@ JS
$query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter(), $this->sourceSort, null, $this->sourceJoin);
}
if(isset($_REQUEST['ctf'][$this->Name()]['sort'])) {
$SQL_sort = Convert::raw2sql($_REQUEST['ctf'][$this->Name()]['sort']);
$sql = $query->sql();
// see {isFieldSortable}
if(in_array($SQL_sort,$query->select) || stripos($sql,"AS {$SQL_sort}")) {
$query->orderby = $SQL_sort;
if(!empty($_REQUEST['ctf'][$this->Name()]['sort'])) {
$sort = $_REQUEST['ctf'][$this->Name()]['sort'];
if(!empty($_REQUEST['ctf'][$this->Name()]['dir'])) {
$dir = $_REQUEST['ctf'][$this->Name()]['dir'];
if(strtoupper(trim($dir)) == 'DESC') $sort .= ' DESC';
}
if($query->canSortBy($sort)) $query->orderby = $sort;
}
return $query;