| 7 tablesort.inc | public TableSort::orderByHeader(Array $header) |
| 8 tablesort.inc | public TableSort::orderByHeader(Array $header) |
Order the query based on a header array.
Parameters
$header: Table header array.
Return value
SelectQueryInterface The called object.
See also
File
- includes/
tablesort.inc, line 42 - Functions to aid in the creation of sortable tables.
Code
public function orderByHeader(Array $header) {
$this->header = $header;
$ts = $this->init();
if (!empty($ts['sql'])) {
// Based on code from db_escape_table(), but this can also contain a dot.
$field = preg_replace('/[^A-Za-z0-9_.]+/', '', $ts['sql']);
// Sort order can only be ASC or DESC.
$sort = drupal_strtoupper($ts['sort']);
$sort = in_array($sort, array('ASC', 'DESC')) ? $sort : '';
$this->orderBy($field, $sort);
}
return $this;
}
Login or register to post comments
Comments
preg_replace was really necesary here?
By filtering the order by condition, expressions like ORDER BY field_x - field_y DESC won't work even though they are perfectly legal in mysql