You are here

public function EntityFieldQuery::addCondition in Drupal 7

Adds a condition to an already built SelectQuery (internal function).

This is a helper for hook_entity_query() and hook_field_storage_query().

Parameters

SelectQuery $select_query: A SelectQuery object.

$sql_field: The name of the field.

$condition: A condition as described in EntityFieldQuery::fieldCondition() and EntityFieldQuery::entityCondition().

$having: HAVING or WHERE. This is necessary because SQL can't handle WHERE conditions on aliased columns.

1 call to EntityFieldQuery::addCondition()
EntityFieldQuery::propertyQuery in includes/entity.inc
Queries entity tables in SQL for property conditions and sorts.

File

includes/entity.inc, line 1417

Class

EntityFieldQuery
Retrieves entities matching a given set of conditions.

Code

public function addCondition(SelectQuery $select_query, $sql_field, $condition, $having = FALSE) {
  $method = $having ? 'havingCondition' : 'condition';
  $like_prefix = '';
  switch ($condition['operator']) {
    case 'CONTAINS':
      $like_prefix = '%';
    case 'STARTS_WITH':
      $select_query
        ->{$method}($sql_field, $like_prefix . db_like($condition['value']) . '%', 'LIKE');
      break;
    default:
      $select_query
        ->{$method}($sql_field, $condition['value'], $condition['operator']);
  }
}