From aa9e0f8bba61277d07df2aa894d68b8d609381cc Mon Sep 17 00:00:00 2001 From: Normann Lou Date: Thu, 30 Aug 2012 11:12:45 +1200 Subject: [PATCH] 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). --- code/DMSDocument.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/code/DMSDocument.php b/code/DMSDocument.php index fc89d8e..e2013a6 100644 --- a/code/DMSDocument.php +++ b/code/DMSDocument.php @@ -5,6 +5,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { "Folder" => "Varchar(255)", // eg. 0 "Title" => 'Varchar(1024)', // eg. "Energy Saving Report for Year 2011, New Zealand LandCorp" "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) "EmbargoedIndefinitely" => 'Boolean(false)', @@ -82,6 +83,16 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { $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. @@ -785,6 +796,10 @@ class DMSDocument_Controller extends Controller { 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-Length: ' . filesize($path), null); if (!empty($mime) && $mime != "text/html") header('Content-Disposition: attachment; filename="'.$doc->getFilenameWithoutID().'"');