Created a patch that provides Views for download_count and slightly improves the files_downloads table
| Project: | download_count |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Jump to:
I was in need of a "most popular downloads" list. Here's what I came up with. It adds an "nid" column to the file_downloads table so the new View can get a one-step join to the node table. With the View you can have the number of downloads as a field, as a filter and sort by it as well. For my listing of most popular downloads I filter by a particular content type and then if the number of downloads for a node's associate file is greater to or equal than 1. Then I sort by the number of downloads.
Attached is my Subversion diff output. I don't think you can run patch with it, but its fairly simple changes to do by hand.
Please consider incorporating this into download_count.
Thanks,
jason
| Attachment | Size |
|---|---|
| download_count_view.txt | 2.78 KB |

#1
There are reasons why there is only a filename in the download_count table to identify the file, and not a fid or nid.
If people move their file to another node, they do not want their download_counter to be reset to zero.
If the same 'physical' file is attached to many nodes, people want only ONE download_counter for it and not many.
As far as fid, the problem with using one is simple: say you want to update the file (correct a typo or bug or bring some improvement to it) through the Drupal interface, and you do not want the filename to change, you have to delete the original file attachment from the node and reupload a new (improved) file with the same name. If you do so, the download_counter picks up where it left off, it is not reset — just like the people I have spoken to wish. While the fid will not be the same. It increments automatically whenever we upload a file.
What matters about the file — all that matters — is the filename. The actual filename.
Since HOOK_file_download receives the actual filename as argument, it was a no brainer, as well, to use that value, and only that value in the table.
A re-design of the database would take all these matters into considerations. A definite advantage of adding nid and fid would be to decrease the amount of JOINs necessary in SOME situations. But it would increase them in OTHERS. Seems like kif-kif to me: if someone downloads a file with filename filename.ext, a check would have to be made EACH time to see if the file has the right nid and fid — at the time. And update these fields accordingly, whenever necessary. If you follow me, these (the nid and fid) could change, between downloads.
#2
Additionnally, before someone asks why not use the file description...?, the file description is not unique to the file. What is really unique about the file is that it exists in a directory on the server... what is unique about the file is its name.
#3
I also want a "most popular downloads" list. I'll test this patch when I get the chance.
#4
do you have view for drupal 6 as i added this code as i don't see thing in views.
Abi