You are here

function Quiz::isPassed in Quiz 6.x

Check if a user passed this Quiz.

Parameters

AccountInterface $account: The user to check.

Return value

bool Returns TRUE if the user has passed the quiz at least once, and FALSE otherwise. Note that a FALSE may simply indicate that the user has not taken the quiz.

File

src/Entity/Quiz.php, line 866

Class

Quiz
Defines the Quiz entity class.

Namespace

Drupal\quiz\Entity

Code

function isPassed(AccountInterface $account) {

  // @todo convert to select()
  $passed = Drupal::database()
    ->query('SELECT COUNT(result_id) AS passed_count
    FROM {quiz_result} qnrs
    INNER JOIN {quiz} USING (vid, qid)
    WHERE qnrs.vid = :vid
    AND qnrs.qid = :qid
    AND qnrs.uid = :uid
    AND score >= pass_rate', [
    ':vid' => $this
      ->getRevisionId(),
    ':qid' => $this
      ->id(),
    ':uid' => $account
      ->id(),
  ])
    ->fetchField();
  return $passed > 0;
}