mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
FEATURE: track DMSDocument downloaded Count by its Field 'ViewCount' (we keep same name as Page for this field, for lots of benefits, such as using the same field for indexing in solar, sphinx etc).
This commit is contained in:
parent
d8d3be0fa1
commit
aa9e0f8bba
@ -5,6 +5,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
|||||||
"Folder" => "Varchar(255)", // eg. 0
|
"Folder" => "Varchar(255)", // eg. 0
|
||||||
"Title" => 'Varchar(1024)', // eg. "Energy Saving Report for Year 2011, New Zealand LandCorp"
|
"Title" => 'Varchar(1024)', // eg. "Energy Saving Report for Year 2011, New Zealand LandCorp"
|
||||||
"Description" => 'Text',
|
"Description" => 'Text',
|
||||||
|
"ViewCount" => 'Int',
|
||||||
"LastChanged" => 'SS_DateTime', //when this document's file was created or last replaced (small changes like updating title don't count)
|
"LastChanged" => 'SS_DateTime', //when this document's file was created or last replaced (small changes like updating title don't count)
|
||||||
|
|
||||||
"EmbargoedIndefinitely" => 'Boolean(false)',
|
"EmbargoedIndefinitely" => 'Boolean(false)',
|
||||||
@ -82,6 +83,16 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
|||||||
$this->Pages()->removeAll();
|
$this->Pages()->removeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* increase ViewCount by 1, without update any other record fields such as LastEdited
|
||||||
|
*/
|
||||||
|
function viewd(){
|
||||||
|
if ($this->ID > 0) {
|
||||||
|
$count = $this->ViewCount + 1;
|
||||||
|
DB::query("UPDATE \"DMSDocument\" SET \"ViewCount\"='$count' WHERE \"ID\"={$this->ID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a metadata tag to the Document. The tag has a category and a value.
|
* Adds a metadata tag to the Document. The tag has a category and a value.
|
||||||
@ -785,6 +796,10 @@ class DMSDocument_Controller extends Controller {
|
|||||||
|
|
||||||
if (self::$testMode) return $path;
|
if (self::$testMode) return $path;
|
||||||
|
|
||||||
|
//if a DMSDocument can be downlaoded and all the permissions/privileges has passed,
|
||||||
|
//its ViewCount should be increased by 1 just before the browser sending the file to front.
|
||||||
|
$doc->viewd();
|
||||||
|
|
||||||
header('Content-Type: ' . $mime);
|
header('Content-Type: ' . $mime);
|
||||||
header('Content-Length: ' . filesize($path), null);
|
header('Content-Length: ' . filesize($path), null);
|
||||||
if (!empty($mime) && $mime != "text/html") header('Content-Disposition: attachment; filename="'.$doc->getFilenameWithoutID().'"');
|
if (!empty($mime) && $mime != "text/html") header('Content-Disposition: attachment; filename="'.$doc->getFilenameWithoutID().'"');
|
||||||
|
Loading…
Reference in New Issue
Block a user