You are here

protected static function SearchApiFacetapiDate::parseRangeFilter in Search API 7

Parses the date range filter value into parts.

Parameters

string $value: The user-facing facet value.

Return value

int[]|null An array of date parts, or NULL if an invalid value was provided.

1 call to SearchApiFacetapiDate::parseRangeFilter()
SearchApiFacetapiDate::createRangeFilter in contrib/search_api_facetapi/plugins/facetapi/query_type_date.inc
Rewrites the handler-specific date range syntax to the normal facet syntax.

File

contrib/search_api_facetapi/plugins/facetapi/query_type_date.inc, line 177
Date query type plugin for the Search API adapter.

Class

SearchApiFacetapiDate
Plugin for "date" query types.

Code

protected static function parseRangeFilter($value) {
  $parts = explode('-', $value);
  foreach ($parts as $i => $part) {

    // Invalidate if part is not an integer.
    if ($part === '' || !is_numeric($part) || intval($part) != $part) {
      return NULL;
    }
    $parts[$i] = (int) $part;

    // Depending on the position, negative numbers or 0 are invalid.
    switch ($i) {
      case 0:

        // Years can contain anything – negative values are unlikely, but
        // technically possible.
        break;
      case 1:
      case 2:

        // Days and months have to be positive.
        if ($part <= 0) {
          return NULL;
        }
        break;
      default:

        // All others can be 0, but not negative.
        if ($part < 0) {
          return NULL;
        }
    }
  }
  return $parts;
}