You are here

function quiz_is_passed in Quiz 8.6

Same name and namespace in other branches
  1. 8.4 quiz.module \quiz_is_passed()
  2. 8.5 quiz.module \quiz_is_passed()
  3. 6.6 quiz.module \quiz_is_passed()
  4. 6.2 quiz.module \quiz_is_passed()
  5. 6.3 quiz.module \quiz_is_passed()
  6. 6.4 quiz.module \quiz_is_passed()
  7. 6.5 quiz.module \quiz_is_passed()
  8. 7.6 quiz.module \quiz_is_passed()
  9. 7 quiz.module \quiz_is_passed()
  10. 7.4 quiz.module \quiz_is_passed()
  11. 7.5 quiz.module \quiz_is_passed()

Check a user/quiz combo to see if the user passed the given quiz.

Parameters

int $uid: The user ID.

int $nid: The node ID.

int $vid: The version ID.

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.

Related topics

1 call to quiz_is_passed()
quiz_quiz_access in ./quiz.module
Implements hook_quiz_access().

File

./quiz.module, line 425
Contains quiz.module

Code

function quiz_is_passed($uid, $nid, $vid) {
  $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', array(
    ':vid' => $vid,
    ':qid' => $nid,
    ':uid' => $uid,
  ))
    ->fetchField();

  // Force into boolean context.
  return $passed !== FALSE && $passed > 0;
}