You are here

function download_count_view_page in Download Count 7.2

Same name and namespace in other branches
  1. 5 download_count.module \download_count_view_page()
  2. 6.2 includes/download_count.pages.inc \download_count_view_page()
  3. 6 download_count.module \download_count_view_page()
  4. 7.3 includes/download_count.pages.inc \download_count_view_page()

@file Page callback file for the download_count module.

1 string reference to 'download_count_view_page'
download_count_menu in ./download_count.module
Implements hook_menu().

File

includes/download_count.pages.inc, line 7
Page callback file for the download_count module.

Code

function download_count_view_page($arg = NULL) {
  global $user;
  $rows = array();
  $header = array();
  $result = NULL;
  $header[] = array(
    'data' => t('Count'),
    'field' => 'count',
    'sort' => 'desc',
    'class' => 'count',
  );
  $header[] = array(
    'data' => t('File'),
    'field' => 'filename',
    'class' => 'file',
  );
  $header[] = array(
    'data' => t('Page'),
    'field' => 'title',
    'class' => 'page',
  );
  $header[] = array(
    'data' => t('Last Download'),
    'field' => 'last',
    'class' => 'date',
  );
  if ($arg == 'download_count') {
    drupal_set_title(check_plain(variable_get('download_count_view_page_title', t('Download Count'))));
    $limit = (int) variable_get('download_count_view_page_limit', '');
    $file_links = variable_get('download_count_file_links', 1);
    if (!$limit) {

      // TODO Please convert this statement to the D7 database API syntax.
      $result = db_query("SELECT COUNT(dc.dcid) AS count, dc.dcid, f.filename, MAX(dc.timestamp) AS last, dc.nid, f.filepath, f.fid, n.title FROM {download_count} dc JOIN {files} f ON dc.fid = f.fid JOIN {node} n ON dc.nid = n.nid GROUP BY dc.nid, f.filename" . tablesort_sql($header));
    }
    else {

      // TODO Please convert this statement to the D7 database API syntax.
      $result = db_query("SELECT COUNT(dc.dcid) AS count, dc.dcid, f.filename, MAX(dc.timestamp) AS last, dc.nid, f.filepath, f.fid, n.title FROM {download_count} dc JOIN {files} f ON dc.fid = f.fid JOIN {node} n ON dc.nid = n.nid GROUP BY dc.nid, f.filename" . tablesort_sql($header) . " LIMIT %d", $limit);
    }
    $output = '<div id="download_count_page">';
  }
  elseif ($arg == 'my_download_count') {
    drupal_set_title(check_plain(variable_get('download_count_mypage_view_page_title', t('My Download Counts'))));
    $limit = (int) variable_get('download_count_mypage_view_page_limit', '');
    $file_links = variable_get('download_count_mypage_file_links', 1);
    if (!$limit) {

      // TODO Please convert this statement to the D7 database API syntax.
      $result = db_query("SELECT COUNT(dc.dcid) AS count, dc.dcid, f.filename, MAX(dc.timestamp) AS last, dc.nid, f.filepath, f.fid, n.title FROM {download_count} dc JOIN {files} f ON dc.fid = f.fid JOIN {node} n ON dc.nid = n.nid WHERE dc.uid = %d GROUP BY dc.nid, f.filename" . tablesort_sql($header), $user->uid);
    }
    else {

      // TODO Please convert this statement to the D7 database API syntax.
      $result = db_query("SELECT COUNT(dc.dcid) AS count, dc.dcid, f.filename, MAX(dc.timestamp) AS last, dc.nid, f.filepath, f.fid, n.title FROM {download_count} dc JOIN {files} f ON dc.fid = f.fid JOIN {node} n ON dc.nid = n.nid WHERE dc.uid = %d GROUP BY dc.nid, f.filename" . tablesort_sql($header) . " LIMIT %d", $user->uid, $limit);
    }
    $output = '<div id="my_download_count_page">';
  }
  $total_downloads = 0;
  $files = array();
  $nodes = array();
  $colspan = 0;
  while ($file = db_fetch_object($result)) {
    $row = array();
    $node = node_load($file->nid);
    $row[] = $file->count;
    $row[] = $file_links && (user_access('view uploaded files') || _download_count_is_accessible_by_filefield($file->filepath)) ? l(t('@filename', array(
      '@filename' => $file->filename,
    )), function_exists('_private_upload_create_url') ? _private_upload_create_url($file) : file_create_url($file->filepath)) : $file->filename;
    $row[] = node_access('view', $node) ? l(t('@title', array(
      '@title' => $node->title,
    )), 'node/' . $node->nid) : check_plain($node->title);
    $row[] = t('@time ago', array(
      '@time' => format_interval(REQUEST_TIME - $file->last),
    ));
    user_access('administer site configuration') ? $row[] = l(t('Reset'), 'download_count/' . $file->dcid . '/reset') : NULL;
    $rows[] = $row;
    $total_downloads += $file->count;
    $files[] = $file->filename;
    $nodes[] = $node->title;
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('No files have been downloaded.'),
        'colspan' => '4',
      ),
    );
  }
  user_access('administer site configuration') && $total_downloads > 0 ? $header[] = t('Action ') . l(t('(Reset All)'), 'download_count/all/reset') : NULL;
  $output .= $arg == 'download_count' ? check_markup(variable_get('download_count_view_page_header', ''), variable_get('download_count_view_page_format', 0), $langcode = '', FALSE) : check_markup(variable_get('download_count_mypage_view_page_header', ''), variable_get('download_count_mypage_view_page_format', 0), $langcode = '', FALSE);
  $output .= '<span id="download_count_summary_top">' . t('Unique Pages: ') . count(array_unique($nodes)) . ', Unique Files: ' . count(array_unique($files)) . ', Total Downloads: ' . $total_downloads . '</span>';
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'download_count_table',
    ),
  ));
  $output .= '<span id="download_count_summary_bottom">' . t('Unique Pages: ') . count(array_unique($nodes)) . ', Unique Files: ' . count(array_unique($files)) . ', Total Downloads: ' . $total_downloads . '</span>';
  $output .= $arg == 'download_count' ? check_markup(variable_get('download_count_view_page_footer', ''), variable_get('download_count_view_page_format', 0), $langcode = '', FALSE) : check_markup(variable_get('download_count_mypage_view_page_footer', ''), variable_get('download_count_mypage_view_page_format', 0), $langcode = '', FALSE);
  $output .= '</div>';
  return $output;
}