1 entity.query.inc | public EntityFieldQuery::addCondition(SelectQuery $select_query, $sql_field, $condition, $having = FALSE) |
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.
File
- core/
modules/ entity/ entity.query.inc, line 977 - Entity query API.
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']);
}
}