public function EntityFieldQuery::fieldOrderBy

public EntityFieldQuery::fieldOrderBy($field, $column, $direction = 'ASC')

Orders the result set by a given field column.

If called multiple times, the query will order by each specified column in the order this method is called. Note that entities with empty field values will be excluded from the EntityFieldQuery results when using this method.

Parameters

$field: Either a field name or a field array.

$column: A column defined in the hook_field_schema() of this field. entity_id and bundle can also be used.

$direction: The direction to sort. Legal values are "ASC" and "DESC".

Return value

EntityFieldQuery The called object.

File

includes/entity.inc, line 950

Class

EntityFieldQuery
Retrieves entities matching a given set of conditions.

Code

public function fieldOrderBy($field, $column, $direction = 'ASC') {
  if (is_scalar($field)) {
    $field_definition = field_info_field($field);
    if (empty($field_definition)) {
      throw new EntityFieldQueryException(t('Unknown field: @field_name', array('@field_name' => $field)));
    }
    $field = $field_definition;
  }
  // Save the index used for the new field, for later use in field storage.
  $index = count($this->fields);
  $this->fields[$index] = $field;
  $this->order[] = array(
    'type' => 'field',
    'specifier' => array(
      'field' => $field,
      'index' => $index,
      'column' => $column,
    ),
    'direction' => $direction,
  );
  return $this;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!entity.inc/function/EntityFieldQuery::fieldOrderBy/7.x