function apachesolr_get_min_date in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr.module \apachesolr_get_min_date()
 - 6.3 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 2680  - 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_numeric($query_min)) {
    $return = (int) $query_min;
  }
  else {
    $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;
}