function statistics_get
Same name in other branches
- 8.9.x core/modules/statistics/statistics.module \statistics_get()
Retrieves a node's "view statistics".
Parameters
$nid: The node ID.
Return value
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.
4 calls to statistics_get()
- StatisticsLoggingTestCase::testLogging in modules/
statistics/ statistics.test - Verifies request logging for cached and uncached pages.
- StatisticsTokenReplaceTestCase::testStatisticsTokenReplacement in modules/
statistics/ statistics.test - Creates a node, then tests the statistics tokens generated from it.
- statistics_node_view in modules/
statistics/ statistics.module - Implements hook_node_view().
- statistics_tokens in modules/
statistics/ statistics.tokens.inc - Implements hook_tokens().
File
-
modules/
statistics/ statistics.module, line 314
Code
function statistics_get($nid) {
if ($nid > 0) {
// Retrieve an array with both totalcount and daycount.
return db_query('SELECT totalcount, daycount, timestamp FROM {node_counter} WHERE nid = :nid', array(
':nid' => $nid,
), array(
'target' => 'slave',
))->fetchAssoc();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.