diff --git a/date_views/includes/date_views_argument_handler_simple.inc b/date_views/includes/date_views_argument_handler_simple.inc index faff05a..d3a8155 100644 --- a/date_views/includes/date_views_argument_handler_simple.inc +++ b/date_views/includes/date_views_argument_handler_simple.inc @@ -88,6 +88,7 @@ class date_views_argument_handler_simple extends views_handler_argument_date { $options['default_argument_type'] = array('default' => 'date'); $options['add_delta'] = array('default' => ''); $options['use_fromto'] = array('default' => ''); + $options['operator'] = array('default' => '='); $options['title_format'] = array('default' => ''); $options['title_format_custom'] = array('default' => ''); return $options; @@ -161,6 +162,26 @@ class date_views_argument_handler_simple extends views_handler_argument_date { '#description' => t("If selected the view will check if any value starting with the 'Start' date and ending with the 'End' date matches the view criteria. Otherwise the view will be limited to the specifically selected fields. Comparing to the whole Start/End range is the recommended setting when using this filter in a Calendar. When using the Start/End option, it is not necessary to add both the Start and End fields to the filter, either one will do."), ); + $form['operator'] = array( + '#type' => 'select', + '#title' => t('Operator'), + '#default_value' => $this->options['operator'], + '#options' => array( + '<' => t('Is less than'), + '<=' => t('Is less than or equal to'), + '>=' => t('Is greater than or equal to'), + '>' => t('Is greater than'), + '=' => t('Is equal to'), + '!=' => t('Is not equal to'), + ), + '#description' => t("Choose operator to compare field to argument. Works only if using 'Only this field' is selected."), + '#states' => array( + 'enabled' => array( + ':input[name="options[use_fromto]"]' => array('value' => 'no'), + ), + ), + ); + $access = TRUE; if (!empty($this->definition['field_name'])) { $field = field_info_field($this->definition['field_name']); @@ -297,8 +318,40 @@ class date_views_argument_handler_simple extends views_handler_argument_date { // The simple case, match the field to the view range. $field = $this->date_handler->sql_field($this->table_alias . '.' . $this->real_field, NULL, $this->min_date); $field = $this->date_handler->sql_format($format, $field); - $this->query->add_where_expression($group, "$field >= $view_min_placeholder AND $field <= $view_max_placeholder", array($view_min_placeholder => $view_min, $view_max_placeholder => $view_max)); + $args = array( + 'min' => array($view_min_placeholder => $view_min), + 'max' => array($view_max_placeholder => $view_max), + ); + + switch ($this->options['operator']) { + case '<': + $where = "$field < $view_min_placeholder"; + $arg = $args['min']; + break; + case '<=': + $where = "$field <= $view_max_placeholder"; + $arg = $args['max']; + break; + case '>=': + $where = "$field >= $view_min_placeholder"; + $arg = $args['min']; + break; + case '<': + $where = "$field > $view_max_placeholder"; + $arg = $args['max']; + break; + case '!=': + $where = "$field < $view_min_placeholder OR $field > $view_max_placeholder"; + $arg = $args['min'] + $args['max']; + break; + case '=': + default: + $where = "$field >= $view_min_placeholder AND $field <= $view_max_placeholder"; + $arg = $args['min'] + $args['max']; + break; + } + $this->query->add_where_expression($group, $where, $arg); } else {