Closed (fixed)
Project:
Download Count
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
31 May 2010 at 04:46 UTC
Updated:
16 Jun 2010 at 00:30 UTC
This is what I use in a block...might be something useful here. I imagine there are better ways of doing some of this, but it works great for me. Will give a list of members (linked to their user page) according to how many downloads there have been of their files. I also use CSS classes and code to pretty it up but have stripped that out here. Oh, this also excludes uid 1 which I normally add to all my sql stuff. That can be taken out easily enough.
<table>
<tr>
<td>
<b>Member</b>
</td>
<td>
<b>Downloads</b>
</td>
</tr>
<?php
$limit = 8; // set how many you want listed here
$results = db_query("SELECT name, files.uid, SUM(count) AS UsersTotalDownloads
FROM upload
JOIN {files} ON upload.fid = files.fid
JOIN {file_downloads}
ON files.filepath = CONCAT( 'sites/default/files/', file_downloads.filename )
JOIN {users} ON files.uid = users.uid
WHERE files.uid != %d
GROUP BY users.name
ORDER BY `UsersTotalDownloads` DESC LIMIT %d", 1, $limit);
while($output = db_fetch_object($results)){
print "<tr><td>";
print "<a href=\"/user/$output->uid\">";
print $output->name;
print "</a>";
print "</td><td>";
print $output->UsersTotalDownloads;
print "</td></tr>";
}
?>
</table>
Comments
Comment #1
WorldFallz commentedexcellent-- thanks for posting this.
Comment #2
esllou commentedglad to help, it's really cool being able to contribute something back to drupal for once. I've taken enough! :-)
Comment #3
WorldFallz commentedI'm playing around with Views 3 -- and this is already completely doable with download_count 2.x's current level of views integration using views version 3's grouping features. Very slick.
Comment #4
WorldFallz commentedInstead of wasting time banging my head on the wall trying to shoehorn this functionality into views 2 integration, I'll probably just add a couple of default blocks like this to dc 2.x for the time being, recommend using Views 3, and provide a nice views 3 default view.
Comment #5
esllou commentedso having Views 2 wouldn't be enough? Is views 3 ready??
Comment #6
WorldFallz commentedYou can do the basics with views 2, but not the aggregations. And getting the aggregations into views 2 seems to be non trivial -- at least for me. I blew a whole day on it, and still can't figure it out.
As for views 3 being ready-- I've been using it for a while and it's been very stable. Between the grouping and exposed sort features, I'm finding it difficult to go back to views 2. It's also the basis for views for d7, so I really can't justify spending any more time on this for views 2-- unless someone who knows the views api provides a patch.
Comment #7
WorldFallz commentedhttp://drupal.org/cvs?commit=374254