1 date_views_filter_handler_simple.inc date_views_filter_handler_simple::op_between($field)

Overrides views_handler_filter_date::op_between

File

core/modules/date/views/date_views_filter_handler_simple.inc, line 144
A standard Views filter for a single date field, using Date API form selectors and sql handling.

Class

date_views_filter_handler_simple
@file A standard Views filter for a single date field, using Date API form selectors and sql handling.

Code

function op_between($field) {

  // Add the delta field to the view so we can later find the value that matched our query.
  list($table_name, $field_name) = explode('.', $field);
  if (!empty($this->options['add_delta']) && (substr($field_name, -6) == '_value' || substr($field_name, -7) == '_value2')) {
    $this->query->add_field($table_name, 'delta');
    $real_field_name = str_replace(array('_value', '_value2'), '', $this->real_field);
    $this->query->add_field($table_name, 'entity_id', 'date_id_' . $real_field_name);
    $this->query->add_field($table_name, 'delta', 'date_delta_' . $real_field_name);
  }

  $min_value = $this->get_filter_value('min', $this->value['min']);
  $min_comp_date = new BackdropDateTime($min_value, date_default_timezone(), $this->format);
  $max_value = $this->get_filter_value('max', $this->value['max']);
  $max_comp_date = new BackdropDateTime($max_value, date_default_timezone(), $this->format);
  $field_min = $this->date_handler->sql_field($field, NULL, $min_comp_date);
  $field_min = $this->date_handler->sql_format($this->format, $field_min);
  $field_max = $this->date_handler->sql_field($field, NULL, $max_comp_date);
  $field_max = $this->date_handler->sql_format($this->format, $field_max);
  $placeholder_min = $this->placeholder();
  $placeholder_max = $this->placeholder();
  $group = !empty($this->options['date_group']) ? $this->options['date_group'] : $this->options['group'];
  if ($this->operator == 'between') {
    $this->query->add_where_expression($group, "$field_min >= $placeholder_min AND $field_max <= $placeholder_max", array($placeholder_min => $min_value, $placeholder_max => $max_value));
  }
  else {
    $this->query->add_where_expression($group, "$field_min < $placeholder_min OR $field_max > $placeholder_max", array($placeholder_min => $min_value, $placeholder_max => $max_value));
  }
}