You are here

function _download_count_block_contents in Download Count 7.3

Same name and namespace in other branches
  1. 6.2 download_count.module \_download_count_block_contents()
  2. 7.2 download_count.module \_download_count_block_contents()

Generate block contents based on delta.

1 call to _download_count_block_contents()
download_count_block_view in ./download_count.module
Implements hook_block_view().

File

./download_count.module, line 306
Tracks file downloads for files stored in the drupal files table using the private files setting or custom private filefield.

Code

function _download_count_block_contents($block) {
  $limit = (int) variable_get('download_count_' . $block . '_block_limit', 10);
  $rows = array();
  if ($block == 'top_files') {
    $sql = 'SELECT dcc.fid, dcc.count, f.filename, f.filesize FROM {download_count_cache} dcc JOIN {file_managed} f ON dcc.fid = f.fid ORDER BY dcc.count DESC';
  }
  else {
    $sql = 'SELECT dc.fid, MAX(dc.timestamp) as date, f.filename, f.filesize FROM {download_count} dc JOIN {file_managed} f ON dc.fid = f.fid GROUP BY dc.fid ORDER BY date DESC';
  }
  $header[] = array(
    'data' => t('Name'),
    'class' => 'filename',
  );
  $header[] = array(
    'data' => t('Size'),
    'class' => 'size',
  );
  $header[] = array(
    'data' => $block == 'top_files' ? t('Count') : t('Last Downloaded'),
    'class' => $block == 'top_files' ? 'count' : 'last',
  );
  $result = db_query_range($sql, 0, $limit);
  foreach ($result as $file) {
    $row = array();
    $row[] = check_plain($file->filename);
    $row[] = format_size($file->filesize);
    $row[] = $block == 'top_files' ? $file->count : t('%time ago', array(
      '%time' => format_interval(REQUEST_TIME - $file->date),
    ));
    $rows[] = $row;
  }
  if (count($rows)) {
    return theme('table', array(
      'header' => $header,
      'rows' => $rows,
      'sticky' => FALSE,
    ));
  }
}