public function EntityFieldQuery::tableSort in Drupal 7
Enables sortable tables for this query.
Parameters
$headers: An EFQ Header array based on which the order clause is added to the query.
Return value
EntityFieldQuery The called object.
File
- includes/
entity.inc, line 1069
Class
- EntityFieldQuery
- Retrieves entities matching a given set of conditions.
Code
public function tableSort(&$headers) {
// If 'field' is not initialized, the header columns aren't clickable
foreach ($headers as $key => $header) {
if (is_array($header) && isset($header['specifier'])) {
$headers[$key]['field'] = '';
}
}
$order = tablesort_get_order($headers);
$direction = tablesort_get_sort($headers);
foreach ($headers as $header) {
if (is_array($header) && $header['data'] == $order['name']) {
if ($header['type'] == 'field') {
$this
->fieldOrderBy($header['specifier']['field'], $header['specifier']['column'], $direction);
}
else {
$header['direction'] = $direction;
$this->order[] = $header;
}
}
}
return $this;
}