class NodeStatisticsDatabaseStorage implements StatisticsStorageInterface (View source)

Provides the default database storage backend for statistics.

Properties

protected Connection $connection

The database connection used.

protected StateInterface $state

The state service.

protected RequestStack $requestStack

The request stack.

Methods

__construct(Connection $connection, StateInterface $state, RequestStack $request_stack)

Constructs the statistics storage.

bool
recordView(int $id)

Counts an entity view.

fetchViews(array $ids)

Returns the number of times entities have been viewed.

fetchView(int $id)

Returns the number of times a single entity has been viewed.

array
fetchAll(string $order = 'totalcount', int $limit = 5)

Returns the number of times an entity has been viewed.

bool
deleteViews(int $id)

Delete counts for a specific entity.

resetDayCount()

Reset the day counter for all entities once every day.

int
maxTotalCount()

Returns the highest 'totalcount' value.

int
getRequestTime()

Get current request time.

Details

__construct(Connection $connection, StateInterface $state, RequestStack $request_stack)

Constructs the statistics storage.

Parameters

Connection $connection

The database connection for the node view storage.

StateInterface $state

The state service.

RequestStack $request_stack

The request stack.

bool recordView(int $id)

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.

StatisticsViewsResult[] fetchViews(array $ids)

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

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.

StatisticsViewsResult|false fetchView(int $id)

Returns the number of times a single entity has been viewed.

Parameters

int $id

The ID of the entity to fetch the views for.

Return Value

StatisticsViewsResult|false

If the entity exists, a value object representing the number of times if has been viewed. If it does not exist, FALSE is returned.

array fetchAll(string $order = 'totalcount', int $limit = 5)

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.

bool deleteViews(int $id)

Delete counts for a specific entity.

Parameters

int $id

The ID of the entity which views to delete.

Return Value

bool

TRUE if the entity views have been deleted.

resetDayCount()

Reset the day counter for all entities once every day.

int maxTotalCount()

Returns the highest 'totalcount' value.

Return Value

int

The highest 'totalcount' value.

protected int getRequestTime()

Get current request time.

Return Value

int

Unix timestamp for current server request time.