You are here

function apachesolr_get_min_date in Apache Solr Search 8

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

Callback that returns the minimum date of the facet's datefield.

@todo Cache this value.

Parameters

$facet: An array containing the facet definition.

Return value

The minimum time in the node table.

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

File

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

Code

function apachesolr_get_min_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('MIN(' . $column . ')', 'min');
  $query_min = $query
    ->execute()
    ->fetch()->min;

  // Update to unix timestamp if this is an ISO or other format.
  if (!is_int($query_min)) {
    $return = strtotime($query_min);
    if ($return === FALSE) {

      // Not a string that strtotime accepts (ex. '0000-00-00T00:00:00').
      // Return default start date of 1 as the date query type getDateRange()
      // function expects a non-0 integer.
      $return = 1;
    }
  }
  return $return;
}