You are here

function statistics_get in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/statistics/statistics.module \statistics_get()

Retrieves a node's "view statistics".

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.
5 calls to statistics_get()
IntegrationTest::testNodeCounterIntegration in core/modules/statistics/src/Tests/Views/IntegrationTest.php
Tests the integration of the {node_counter} table in views.
StatisticsLoggingTest::testLogging in core/modules/statistics/src/Tests/StatisticsLoggingTest.php
Verifies node hit counter logging and script placement.
StatisticsTokenReplaceTest::testStatisticsTokenReplacement in core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php
Creates a node, then tests the statistics tokens generated from it.
statistics_node_links_alter in core/modules/statistics/statistics.module
Implements hook_node_links_alter().
statistics_tokens in core/modules/statistics/statistics.tokens.inc
Implements hook_tokens().

File

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

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' => 'replica',
    ))
      ->fetchAssoc();
  }
}