1 date_views_filter_handler.inc protected date_views_filter_handler::date_combine_conditions($function)

Combines multiple date WHERE expressions into a single WHERE expression.

Parameters

string $function: The function name to use to add individual conditions. Either 'op_simple' or 'op_between'.

File

core/modules/date/views/date_views_filter_handler.inc, line 40
A flexible, configurable date filter. This filter combines multiple date filters into a single filter where all fields are controlled by the same date and can be combined with either AND or OR.

Class

date_views_filter_handler
@file A flexible, configurable date filter. This filter combines multiple date filters into a single filter where all fields are controlled by the same date and can be combined with either AND or OR.

Code

protected function date_combine_conditions($function) {
  $this->get_query_fields();
  if (empty($this->query_fields)) {
    return;
  }

  // Create a custom filter group for the conditions.
  $this->query->set_where_group($this->options['date_method'], $this->options['date_group']);
  // Add each condition to the custom filter group.
  foreach ((array) $this->query_fields as $query_field) {
    $field = $query_field['field'];
    $this->date_handler = $query_field['date_handler'];

    // Respect relationships when determining the table alias.
    if ($field['table_name'] != $this->table || !empty($this->relationship)) {
      $related_table_alias = $this->query->ensure_table($field['table_name'], $this->relationship);
    }
    else {
      $related_table_alias = NULL;
    }
    $table_alias = !empty($related_table_alias) ? $related_table_alias : $field['table_name'];
    $field_name = $table_alias . '.' . $field['field_name'];

    // Call the appropriate function, either 'op_between' or 'op_simple'.
    parent::$function($field_name);
  }

  // Gather all of the condition strings and their placeholders.
  $conditions = array();
  $placeholders = array();
  foreach ($this->query->where[$this->options['date_group']]['conditions'] as $condition) {
    $conditions[] = $condition['field'];
    $placeholders += $condition['value'];
  }

  // Remove the conditions from the custom filter group.
  unset($this->query->where[$this->options['date_group']]);

  // Combine all of the conditions into one string.
  $conditions = implode(' ' . $this->options['date_method'] . ' ', $conditions);

  // Add it to the filter group chosen in the Views UI.
  $this->query->add_where_expression($this->options['group'], $conditions, $placeholders);
}