You are here

public function EntityFieldQuery::addCondition in RESTful 7.2

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.

string $sql_field: The name of the field.

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

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

Overrides EntityFieldQuery::addCondition

2 calls to EntityFieldQuery::addCondition()
EntityFieldQuery::fieldStorageQuery in src/Util/EntityFieldQuery.php
Copies field_sql_storage_field_storage_query() using left joins some times.
EntityFieldQuery::prePropertyQuery in src/Util/EntityFieldQuery.php
Copy of propertyQuery() without the finishQuery execution.
1 method overrides EntityFieldQuery::addCondition()
EntityFieldQuery::addCondition in src/Util/EntityFieldQuery.php
Adds a condition to an already built SelectQuery (internal function).

File

src/Util/EntityFieldQuery.php, line 452
Contains \Drupal\restful\Util\EntityFieldQuery.

Class

EntityFieldQuery

Namespace

Drupal\restful\Util

Code

public function addCondition(SelectQuery $select_query, $sql_field, $condition, $having = FALSE) {
  $needs_or = !empty($condition['or']) || in_array($condition['operator'], static::$leftJoinOperators);
  if (in_array($condition['operator'], array(
    'CONTAINS',
    'STARTS_WITH',
  )) || !$needs_or) {
    parent::addCondition($select_query, $sql_field, $condition, $having);
    return;
  }
  $method = $having ? 'havingCondition' : 'condition';
  $db_or = db_or()
    ->condition($sql_field, $condition['value'], $condition['operator']);
  if (strtoupper($condition['operator']) != 'IS NULL' && strtoupper($condition['operator']) != 'IS NOT NULL') {
    $db_or
      ->condition($sql_field, NULL, 'IS NULL');
  }
  $select_query
    ->{$method}($db_or);
}