function theme_download_count_formatter_download_count in Download Count 7.2
Same name and namespace in other branches
- 6.2 includes/download_count.theme.inc \theme_download_count_formatter_download_count()
@todo Please document this function.
See also
File
- includes/
download_count.theme.inc, line 31 - Theme related functions for the download_count module.
Code
function theme_download_count_formatter_download_count($variables) {
$element = $variables['element'];
if (empty($element['#item']['fid'])) {
return '';
}
global $user;
$file = $element['#item'];
$node = $element['#node'];
$field = content_fields($element['#field_name']);
$filepath = $file['filepath'];
if (user_access('view own download counts') && $user->uid != 1) {
$count = db_query("SELECT COUNT(dc.dcid) FROM {download_count} dc JOIN {files} f ON dc.fid = f.fid WHERE f.filepath = :f.filepath AND dc.nid = :dc.nid AND dc.uid = :dc.uid", array(
':f.filepath' => $filepath,
':dc.nid' => $node->nid,
':dc.uid' => $user->uid,
))
->fetchField();
}
elseif (user_access('view all download counts')) {
$count = db_query("SELECT COUNT(dc.dcid) FROM {download_count} dc JOIN {files} f ON dc.fid = f.fid WHERE f.filepath = :f.filepath AND dc.nid = :dc.nid", array(
':f.filepath' => $filepath,
':dc.nid' => $node->nid,
))
->fetchField();
}
// TODO Please change this theme call to use an associative array for the $variables parameter.
$output = theme('filefield_file', $file);
if ($output) {
if (user_access('view all download counts') || user_access('view own download counts')) {
$text = ' — ';
if ($count) {
$text .= format_plural($count, 'Downloaded 1 time', 'Downloaded @count times');
}
else {
$text .= t('Never downloaded');
}
}
else {
$text = '';
}
if (substr($output, -6) == '</div>') {
return substr($output, 0, -6) . $text . '</div>';
}
else {
return $output . $text;
}
}
return $output;
}