I'm building a site for a client with a file download section. I've created a directory under assets/ to upload the files, and then a custom page type (FileViewerPage) that lists the files to logged in Members.
What I'd like to do is have a tab for the file download section in the CMS that shows a log of what time which member is downloading which file.
The way I'm trying to do this is with a FileDownloadLogger:
class FileDownloadLogger extends DataObject
{
static $db = array (
'Filename' => 'Text'
);
static $has_one = array (
'Member' => 'Member'
);
}
To link to the file I append to http://example.com/file-home/download?file=test.pdf
Where test.pdf is in /assets/Client/
Then in my FileViewerPage_Controller I have a download() function:
function download() {
$file = $_SERVER['DOCUMENT_ROOT'].'/assets/Client/'.$this->requestParams['file'];
if (file_exists($file)) {
//make a new log entry
$log = new FileDownloadLogger;
$log->Filename = $this->requestParams['file'];
$log->Member = Member::currentUser();
$log->write();
//set headers, send the file with readfile()
}
}
It's about this point I get stuck... when I look at the database table FileDownloadLogger, MemberID is always 0.
I think what I want from here is to maybe use DataObjectManager or complexfieldtable to show a list of: time, member (name), file.
I couldn't find anything on using a Member in other DataObject classes... is it even "right" to do that?
Any advice on how I should do this would be most appreciated, thanks!