public function tripal_views_query::add_where

3.x tripal_views_query.inc public tripal_views_query::add_where($group, $field_name, $value = NULL, $operator = NULL)

Add a simple WHERE clause to the query.

Parameters

$group: The WHERE group to add these to; groups are used to create AND/OR sections. Groups cannot be nested. Use 0 as the default group. If the group does not yet exist it will be created as an AND group.

$field: The name of the field to check.

$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 the $operator.

$operator: The comparison operator, such as =, <, or >=. It also accepts more complex options such as IN, LIKE, or BETWEEN. Defaults to IN if $value is an array = otherwise. If $field is a string you have to use 'formula' here.

File

tripal/tripal_views_query.inc, line 89

Class

tripal_views_query

Code

public function add_where($group, $field_name, $value = NULL, $operator = NULL) {

  if ($value) {

    $this->filters[] = array(
      'group' => $group,
      'field_name' => $field_name,
      'value' => $value,
      'op' => $operator
    );

    // Handle the bundle properties separate from real fields.
    if ($field_name == 'entity_id' or $field_name == 'status') {
      $this->query->propertyCondition($field_name, $value, $operator);
      $this->cquery->propertyCondition($field_name, $value, $operator);
      return;
    }

    // For Tripal create fields the name of the field is an encoded
    // string that contains the bundle term, field name and any
    // sub elements. We need to extract them.
    $elements = explode('.', $field_name);
    $bundle_term = array_shift($elements);
    $field_name = array_shift($elements);
    $element_name = implode(',', $elements);

    // Get the field and instance.
    $field = field_info_field($field_name);
    $instance = field_info_instance('TripalEntity', $field_name, $this->query->entityConditions['bundle']['value']);

    // Construct the field term.
    $field_term = $instance['settings']['term_vocabulary'] . ':' . $instance['settings']['term_accession'];

    // Let's add add on the $field_term to the element_name and add the
    // query condition.
    if ($element_name) {
      $element_name = $field_term . ',' . $element_name;
    }
    else {
      $element_name = $field_term;
    }

    $this->query->fieldCondition($field_name, $element_name, $value, $operator);
    $this->cquery->fieldCondition($field_name, $element_name, $value, $operator);
  }
}