You are here

public function RecentlyReadService::getRecords in Recently Read 8

Get all records in DB for specified user/anonymous.

Parameters

int $user_id: User id.

Return value

array|int Returns an array of record id's.

Overrides RecentlyReadServiceInterface::getRecords

1 call to RecentlyReadService::getRecords()
RecentlyReadService::insertEntity in src/RecentlyReadService.php
Custom function to insert or update an entry for recently read.

File

src/RecentlyReadService.php, line 155

Class

RecentlyReadService
Recently read service.

Namespace

Drupal\recently_read

Code

public function getRecords($user_id) {
  if ($user_id != 0) {
    $records = $this->recentlyReadStorage
      ->getQuery()
      ->condition('user_id', $user_id)
      ->sort('created', 'DESC')
      ->execute();
  }
  else {
    $records = $this->recentlyReadStorage
      ->getQuery()
      ->condition('session_id', session_id())
      ->sort('created', 'DESC')
      ->execute();
  }
  return $records;
}