You are here

function _quiz_cleanup_after_jumping in Quiz 6.4

Same name and namespace in other branches
  1. 8.4 quiz.module \_quiz_cleanup_after_jumping()
  2. 7 quiz.module \_quiz_cleanup_after_jumping()
  3. 7.4 quiz.module \_quiz_cleanup_after_jumping()

Clean up result data when the user jumps forward in a quiz

When jumping in a quiz we might be skipping lots of questions. We need to update the result data according to this...

Parameters

object $quiz: The quiz node we want to clean up results for

int $rid: Result id for the result we want to clean up

1 call to _quiz_cleanup_after_jumping()
quiz_jump_to in ./quiz.module
Set the current session to jump to a specific question number

File

./quiz.module, line 3534
Quiz Module

Code

function _quiz_cleanup_after_jumping($quiz, $rid) {
  $sql = "INSERT IGNORE INTO {quiz_node_results_answers}\n          (result_id, question_nid, question_vid, is_skipped, answer_timestamp, number";
  if ($quiz->randomization == 3) {
    $sql .= ', tid';
  }
  $sql .= ') VALUES ';
  $args = array();
  $first = TRUE;
  $time = time();
  foreach ($_SESSION['quiz_' . $quiz->nid]['previous_quiz_questions'] as $previous_question) {
    if (!$first) {
      $sql .= ', ';
    }
    $sql .= '(%d, %d, %d, 1, ' . $time . ', %d';
    array_push($args, $rid, $previous_question['nid'], $previous_question['vid'], $previous_question['number']);
    if ($quiz->randomization == 3) {
      $sql .= ', %d';
      $args[] = $previous_question['tid'];
    }
    $sql .= ')';
    $first = FALSE;
  }
  db_query($sql, $args);
}