You are here

function ApacheSolrFacetapiDate::getDateRange in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 plugins/facetapi/query_type_date.inc \ApacheSolrFacetapiDate::getDateRange()
  2. 6.3 plugins/facetapi/query_type_date.inc \ApacheSolrFacetapiDate::getDateRange()

Gets the range of dates we are using.

Parameters

DrupalSolrQueryInterface $query: A SolrBaseQuery object.

Return value

bool|array An array containing the gap and range information or false if not present

1 call to ApacheSolrFacetapiDate::getDateRange()
ApacheSolrFacetapiDate::execute in plugins/facetapi/query_type_date.inc
Adds the filter to the query object.

File

plugins/facetapi/query_type_date.inc, line 65
Date query type plugin for the Apache Solr adapter.

Class

ApacheSolrFacetapiDate
Plugin for "date" query types.

Code

function getDateRange(DrupalSolrQueryInterface $query) {
  $return = NULL;
  $gap = NULL;

  // Attempts to get next gap from passed date filters.
  foreach ($this->adapter
    ->getActiveItems($this->facet) as $item) {
    if ($gap = facetapi_get_date_gap($item['start'], $item['end'])) {
      $next_gap = facetapi_get_next_date_gap($gap, FACETAPI_DATE_SECOND);
      if ($next_gap == $gap) {
        $next_gap = NULL;
        return NULL;
      }
      $return = array(
        "{$item['start']}/{$next_gap}",
        "{$item['end']}+1{$next_gap}/{$next_gap}",
        "+1{$next_gap}",
      );
    }
  }

  // If no filters were passed, get default range.
  if (NULL === $return) {

    // Builds SQL that gets minimum and maximum values from node table.
    $minimum = $maximum = FALSE;
    if ($this->facet['min callback'] && is_callable($this->facet['min callback'])) {
      $minimum = $this->facet['min callback']($this->facet);
    }
    if ($this->facet['max callback'] && is_callable($this->facet['max callback'])) {
      $maximum = $this->facet['max callback']($this->facet);
    }

    // Gets the default gap.

    //$gap = FACETAPI_DATE_YEAR;
    if ($minimum && $maximum) {
      $gap = facetapi_get_timestamp_gap($minimum, $maximum);
      $minimum = facetapi_isodate($minimum, $gap);
      $maximum = facetapi_isodate($maximum, $gap);
      $return = array(
        "{$minimum}/{$gap}",
        "{$maximum}+1{$gap}/{$gap}",
        "+1{$gap}",
      );
    }
  }

  // Returns the range information.
  return $return;
}