public function date_views_filter_handler_simple::op_between in Date 7.2
Same name and namespace in other branches
- 8 date_views/includes/date_views_filter_handler_simple.inc \date_views_filter_handler_simple::op_between()
- 7.3 date_views/includes/date_views_filter_handler_simple.inc \date_views_filter_handler_simple::op_between()
@todo Document this.
Overrides views_handler_filter_date::op_between
1 method overrides date_views_filter_handler_simple::op_between()
- date_views_filter_handler::op_between in date_views/
includes/ date_views_filter_handler.inc - @todo Document this.
File
- date_views/
includes/ date_views_filter_handler_simple.inc, line 163 - A standard Views filter for a single date field.
Class
- date_views_filter_handler_simple
- A standard Views filter for a single date field.
Code
public 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 DateObject($min_value, date_default_timezone(), $this->format);
$max_value = $this
->get_filter_value('max', $this->value['max']);
$max_comp_date = new DateObject($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,
));
}
}