You are here

function Quiz::getResumeableResult in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 src/Entity/Quiz.php \Drupal\quiz\Entity\Quiz::getResumeableResult()
  2. 8.5 src/Entity/Quiz.php \Drupal\quiz\Entity\Quiz::getResumeableResult()

Find a resumable Quiz attempt in progress.

Parameters

AccountInterface $user: A user.

Return value

Drupal\quiz\Entity\QuizResult The Quiz result to resume, or NULL if one is not found.

File

src/Entity/Quiz.php, line 465

Class

Quiz
Defines the Quiz entity class.

Namespace

Drupal\quiz\Entity

Code

function getResumeableResult(AccountInterface $user) {
  $query = Drupal::entityQuery('quiz_result')
    ->condition('qid', $this
    ->get('qid')
    ->getString())
    ->condition('uid', $user
    ->id())
    ->condition('time_end', NULL, 'IS NULL')
    ->sort('time_start', 'DESC')
    ->range(0, 1);
  if ($result = $query
    ->execute()) {
    return QuizResult::load(key($result));
  }
  return NULL;
}