You are here

function file_download_counter_get in File Download 8

Retrieves a node's "view file_download_counter".

Parameters

int $nid: The node ID.

Return value

array An associative array containing:

  • totalcount: Integer for the total number of times the node has been viewed.
  • daycount: Integer for the total number of times the node has been viewed "today". For the daycount to be reset, cron must be enabled.
  • timestamp: Integer for the timestamp of when the node was last viewed.
1 call to file_download_counter_get()
file_download_counter_tokens in modules/file_download_counter/file_download_counter.tokens.inc
Implements hook_tokens().

File

modules/file_download_counter/file_download_counter.module, line 95
Logs and displays content file_download_counter for a site.

Code

function file_download_counter_get($fid) {
  if ($fid > 0) {

    // Retrieve an array with both totalcount and daycount.
    return \Drupal\core\Database\Database::getConnection('replica')
      ->query('SELECT totalcount, daycount, timestamp FROM {file_download_counter} WHERE fid = :fid', [
      ':fid' => $fid,
    ], [])
      ->fetchAssoc();
  }
}