Added a download counter.

Because we like stats, even if not really reliable :)
This commit is contained in:
Loic d'Anterroches 2008-08-05 15:44:27 +02:00
parent 366b73d27e
commit 5e3b2bac28
5 changed files with 34 additions and 2 deletions

View File

@ -132,6 +132,7 @@ class IDF_Form_UpdateUpload extends Pluf_Form
}
// Create the upload
$this->upload->summary = trim($this->cleaned_data['summary']);
$this->upload->modif_dtime = gmdate('Y-m-d H:i:s');
$this->upload->update();
$this->upload->batchAssoc('IDF_Tag', $tags);
return $this->upload;

View File

@ -137,7 +137,12 @@ class IDF_Upload extends Pluf_Model
{
if ($this->id == '') {
$this->creation_dtime = gmdate('Y-m-d H:i:s');
}
$this->modif_dtime = gmdate('Y-m-d H:i:s');
}
}
function getAbsoluteUrl($project)
{
return Pluf::f('url_media').'/upload/'.$project->shortname.'/files/'.$this->file;
}
}

View File

@ -77,6 +77,9 @@ class IDF_Views_Download
{
$prj = $request->project;
$upload = Pluf_Shortcuts_GetObjectOr404('IDF_Upload', $match[2]);
if ($upload->project != $prj->id) {
throw new Pluf_HTTP_Error404();
}
$title = sprintf(__('Download %s'), $upload->summary);
$form = false;
if ($request->method == 'POST' and
@ -111,6 +114,21 @@ class IDF_Views_Download
$request);
}
/**
* Download a file.
*/
public function download($request, $match)
{
$prj = $request->project;
$upload = Pluf_Shortcuts_GetObjectOr404('IDF_Upload', $match[2]);
if ($upload->project != $prj->id) {
throw new Pluf_HTTP_Error404();
}
$upload->downloads += 1;
$upload->update();
return new Pluf_HTTP_Response_Redirect($upload->getAbsoluteUrl($prj));
}
/**
* Submit a new file for download.
*/

View File

@ -159,6 +159,12 @@ $ctl[] = array('regex' => '#^/p/(\w+)/downloads/(\d+)/$#',
'model' => 'IDF_Views_Download',
'method' => 'view');
$ctl[] = array('regex' => '#^/p/(\w+)/downloads/(\d+)/get/$#',
'base' => $base,
'priority' => 4,
'model' => 'IDF_Views_Download',
'method' => 'download');
$ctl[] = array('regex' => '#^/p/(\w+)/downloads/create/$#',
'base' => $base,
'priority' => 4,

View File

@ -3,7 +3,7 @@
{block body}
<div class="download-file">
<a href="{media}/upload/{$project.shortname}/files/{$file}">{$file}</a> - {$file.filesize|size}
<a href="{url 'IDF_Views_Download::download', array($project.shortname, $file.id)}">{$file}</a> - {$file.filesize|size}
</div>
@ -47,6 +47,8 @@
<p><strong>{trans 'Uploaded:'}</strong> <span class="nobrk">{$file.creation_dtime|dateago}</span> <span class="nobrk">{blocktrans}by {$submitter}{/blocktrans}</span></p>
<p>
<strong>{trans 'Updated:'}</strong> <span class="nobrk">{$file.modif_dtime|dateago}</span></p>
<p>
<strong>{trans 'Downloads:'}</strong> <span class="nobrk">{$file.downloads}</span></p>
{assign $tags = $file.get_tags_list()}{if $tags.count()}
<p>
<strong>{trans 'Labels:'}</strong><br />