You are here

function _quiz_active_result_id in Quiz 7.5

Same name and namespace in other branches
  1. 8.4 quiz.module \_quiz_active_result_id()
  2. 6.6 quiz.module \_quiz_active_result_id()
  3. 6.3 quiz.module \_quiz_active_result_id()
  4. 6.4 quiz.module \_quiz_active_result_id()
  5. 6.5 quiz.module \_quiz_active_result_id()
  6. 7.6 quiz.module \_quiz_active_result_id()
  7. 7 quiz.module \_quiz_active_result_id()
  8. 7.4 quiz.module \_quiz_active_result_id()

Returns the result ID for any current result set for the given quiz.

Parameters

$uid: User ID

$nid: Quiz node ID

$vid: Quiz node version ID

$now: Timestamp used to check whether the quiz is still open. Default: current time.

Return value

If a quiz is still open and the user has not finished the quiz, return the result set ID so that the user can continue. If no quiz is in progress, this will return 0.

5 calls to _quiz_active_result_id()
QuizGradingTestCase::testManualWeightedScore in tests/QuizGradingTestCase.test
Test question weights.
QuizGradingTestCase::testWeightedScore in tests/QuizGradingTestCase.test
Test question weights.
QuizResultTestCase::testFieldableResults in tests/QuizResultTestCase.test
Test fieldable Quiz results.
quiz_quiz_access in ./quiz.module
Can a user take this quiz?
quiz_take_quiz in ./quiz.module
Find a resumable result for this quiz and the current user.

File

./quiz.module, line 2622
quiz.module Main file for the Quiz module.

Code

function _quiz_active_result_id($uid, $nid, $vid, $now = NULL) {
  if (!isset($now)) {
    $now = REQUEST_TIME;
  }

  // Get any quiz that is open, for this user, and has not already
  // been completed.
  $result_id = db_query('SELECT result_id FROM {quiz_node_results} qnr
          INNER JOIN {quiz_node_properties} qnp ON qnr.vid = qnp.vid
          WHERE (qnp.quiz_always = :quiz_always OR (:between BETWEEN qnp.quiz_open AND qnp.quiz_close))
          AND qnr.nid = :nid
          AND qnr.uid = :uid
          AND qnr.time_end IS NULL', array(
    ':quiz_always' => 1,
    ':between' => $now,
    ':nid' => $nid,
    ':uid' => $uid,
  ))
    ->fetchField();
  return (int) $result_id;
}