You are here

public function PartyQuery::fieldCondition in Party 8.2

Same name and namespace in other branches
  1. 7 includes/party.extender.inc \PartyQuery::fieldCondition()

Set a simple property condition on an attached entity.

This doesn't handle more complicated condition sets. If you need that functionality, use PartyQuery::joinAttachedEntity() and set your conditions using the normal SelectQuery methods.

Parameters

$data_set: Either a data set name or a data set array.

$field string|array: Either a field name or a field info array.

$column: A column defined in the hook_field_schema() of this field. If this is omitted then the query will find only entities that have data in this field, using the entity and property conditions if there are any.

$value: The value to test the field against. In most cases, this is a scalar. For more complex options, it is an array. The meaning of each element in the array is dependent on $operator.

$operator: Possible values:

  • '=', '<>', '>', '>=', '<', '<=', 'STARTS_WITH', 'CONTAINS': These operators expect $value to be a literal of the same type as the column.
  • 'IN', 'NOT IN': These operators expect $value to be an array of literals of the same type as the column.
  • 'BETWEEN': This operator expects $value to be an array of two literals of the same type as the column.

The operator can be omitted, and will default to 'IN' if the value is an array, or to '=' otherwise.

$field_delta: Optionally specify an field delta you want to query against.

$data_set_delta: Optionally specify an attached entity delta you want to query against.

$type string: The type of join. Typically one of INNER, LEFT OUTER and RIGHT OUTER. Defaults to INNER.

Return value

PartyQuery The build PartyQuery.

See also

PartyQuery::joinAttachedEntity().

File

includes/party.extender.inc, line 347
Class to aid querying parties and attached entities.

Class

PartyQuery
Query extender for party attached entities.

Code

public function fieldCondition($data_set, $field, $column, $value, $operator = NULL, $field_delta = NULL, $data_set_delta = NULL, $type = 'INNER') {

  // Get hold of the field information.
  if (is_scalar($field)) {
    $field_definition = field_info_field($field);
    if (empty($field_definition)) {
      throw new Exception(t('Unknown field: @field_name', array(
        '@field_name' => $field,
      )));
    }
    $field = $field_definition;
  }

  // Get our entity table alias.
  $field_alias = $this
    ->joinField($data_set, $field, NULL, $field_delta, $data_set_delta, $type);

  // Set our condition.
  $this
    ->condition("{$field_alias}.{$field['field_name']}_{$column}", $value, $operator);
  return $this;
}