diff --git a/date_views/includes/date_views_argument_handler_simple.inc b/date_views/includes/date_views_argument_handler_simple.inc index 2839b95..5ab163a 100644 --- a/date_views/includes/date_views_argument_handler_simple.inc +++ b/date_views/includes/date_views_argument_handler_simple.inc @@ -96,6 +96,7 @@ class date_views_argument_handler_simple extends views_handler_argument_date { $options['granularity_reset'] = array('default' => FALSE); $options['default_argument_type']['default'] = 'date'; $options['add_delta'] = array('default' => ''); + $options['operation'] = array('default' => NULL); $options['use_fromto'] = array('default' => ''); $options['title_format'] = array('default' => ''); $options['title_format_custom'] = array('default' => ''); @@ -200,6 +201,30 @@ class date_views_argument_handler_simple extends views_handler_argument_date { // Only let mere mortals tweak this setting for multi-value fields. '#access' => $access, ); + + // Add the operation. + $operation_options = array( + '' => t('- Select -'), + '<' => 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'), + ); + $form['operation'] = array( + '#title' => t('Operation'), + '#type' => 'select', + '#options' => $operation_options, + '#description' => t('The comparison to perform to determine if the date field meets the condition. For multiple value date fields, all values will be checked to see if any meet the condition.'), + '#default_value' => isset($defaults['operation']) ? $defaults['operation'] : $this->options['operation'], + '#access' => $access, + '#states' => array( + 'visible' => array( + ':input[name="options[use_fromto]"]' => array('value' => 'no') + ), + ), + ); } /** @@ -211,6 +236,9 @@ class date_views_argument_handler_simple extends views_handler_argument_date { if (!preg_match('/^(?:\-[0-9]{1,4}|[0-9]{4}):(?:[\+\-][0-9]{1,4}|[0-9]{4})$/', $form_state['values']['options']['year_range'])) { form_error($form['year_range'], t('Date year range must be in the format -9:+9, 2005:2010, -9:2010, or 2005:+9')); } + if (!empty($form_state['values']['options']['use_fromto']) && empty($form_state['values']['options']['operation'])) { + form_error($form['operation'], t('Operation field is required.')); + } } /** @@ -308,6 +336,11 @@ class date_views_argument_handler_simple extends views_handler_argument_date { $this->ensure_my_table(); $group = !empty($this->options['date_group']) ? $this->options['date_group'] : 0; + // Add in our operations option. + if (!empty($this->options['operation'])) { + $this->query->add_where($group, $this->table_alias .'.'. $this->real_field, $this->argument, $this->options['operation']); + } + // If requested, add the delta field to the view so // we can later find the value that matched our query. if (!empty($this->options['add_delta']) && (substr($this->real_field, -6) == '_value' || substr($this->real_field, -7) == '_value2')) {