You are here

function file_download_counter_title_list in File Download 8

Returns the most viewed content of all time, today, or the last-viewed node.

Parameters

string $dbfield: The database field to use, one of:

  • 'totalcount': Integer that shows the top viewed content of all time.
  • 'daycount': Integer that shows the top viewed content for today.
  • 'timestamp': Integer that shows only the last viewed node.

int $dbrows: The number of rows to be returned.

Return value

SelectQuery|false A query result containing the node ID, title, user ID that owns the node, and the username for the selected node(s), or FALSE if the query could not be executed correctly.

1 call to file_download_counter_title_list()
FileDownloadPopularBlock::build in modules/file_download_counter/src/Plugin/Block/FileDownloadPopularBlock.php
Builds and returns the renderable array for this block plugin.

File

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

Code

function file_download_counter_title_list($dbfield, $dbrows) {
  if (in_array($dbfield, [
    'totalcount',
    'daycount',
    'timestamp',
  ])) {
    $query = \Drupal::database()
      ->select('file_managed', 'f');
    $query
      ->join('file_usage', 'us', 'us.fid = f.fid');
    $query
      ->join('file_download_counter', 'c', 'f.fid = c.fid');
    $query
      ->join('node_field_revision', 'nr', 'us.id = nr.nid');
    $query
      ->join('users_field_data', 'u', 'nr.uid = u.uid');
    $query
      ->addField('nr', 'nid', 'nid');
    $query
      ->addField('nr', 'title', 'title');
    $query
      ->addField('u', 'uid', 'uid');
    $query
      ->addField('u', 'name', 'name');
    $query
      ->condition($dbfield, 0, '<>');
    $query
      ->condition('nr.status', 1);
    $query
      ->condition('nr.default_langcode', 1);
    return $query
      ->condition('u.default_langcode', 1)
      ->orderBy($dbfield, 'DESC')
      ->range(0, $dbrows)
      ->execute();
  }
  return FALSE;
}