Show number of downloads with a custom template

Permalink 1 user found helpful
Hey everyone,

I'm having some problems with my custom template for the file-block.
My Plan is very simple:
I just want to show the number of downloads (for each single file) beneath the download-link of the file.
For that I've just created a new template, inlcluding the following code:

<?php   defined('C5_EXECUTE') or die("Access Denied.");
   $f = $controller->getFileObject();
   $fp = new Permissions($f);
   if ($fp->canRead()) { 
      $c = Page::getCurrentPage();
      if($c instanceof Page) {
         $cID = $c->getCollectionID();
      }
?>
<a href="<?php echo  View::url('/download_file', $controller->getFileID(),$cID) ?>"><?php echo  stripslashes($controller->getLinkText())?></a>
<?php
   $f = File::getByID($fileID);
   $r = $f->getDownloadStatistics();
   echo $r;
   echo '<br>';


I'm not very good at this, so it might be a very simple error.
It would be very nice, if somone could help me. :-)

Greets,
Kalli

Kalli
 
Kalli replied on at Permalink Reply
Kalli
No Ideas?
cioclod replied on at Permalink Reply
Unfortunately, C5 has a very low number of developers, unlike wordpress, which probably has tens of addons that do exactly what you need. And the developers that create C5 addons price them EXTREMELY high...
mnakalay replied on at Permalink Reply
mnakalay
Hello,

In your code you have this line
$f = File::getByID($fileID);


This would be ok if $fileID was defined but I don't see it defined anywhere. What it means is that you are trying to get statistics for a non-existent file.

I agree with cioclod that we are not as big a group of developers as what you can find with Wordpress but I can tell you that we are still an extremely supportive community with some very high level people who spend a lot of time helping others just for the sake of it.
Concerning prices, I'm not going to mention all the free addons, but the ratio of bad addons is extremely low compared to Wordpress. Many addons are priced $15 which is not very high considering that for that price you have the right to full support or your money back plus a penalty for the developer who didn't provide support or mislead the buyer on the quality of the addon. In short, whatever the price, if it doesn't do what it's supposed to do you get a refund and the developer looses 10% on top of it.
With wordpress you never know what you're going to get and unless the developer is highly professional and honest, you'll get no support and no money back if you have a problem.

Anyway, just an opinion, but based on (some) facts :)
Phallanx replied on at Permalink Best Answer Reply
Phallanx
I have file block which only shows a download link for logged in users and only shows the number of files for admins.

This is how it works.
<?php   defined('C5_EXECUTE') or die("Access Denied.");
   $f = $controller->getFileObject();
   $fp = new Permissions($f);
   //if ($fp->canRead()) { 
      $c = Page::getCurrentPage();
      if($c instanceof Page) {
         $cID = $c->getCollectionID();
      }
      $db = Loader::db();
      $fID =  $controller->getFileID();
      $num = $db->GetOne("SELECT Count(fID) FROM DownloadStatistics  WHERE DownloadStatistics.fID=$fID" );
      $u = new User();
   //}   
?>
<ul><li>
Kalli replied on at Permalink Reply
Kalli
I'm new in the C5-Community and I assumed that the ammount of people is not as big as in some others.

But this was my first thread and I have to say, I'm very impressed.

Phallanx code just works perfectly for me! :-)
So thank you very much!
mnakalay replied on at Permalink Reply
mnakalay
Very happy you are convinced, welcome to the community, may your stay be long and fruitful :)