Hi,
Thanks for helping me out! I wanted to add a counter to the file download page to display the number of times something is downloaded (the way that this site's plugins pages have a counter).
Does anyone know how to do this? I'd appreciate the pointers on how to script this (I'm not much of a programmer) and what ELGG file belongs to the File download view (I'm struggling to find it!).
Much appreciated!!
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Mike Zacher (vazco)@vazco

Mike Zacher (vazco) - 0 likes
- tpogonat@tpogonat

tpogonat - 0 likes
You must log in to post replies.tpogonat, the best way to do this would be to use annotation, you can look at the fivestar plugin how it was done there. The other solution is to use metadata and use the metadata handler to allow everyone to change metadata:
register_plugin_hook('permissions_check:metadata', 'user', 'hereFunctionThatChecksIfMetadataIsCounter',1);
function hereFunctionThatChecksIfMetadataIsCounter($event, $object_type, $object, $vars){
if (!isset($vars['metadata']['name']))
return $object;
if ($vars['metadata']['name'] == 'download_counter')
return true;
return $object;
//return the original value of the hook (true/false in this case)
return $object;
}
Then it's enought if you use $object->download_counter++; after each download.
Ok, I think I understand somewhat in regards to your description of the Metadata.
So by using the metadata handler as you suggested, I registered the plugin hook and added the function call within the start.php of the mod/file/ directory. I added the download counter increase to the download.php in the actions directory (within the "if ($file) {}" statement) - the assumption I made was that after the exit statement, the counter would increase for every download.
What I'm having a hard time figuring out is how do I display this counter within the user's view of the file information (file/views/default/object/file.php). What would I need to do to call this value that gets incremented?
Also, i'm having a hard time relating how each file has it's own counter value? (thanks to my limited knowledge of scripting)....