You are here

protected function date_views_filter_handler::date_combine_conditions in Date 8

Same name and namespace in other branches
  1. 7.3 date_views/includes/date_views_filter_handler.inc \date_views_filter_handler::date_combine_conditions()
  2. 7.2 date_views/includes/date_views_filter_handler.inc \date_views_filter_handler::date_combine_conditions()

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'.

2 calls to date_views_filter_handler::date_combine_conditions()
date_views_filter_handler::op_between in date_views/includes/date_views_filter_handler.inc
date_views_filter_handler::op_simple in date_views/includes/date_views_filter_handler.inc

File

date_views/includes/date_views_filter_handler.inc, line 46
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)) {
      $this->related_table_alias = $this->query
        ->ensure_table($field['table_name'], $this->relationship);
    }
    $table_alias = !empty($this->related_table_alias) ? $this->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);
}