function statistics_title_list

Same name in other branches
  1. 8.9.x core/modules/statistics/statistics.module \statistics_title_list()

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

Parameters

$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.

$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 statistics_title_list()
statistics_block_view in modules/statistics/statistics.module
Implements hook_block_view().

File

modules/statistics/statistics.module, line 280

Code

function statistics_title_list($dbfield, $dbrows) {
    if (in_array($dbfield, array(
        'totalcount',
        'daycount',
        'timestamp',
    ))) {
        $query = db_select('node', 'n');
        $query->addTag('node_access');
        $query->join('node_counter', 's', 'n.nid = s.nid');
        $query->join('users', 'u', 'n.uid = u.uid');
        return $query->fields('n', array(
            'nid',
            'title',
        ))
            ->fields('u', array(
            'uid',
            'name',
        ))
            ->condition($dbfield, 0, '<>')
            ->condition('n.status', 1)
            ->orderBy($dbfield, 'DESC')
            ->range(0, $dbrows)
            ->execute();
    }
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.