function download_count_export_data in Download Count 7.3
1 call to download_count_export_data()
- download_count_export_form_submit in includes/
download_count.export.inc - Implements hook_submit().
File
- includes/
download_count.export.inc, line 91 - Page callback file for the download_count module export feature.
Code
function download_count_export_data($filename, $range, $file_info, $start, $end) {
ob_end_clean();
drupal_add_http_header('Content-Disposition', 'attachment; filename="' . $filename . '"');
drupal_add_http_header('Content-Type', 'application/csv');
drupal_send_headers();
$query = db_select('download_count', 'dc')
->fields('dc', array(
'dcid',
'fid',
'type',
'id',
'uid',
'ip_address',
'referrer',
'timestamp',
))
->fields('f', array(
'filename',
'filesize',
'uri',
))
->fields('u', array(
'name',
));
$query
->join('file_managed', 'f', 'dc.fid = f.fid');
$query
->join('users', 'u', 'dc.uid = u.uid');
if ($file_info != 'all') {
$query
->condition('dc.type', $file_info->type, '=');
$query
->condition('dc.id', $file_info->id, '=');
$query
->condition('dc.fid', $file_info->fid, '=');
}
if ($range > 0) {
$from = strtotime($start['year'] . '-' . $start['month'] . '-' . $start['day']);
$to = strtotime($end['year'] . '-' . $end['month'] . '-' . $end['day']);
if ($from == $to) {
$to += 86400;
}
$query
->condition('dc.timestamp', $from, '>=');
$query
->condition('dc.timestamp', $to, '<=');
}
$result = $query
->execute();
$column_names = '"Download count id","File id","File name","File URI","File size","Entity type","Entity id","Downloading user id","Downloading username","Downloading user ip address","HTTP referrer","Date time"' . "\n";
print $column_names;
foreach ($result as $record) {
$row = '"' . $record->dcid . '"' . ',';
$row .= '"' . $record->fid . '"' . ',';
$row .= '"' . $record->filename . '"' . ',';
$row .= '"' . $record->uri . '"' . ',';
$row .= '"' . $record->filesize . '"' . ',';
$row .= '"' . $record->type . '"' . ',';
$row .= '"' . $record->id . '"' . ',';
$row .= '"' . $record->uid . '"' . ',';
$row .= '"' . $record->name . '"' . ',';
$row .= '"' . $record->ip_address . '"' . ',';
$row .= '"' . $record->referrer . '"' . ',';
$row .= '"' . date('Y-m-d H:i:s', $record->timestamp) . '"';
$row .= "\n";
print $row;
}
exit;
}