You are here

public function NodeStatisticsDatabaseStorage::recordView in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/statistics/src/NodeStatisticsDatabaseStorage.php \Drupal\statistics\NodeStatisticsDatabaseStorage::recordView()
  2. 10 core/modules/statistics/src/NodeStatisticsDatabaseStorage.php \Drupal\statistics\NodeStatisticsDatabaseStorage::recordView()

Counts an entity view.

Parameters

int $id: The ID of the entity to count.

Return value

bool TRUE if the entity view has been counted.

Overrides StatisticsStorageInterface::recordView

File

core/modules/statistics/src/NodeStatisticsDatabaseStorage.php, line 54

Class

NodeStatisticsDatabaseStorage
Provides the default database storage backend for statistics.

Namespace

Drupal\statistics

Code

public function recordView($id) {
  return (bool) $this->connection
    ->merge('node_counter')
    ->key('nid', $id)
    ->fields([
    'daycount' => 1,
    'totalcount' => 1,
    'timestamp' => $this
      ->getRequestTime(),
  ])
    ->expression('daycount', '[daycount] + 1')
    ->expression('totalcount', '[totalcount] + 1')
    ->execute();
}