function download_count_view_page in Download Count 7.3
Same name and namespace in other branches
- 5 download_count.module \download_count_view_page()
- 6.2 includes/download_count.pages.inc \download_count_view_page()
- 6 download_count.module \download_count_view_page()
- 7.2 includes/download_count.pages.inc \download_count_view_page()
Page callback for the view download counts page.
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 11 - Administrative page callbacks for the download_count module.
Code
function download_count_view_page($arg = NULL) {
drupal_set_title(variable_get('download_count_view_page_title', 'Download Counts'));
$total_downloads = 0;
$colspan = 0;
$item = 1;
$limit = (int) variable_get('download_count_view_page_limit', 0);
$items_per_page = (int) variable_get('download_count_view_page_items', 0);
$page_header = variable_get('download_count_view_page_header', '');
$page_footer = variable_get('download_count_view_page_footer', '');
$output = '<div id="download-count-page">';
$header = array(
array(
'data' => t('#'),
),
array(
'data' => t('Count'),
'field' => 'count',
'sort' => 'desc',
),
array(
'data' => t('FID'),
'field' => 'FID',
),
array(
'data' => t('Entity Type'),
'field' => 'type',
),
array(
'data' => t('Entity ID'),
'field' => 'id',
),
array(
'data' => t('File name'),
'field' => 'filename',
),
array(
'data' => t('File Size'),
'field' => 'file-size',
),
array(
'data' => t('Total Size'),
'field' => 'total-size',
),
array(
'data' => t('Last Downloaded'),
'field' => 'last',
),
);
$query = db_select('download_count', 'dc')
->fields('dc', array(
'dcid',
'type',
'id',
))
->fields('f', array(
'filename',
'fid',
'filesize',
'uri',
))
->groupBy('dc.type')
->groupBy('dc.id')
->groupBy('dc.fid');
$query
->addExpression('COUNT(dc.dcid)', 'count');
$query
->addExpression('COUNT(dc.dcid) * f.filesize', 'total-size');
$query
->addExpression('MAX(dc.timestamp)', 'last');
$query
->join('file_managed', 'f', 'dc.fid = f.fid');
if ($limit > 0) {
$query
->range(0, $limit);
}
if ($items_per_page > 0) {
$query = $query
->extend('PagerDefault')
->limit($items_per_page);
}
$query = $query
->extend('TableSort')
->orderByHeader($header);
$rows = array();
$result = $query
->execute();
foreach ($result as $file) {
$row = array();
$row[] = $item;
$row[] = number_format($file->count);
$row[] = $file->fid;
$row[] = check_plain($file->type);
$row[] = $file->id;
$row[] = check_plain($file->filename);
$row[] = format_size($file->filesize);
$row[] = format_size($file->count * $file->filesize);
$row[] = t('@time ago', array(
'@time' => format_interval(REQUEST_TIME - $file->last),
));
$row[] = l(t('Details'), 'admin/reports/download-count/' . $file->dcid . '/details');
if (user_access('export download counts')) {
$row[] = l(t('Export'), 'admin/reports/download-count/' . $file->dcid . '/export');
}
if (user_access('reset download counts')) {
$row[] = l(t('Reset'), 'admin/reports/download-count/' . $file->dcid . '/reset');
}
$rows[] = $row;
$item++;
$total_downloads += $file->count;
$colspan = count($rows[0]) - count($header);
}
if (empty($rows)) {
$rows[] = array(
array(
'data' => t('No files have been downloaded.'),
'colspan' => '9',
),
);
}
if ($colspan > 1) {
$header[] = array(
'data' => t('Actions') . ' [' . l(t('Details All'), 'admin/reports/download-count/all/details') . (user_access('export download counts') ? l(t('Export All'), 'admin/reports/download-count/all/export') : NULL) . (user_access('reset download counts') ? l(t('Reset All'), 'admin/reports/download-count/all/reset') : NULL) . ']',
'colspan' => $colspan,
'id' => 'actions',
);
drupal_add_css(drupal_get_path('module', 'download_count') . '/download_count.css');
}
if (!empty($page_header['value'])) {
$output .= '<div id="download-count-header">' . check_markup($page_header['value'], $page_header['format']) . '</div>';
}
$output .= '<div id="download-count-total-top">' . t('Total Downloads:') . ' ' . number_format($total_downloads) . '</div>';
$output .= theme('table', array(
'header' => $header,
'rows' => $rows,
'attributes' => array(
'id' => 'download-count-table',
),
));
$output .= '<div id="download-count-total-bottom">' . t('Total Downloads:') . ' ' . number_format($total_downloads) . '</div>';
if ($items_per_page > 0) {
$output .= theme('pager', array(
'tags' => array(),
));
}
if (!empty($page_footer['value'])) {
$output .= '<div id="download-count-footer">' . check_markup($page_footer['value'], $page_footer['format']) . '</div>';
}
$output .= '</div>';
return $output;
}