You are here

public function NodeStatisticsDatabaseStorage::fetchAll in Drupal 9

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

Returns the number of times an 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 95

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();
}