Creating a File Block programmatically

Permalink 1 user found helpful
Hey..

I've only recently starting using Concrete5, but I love it already, though there is something that's starting to give me grey hairs on my head.

I simply cannot find a way to create a File Block programmatically.

I want to use it, to create an Download url which is tracked.

Can anyone help me ?

Regards
Kim

 
jordanlev replied on at Permalink Reply
jordanlev
How do you want to track the download URL? Or rather, what information is it you want to see about downloads -- is it registered users only or anyone viewing the site? If anyone can download, how do you want to identify them? Do you want a dashboard screen that shows number of downloads per file, or something that shows number of total downloads per user?

Concrete5 comes with a built-in "File" block that provides a file download, but not with any kind of tracking. That may be a good place to start -- copy that and build out from there (but you'll need to figure out how the tracking works and build out that portion of the functionality from there).
SilverDK replied on at Permalink Reply
Hey and thanks for the response..

If you go to the "Dashboard" and select "File Manager", then click on a file and select "Properties", in the window that opens, there is a "Statistics" tab which present's itself as "Download Statistics", those counted there are the ones I'm interested in..

I also looked through the code of the file block, and the "File" class, has an "trackDownload" method which takes the page id as an parameter, if I have figured out the method correctly..

But, I think you're right, I properly need to change the "File" block, to actually call the "trackDownload" method on the "File" class, but I need to play with it a lot more, before I find a method that will work..

If you, or any reading this post, have any good advice, links to tutorials, a link to an complete API document (*chuckles*), I'd love it..
jordanlev replied on at Permalink Reply
jordanlev
Interesting, I never knew about those file statistics -- pretty cool!

So I think that's just a built-in feature of C5, I don't think you need to do anything special to make it track those statistics. You can test this out by uploading a new file, adding a "File" block to a page, and then downloading that file from the page, then going back to the statistics and seeing if it added an entry to it.

Assuming that works, then what else is it that you'd want this block to do (show the statistics in an easier-to-find place than the properties I presume? Or something else?)
SilverDK replied on at Permalink Reply
I have a list of pictures in a gallery, that has a link to download the full size picture, because I don't use the full size in lightbox, due to their large resolution 3000+px..

I made it so, that lightbox only shows an 1280x720 pixel image, and if the user wants they can click the download button underneath the picture.. You can see the gallery here:http://www.selune.dk/index.php/gallery/werewolf-costume/...

What I want to do is to instantiate an File block in code, so I can set the File name and get a download url, that uses the download_file single page, which I believe automatically tracks the download..

But due to the fact that I'm new to concrete5, I haven't mastered the use of "View::url" yet, so I don't know how to pass the specific parameters that "download_file" needs to work..

If I could get a little more insight into how you create an url with "View::url" it might help me a bit..

Thanks for reading.
Kim
jordanlev replied on at Permalink Best Answer Reply
jordanlev
Here's how to use the View::url function to output a link to a file. Note that you'll need to get the file id somehow (should be in the code of the lightbox block you're using somehow... maybe)
<?php
$fileID = 123;
echo View::url('/download_file', $fileID, Page::getCurrentPage()->getCollectionID());
?>
SilverDK replied on at Permalink Reply
Thank you very much.. That cleared it up a bit, now I just need to incorperate it into the code I have already, but I am sure it isn't that hard..

What Concrete5 really needs is a good API documentation *chuckles*

Thanks again for the answer.

Kim
jordanlev replied on at Permalink Reply
jordanlev
I wholeheartedly agree that better API docs would be supremely useful.
SilverDK replied on at Permalink Reply
Woo! It works. *chuckles* Now I just need to code an Dashboard plugin, so that I can easily see downloads for the files that have download stats, instead of going through every file to find those that have been downloaded.

Thanks again for your help
Kim
jordanlev replied on at Permalink Reply
jordanlev
Awesome! If you're going to build a dashboard interface, I recommend reading this how-to:
http://www.concrete5.org/documentation/how-tos/developers/build-a-s...

Ignore the stuff about the FAQs -- just use it as a reference to see how controllers and views (aka single_pages) need to be structured in the dashboard.
SilverDK replied on at Permalink Reply
Thank you very much for all the help..

I will read through the link provided..

Thanks again
Kim
corschepens replied on at Permalink Reply
Hi,

It sound you are looking for the same thing as I need.
Registered Users can download files from our website and I want a logfile (or a special page for admin) showing which registered user has downloaded which file and when.

Is this what you have been able to achieve?
If yes, can you tell me how to do this?
davidprotean replied on at Permalink Reply
Hi Corschepens,

Did you find a solution? I need to do the exact same thing... I need to know which registered users downloaded which PDF files.
corschepens replied on at Permalink Reply
Hi David,

My colleague found a solution and wrote some PHP code. I believe the info is already stored inside the concrete database. You just need to pull it out with some PHP code.
davidprotean replied on at Permalink Reply
Thanks for responding. I'll take a look...
I was hoping for an add-on :-(
Courtney replied on at Permalink Reply
Hi David,

Did you find a solution to this? I have to set up the same thing with my site.

Thanks in Advance.
McCormick replied on at Permalink Reply
McCormick
Have you checked out JordanLev's Designer Content block? You could use it to create a block in the dashboard and add it to your blocks folder (root/blocks/). It demonstrates ways to create many types of blocks.

http://www.concrete5.org/marketplace/addons/designer-content/...
davidprotean replied on at Permalink Reply
Hi,

I had to employ someone to pull out the data from the database using PHP as I could not find another solution. It's not the most elegant solution, but it more or less works for my needs. I then have a page outside of concrete5 where I can view and export the stats.