Order the query based on a header array.
array $header: Table header array.
SelectQueryInterface The called object.
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;
}