function _node_tools_extract_order_clause_from_URI in Module Grants 6.4
Same name and namespace in other branches
- 6.3 node_tools/node_tools.module \_node_tools_extract_order_clause_from_URI()
Extract from the incoming URI (as in the table column header href) the sort field and order for use in an SQL 'ORDER BY' clause.
Parameters
none:
Return value
db table field name and sort direction as a string
1 call to _node_tools_extract_order_clause_from_URI()
- node_tools_get_nodes in node_tools/
node_tools.module - Retrieve a list of nodes or revisions accessible to the logged-in user via the supplied operation.
File
- node_tools/
node_tools.module, line 197 - Generic reusable functions involving node objects.
Code
function _node_tools_extract_order_clause_from_URI() {
// We shouldn't have to do this, as tablesort.inc/tablesort_header(), called
// from theme_table() is meant to look after it, but it's got a bug [#480382].
// Note: this function is secure, as we're only allowing recognised values,
// all unknown values, result in the a descending sort by 'timestamp'.
switch ($order_by = drupal_strtolower($_REQUEST['order'])) {
case 'creator':
$order_by = 'n.uid';
break;
case 'by':
$order_by = 'r.uid';
break;
case 'published?':
$order_by = 'status';
break;
case 'workflow state':
$order_by = 'state';
break;
// Listing names that are fine the way they are here:
case 'title':
case 'type':
case 'term':
break;
default:
$order_by = 'timestamp';
break;
}
$direction = drupal_strtolower($_REQUEST['sort']) == 'asc' ? 'ASC' : 'DESC';
return "{$order_by} {$direction}";
}