You are here

public function NodeStatisticsDatabaseStorage::fetchAll in Drupal 8

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

Returns the number of times a entity has been viewed.

Parameters

string $order: The counter name to order by:

  • 'totalcount' The total number of views.
  • 'daycount' The number of views today.
  • 'timestamp' The unix timestamp of the last view.

int $limit: The number of entity IDs to return.

Return value

array An ordered array of entity IDs.

Overrides StatisticsStorageInterface::fetchAll

File

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

Class

NodeStatisticsDatabaseStorage
Provides the default database storage backend for statistics.

Namespace

Drupal\statistics

Code

public function fetchAll($order = 'totalcount', $limit = 5) {
  assert(in_array($order, [
    'totalcount',
    'daycount',
    'timestamp',
  ]), "Invalid order argument.");
  return $this->connection
    ->select('node_counter', 'nc')
    ->fields('nc', [
    'nid',
  ])
    ->orderBy($order, 'DESC')
    ->range(0, $limit)
    ->execute()
    ->fetchCol();
}