function _archive_query in Archive 7
Same name and namespace in other branches
- 5 archive.inc \_archive_query()
 - 6 archive.pages.inc \_archive_query()
 - 7.2 archive.pages.inc \_archive_query()
 
Builds an archive SQL query with its parameters for the specified date.
Parameters
$date: A date object obtained from _archive_date().
Return value
An array of (query, param_start, param_end).
1 call to _archive_query()
- archive_page in ./
archive.pages.inc  - Fetch nodes for the selected date, or current date if none selected.
 
File
- ./
archive.pages.inc, line 118  - Pages for the archive module.
 
Code
function _archive_query($type, $date) {
  // Confine the display interval to only one day
  if ($date->day) {
    $start = mktime(0, 0, 0, $date->month, $date->day, $date->year);
    $end = mktime(0, 0, 0, $date->month, $date->day + 1, $date->year);
  }
  elseif ($date->month) {
    $start = mktime(0, 0, 0, $date->month, 1, $date->year);
    $end = mktime(0, 0, 0, $date->month + 1, 1, $date->year);
  }
  elseif ($date->year) {
    $start = mktime(0, 0, 0, 1, 1, $date->year);
    $end = mktime(0, 0, 0, 1, 1, $date->year + 1);
  }
  else {
    $start = 0;
    $end = 0;
  }
  // Grab limits on node types if exist
  $final_types = _archive_types_sql_array($type);
  // Allow viewing all nodes, not just nodes by year
  $query = db_select('node', 'n');
  $query
    ->fields('n', array(
    'nid',
    'type',
  ));
  $query
    ->condition('n.status', 1);
  $query
    ->orderBy('n.created', 'DESC');
  $query
    ->condition('n.type', $final_types, 'IN');
  $query
    ->addTag('node_access');
  if ($start && $end) {
    $query
      ->condition('n.created', $start - $date->tz, '>=');
    $query
      ->condition('n.created', $end - $date->tz, '<=');
  }
  return $query;
}