public function onBeforeSendFile($file)
 {
     // check to make sure this is the actual file and not just a rendition... if that matters?
     $downloadRecord = new FileDownloadRecord();
     // store the full filename for now
     $url = array_key_exists('url', $_GET) ? $_GET['url'] : $_SERVER['REQUEST_URI'];
     // check if it's a resampled file
     if (strpos($url, '_resampled') !== false) {
         // ignore it
         return;
     }
     $file_path = Director::makeRelative($url);
     $downloadRecord->Filename = $file_path ? $file_path : $file->getFilename();
     $downloadRecord->FileID = $file->ID;
     $downloadRecord->write();
 }
 public function updateCMSFields(FieldList $fields)
 {
     if (!$this->owner instanceof Folder) {
         $showfields = array('Filename' => 'Filename', 'Created' => 'At time', 'Downloader' => 'Downloader');
         $records = FileDownloadRecord::get()->filter(array('FileID' => $this->owner->ID));
         $config = GridFieldConfig_RecordViewer::create();
         $colums = $config->getComponentByType('GridFieldDataColumns')->setDisplayFields($showfields);
         $grid = GridField::create('Downloads', 'Recorded downloads', $records, $config);
         $total = $records->count();
         $tf = TextField::create('DownloadTotal', _t('DownloadTrackable.TOTAL', 'Total'), $total);
         $tf = $tf->performReadonlyTransformation();
         $fields->addFieldToTab('Root.' . _t('DownloadTrackable.DOWNLOADTRACKINGTAB', 'Downloads'), $tf);
         $fields->addFieldToTab('Root.' . _t('DownloadTrackable.DOWNLOADTRACKINGTAB', 'Downloads'), $grid);
     }
 }
 /**
  * Return the records that provides your report data.
  */
 public function sourceRecords($params = null)
 {
     return FileDownloadRecord::get()->sort('Created', 'DESC');
 }