You are here

public function NodeStatisticsDatabaseStorage::fetchViews in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/statistics/src/NodeStatisticsDatabaseStorage.php \Drupal\statistics\NodeStatisticsDatabaseStorage::fetchViews()

Returns the number of times entities have been viewed.

Parameters

array $ids: An array of IDs of entities to fetch the views for.

Return value

\Drupal\statistics\StatisticsViewsResult[] An array of value objects representing the number of times each entity has been viewed. The array is keyed by entity ID. If an ID does not exist, it will not be present in the array.

Overrides StatisticsStorageInterface::fetchViews

1 call to NodeStatisticsDatabaseStorage::fetchViews()
NodeStatisticsDatabaseStorage::fetchView in core/modules/statistics/src/NodeStatisticsDatabaseStorage.php
Returns the number of times a single entity has been viewed.

File

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

Class

NodeStatisticsDatabaseStorage
Provides the default database storage backend for statistics.

Namespace

Drupal\statistics

Code

public function fetchViews($ids) {
  $views = $this->connection
    ->select('node_counter', 'nc')
    ->fields('nc', [
    'totalcount',
    'daycount',
    'timestamp',
  ])
    ->condition('nid', $ids, 'IN')
    ->execute()
    ->fetchAll();
  foreach ($views as $id => $view) {
    $views[$id] = new StatisticsViewsResult($view->totalcount, $view->daycount, $view->timestamp);
  }
  return $views;
}