diff --git a/contrib/search_api_views/includes/handler_argument_date.inc b/contrib/search_api_views/includes/handler_argument_date.inc new file mode 100644 index 0000000..45ea24f --- /dev/null +++ b/contrib/search_api_views/includes/handler_argument_date.inc @@ -0,0 +1,86 @@ +argument. + */ + public function query($group_by = FALSE) { + if (empty($this->value)) { + $this->fillValue(); + } + + if (empty($this->options['not'])) { + $operator = '='; + $conjunction = 'AND'; + } + else { + $operator = '<>'; + $conjunction = 'OR'; + } + + if (!empty($this->argument)) { + $dates = explode(',', $this->argument); + + if (!empty($dates)) { + $filter = $this->query->createFilter($conjunction); + foreach ($dates as $date) { + list($min, $max) = explode(' - ', $date); + $is_range = !empty($max); + $range_op = (empty($this->options['not']) ? '>=' : '<'); + $filter->condition($this->real_field, $min, $is_range ? $range_op : $operator); + if ($is_range) { + $range_op = (empty($this->options['not']) ? '<=' : '>'); + $filter->condition($this->real_field, strtotime('+1 day', $max)+1, $range_op); + } + } + + $this->query->filter($filter); + } + } + } + + /** + * Get the title this argument will assign the view, given the argument. + */ + public function title() { + if (!empty($this->argument)) { + if (empty($this->value)) { + $this->fillValue(); + } + $terms = array(); + foreach ($this->value as $tid) { + $taxonomy_term = taxonomy_term_load($tid); + if ($taxonomy_term) { + $terms[] = check_plain($taxonomy_term->name); + } + } + + return $terms ? implode(', ', $terms) : check_plain($this->argument); + } + else { + return check_plain($this->argument); + } + } + + /** + * Fill $this->value with data from the argument. + * + * Uses views_break_phrase(), if appropriate. + */ + protected function fillValue() { + if (!empty($this->options['break_phrase'])) { + views_break_phrase($this->argument, $this); + } + else { + $this->value = array($this->argument); + } + } + +} diff --git a/contrib/search_api_views/search_api_views.info b/contrib/search_api_views/search_api_views.info index 5525a67..3619aa1 100644 --- a/contrib/search_api_views/search_api_views.info +++ b/contrib/search_api_views/search_api_views.info @@ -12,6 +12,7 @@ files[] = includes/handler_argument.inc files[] = includes/handler_argument_fulltext.inc files[] = includes/handler_argument_more_like_this.inc files[] = includes/handler_argument_string.inc +files[] = includes/handler_argument_date.inc files[] = includes/handler_argument_taxonomy_term.inc files[] = includes/handler_filter.inc files[] = includes/handler_filter_boolean.inc diff --git a/contrib/search_api_views/search_api_views.views.inc b/contrib/search_api_views/search_api_views.views.inc index da2936a..da67608 100644 --- a/contrib/search_api_views/search_api_views.views.inc +++ b/contrib/search_api_views/search_api_views.views.inc @@ -174,6 +174,7 @@ function _search_api_views_add_handlers($id, array $field, EntityMetadataWrapper } elseif ($inner_type == 'date') { $table[$id]['filter']['handler'] = 'SearchApiViewsHandlerFilterDate'; + $table[$id]['argument']['handler'] = 'SearchApiViewsHandlerArgumentDate'; } else { $table[$id]['filter']['handler'] = 'SearchApiViewsHandlerFilter'; @@ -182,7 +183,7 @@ function _search_api_views_add_handlers($id, array $field, EntityMetadataWrapper if ($inner_type == 'string') { $table[$id]['argument']['handler'] = 'SearchApiViewsHandlerArgumentString'; } - else { + else if (!isset($table[$id]['argument']['handler'])) { $table[$id]['argument']['handler'] = 'SearchApiViewsHandlerArgument'; }