mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX: Make TableListField sort checking use SQLQuery::canSortBy() to let SSReprot_FakeQuery work.
ENHANCEMENT: Allow sort descending as well as ascending. (from r96054) (from r98132) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102604 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
0a7cca3c56
commit
d743cdef78
@ -324,10 +324,13 @@ JS
|
|||||||
if($this->form) {
|
if($this->form) {
|
||||||
$sortLink = $this->Link();
|
$sortLink = $this->Link();
|
||||||
$sortLink = HTTP::setGetVar("ctf[{$this->Name()}][sort]", $fieldName, $sortLink);
|
$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;
|
// Apply sort direction
|
||||||
$sortLink = HTTP::setGetVar("ctf[{$this->Name()}][dir]", $XML_sort, $sortLink);
|
$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'])) {
|
if(isset($_REQUEST['ctf'][$this->Name()]['search']) && is_array($_REQUEST['ctf'][$this->Name()]['search'])) {
|
||||||
foreach($_REQUEST['ctf'][$this->Name()]['search'] as $parameter => $value) {
|
foreach($_REQUEST['ctf'][$this->Name()]['search'] as $parameter => $value) {
|
||||||
$XML_search = Convert::raw2xml($value);
|
$XML_search = Convert::raw2xml($value);
|
||||||
@ -484,13 +487,13 @@ JS
|
|||||||
$query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter(), $this->sourceSort, null, $this->sourceJoin);
|
$query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter(), $this->sourceSort, null, $this->sourceJoin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($_REQUEST['ctf'][$this->Name()]['sort'])) {
|
if(!empty($_REQUEST['ctf'][$this->Name()]['sort'])) {
|
||||||
$SQL_sort = Convert::raw2sql($_REQUEST['ctf'][$this->Name()]['sort']);
|
$sort = $_REQUEST['ctf'][$this->Name()]['sort'];
|
||||||
$sql = $query->sql();
|
if(!empty($_REQUEST['ctf'][$this->Name()]['dir'])) {
|
||||||
// see {isFieldSortable}
|
$dir = $_REQUEST['ctf'][$this->Name()]['dir'];
|
||||||
if(in_array($SQL_sort,$query->select) || stripos($sql,"AS {$SQL_sort}")) {
|
if(strtoupper(trim($dir)) == 'DESC') $sort .= ' DESC';
|
||||||
$query->orderby = $SQL_sort;
|
|
||||||
}
|
}
|
||||||
|
if($query->canSortBy($sort)) $query->orderby = $sort;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user