You are here

function statistics_title_list in Drupal 8

Same name and namespace in other branches
  1. 4 modules/statistics.module \statistics_title_list()
  2. 5 modules/statistics/statistics.module \statistics_title_list()
  3. 6 modules/statistics/statistics.module \statistics_title_list()
  4. 7 modules/statistics/statistics.module \statistics_title_list()

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.

Deprecated

in drupal:8.6.0 and is removed from drupal:9.0.0. Use \Drupal\statistics\NodeStatisticsDatabaseStorage::fetchAll() instead.

File

core/modules/statistics/statistics.module, line 99
Logs and displays content statistics for a site.

Code

function statistics_title_list($dbfield, $dbrows) {
  @trigger_error('statistics_title_list() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use \\Drupal\\statistics\\NodeStatisticsDatabaseStorage::fetchAll() instead.', E_USER_DEPRECATED);
  if (in_array($dbfield, [
    'totalcount',
    'daycount',
    'timestamp',
  ])) {
    $query = \Drupal::database()
      ->select('node_field_data', 'n');
    $query
      ->addTag('node_access');
    $query
      ->join('node_counter', 's', 'n.nid = s.nid');
    $query
      ->join('users_field_data', 'u', 'n.uid = u.uid');
    return $query
      ->fields('n', [
      'nid',
      'title',
    ])
      ->fields('u', [
      'uid',
      'name',
    ])
      ->condition($dbfield, 0, '<>')
      ->condition('n.status', 1)
      ->condition('n.default_langcode', 1)
      ->condition('u.default_langcode', 1)
      ->orderBy($dbfield, 'DESC')
      ->range(0, $dbrows)
      ->execute();
  }
  return FALSE;
}