You are here

function apachesolr_get_max_date in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 apachesolr.module \apachesolr_get_max_date()
  2. 6.3 apachesolr.module \apachesolr_get_max_date()

Callback that returns the maximum value of the facet's date field.

@todo Cache this value.

Parameters

$facet: An array containing the facet definition.

Return value

The maximum time of the field.

1 string reference to 'apachesolr_get_max_date'
date_apachesolr_field_mappings in ./apachesolr.module
Implements hook_apachesolr_field_mappings() on behalf of date module.

File

./apachesolr.module, line 2714
Integration with the Apache Solr search application.

Code

function apachesolr_get_max_date(array $facet) {

  // FieldAPI date fields.
  $table = 'field_data_' . $facet['field api name'];
  $column = $facet['field api name'] . '_value';
  $query = db_select($table, 't');
  $query
    ->addExpression('MAX(' . $column . ')', 'max');
  $query_max = $query
    ->execute()
    ->fetch()->max;

  // Update to unix timestamp if this is an ISO or other format.
  if (is_numeric($query_max)) {
    $return = (int) $query_max;
  }
  else {
    $return = strtotime($query_max);
    if ($return === FALSE) {

      // Not a string that strtotime accepts (ex. '0000-00-00T00:00:00').
      // Return default end date of 1 year from now.
      $return = time() + 52 * 7 * 24 * 60 * 60;
    }
  }
  return $return;
}