You are here

function _quiz_active_result_id in Quiz 7.4

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.5 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.

1 call to _quiz_active_result_id()
quiz_take_quiz in ./quiz.module
Handles quiz taking.

File

./quiz.module, line 3389
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.
  $rid = 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.vid = :vid
          AND qnr.uid = :uid
          AND qnr.time_end = :time_end', array(
    ':quiz_always' => 1,
    ':between' => $now,
    ':vid' => $vid,
    ':uid' => $uid,
    ':time_end' => 0,
  ))
    ->fetchField();
  return (int) $rid;
}