1.20.x entity.query.inc public EntityFieldQuery::tableSort(&$headers)

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

modules/entity/entity.query.inc, line 626
Entity query API.

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;
}