Since webfm is not integrated into views I have a request.
I want to make a block to display the top 5 downloaded files. So basically it should display the node titles where the files are attached to sorted on the dl_count descending.
I am not much of a programmer and am struggling with this. Is there anyone who has some code for me (to put into a block) or how to make that block working.

Thanks

Comments

robmilne’s picture

Not a difficult task for a custom module and a bit of sql however it does require programming skill. I believe there are ways of contracting help within the Drupal community - I'm too busy to offer my services.

erald’s picture

Well I made a block in the mean time by simply use the option to put some php code in the block. Know enough PHP to make this.. :)
This will display the node titles of the top 3 downloaded files

This code I used

$query ="SELECT a.fid, a.dl_cnt, c.nid, c.title 
FROM {webfm_file} a 
LEFT OUTER JOIN {webfm_attach} b ON a.fid = b.fid 
LEFT OUTER JOIN {node} c ON b.nid = c.nid 
ORDER BY a.dl_cnt DESC";

$result = db_query_range($query, 0, 3);

while ($data = db_fetch_object($result)) {
    $nodeurl = url('node/'. $data->nid);
  $rows[] =  '<a href="'. $nodeurl . '">'. $data->title.'</a>';
}

print theme('item_list', $rows);

Philo72’s picture

Modified eralds code a little for my purposes. Included for anyone who wants it.

All i have done is add the path and the size from the webfm_file table then explode the path to get the file name and change the link to allow a user webfm_send the file. I also added a bit of info on download count and size.

Not a neat coder but. if there is any way to do it better i'm all ears. :)

$query ="SELECT a.fid, a.dl_cnt, c.nid, c.title, a.fpath,a.fsize
FROM {webfm_file} a
LEFT OUTER JOIN {webfm_attach} b ON a.fid = b.fid
LEFT OUTER JOIN {node} c ON b.nid = c.nid
ORDER BY a.dl_cnt DESC";

$result = db_query_range($query, 0, 5);

while ($data = db_fetch_object($result)) {
    $filename = end(explode('/', $data->fpath)); 
    $nodeurl = url('webfm_send/'. $data->fid);
    if (round(($data->fsize/1024),0) >= 1024) {
        $size = round((($data->fsize/1024)/1024),0).'Mb';
    }else{
        $size = round(($data->fsize/1024),0).'Kb';
    }
  $rows[] =  '<a href="'. $nodeurl . '">'. $filename.' ('.$data->dl_cnt.' times) ('.$size.' size)</a>';
}
print theme('item_list', $rows);