You are here

function _revisioning_extract_order_clause_from_URI in Revisioning 7

Same name and namespace in other branches
  1. 8 revisioning_api.inc \_revisioning_extract_order_clause_from_URI()

Extract order clause.

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.

Return value

string db table field name and sort direction as a string

1 call to _revisioning_extract_order_clause_from_URI()
revisioning_get_revisions in ./revisioning_api.inc
Get list of revisions accessible to the logged-in user via the operation.

File

./revisioning_api.inc, line 931
API functions of Revisioning module

Code

function _revisioning_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 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;

    // List 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}";
}