You are here

function quiz_clone_quiz_result in Quiz 7.5

Same name and namespace in other branches
  1. 7.6 quiz.module \quiz_clone_quiz_result()

Clone a result, and its correct answers. Do not finish.

1 call to quiz_clone_quiz_result()
QuizResultController::save in includes/QuizResultController.class.inc
Save the Quiz result and do any post-processing to the result.

File

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

Code

function quiz_clone_quiz_result($result_old, $result_new) {

  // Re-take all the questions.
  foreach ($result_old
    ->getLayout() as $qinfo) {
    $question = node_load($qinfo['nid'], $qinfo['vid']);
    $quiz_question_response = _quiz_question_response_get_instance($result_old->result_id, $question);
    $quiz_question_response_new = _quiz_question_response_get_instance($result_new->result_id, $question);
    if (($result_new->build_on_last == 'all' || $quiz_question_response
      ->isCorrect()) && !$quiz_question_response->is_skipped) {

      // Load the old quiz_result_answer.
      $qra = entity_load_single('quiz_result_answer', $quiz_question_response->result_answer_id);

      // Override the existing response.
      $quiz_question_response
        ->setResultAnswerId($quiz_question_response_new->result_answer_id);
      $quiz_question_response
        ->save();

      // Set the new quiz_result_answer with points and correctness.
      $qra->result_answer_id = $quiz_question_response_new->result_answer_id;
      $qra->result_id = $result_new->result_id;
      $qra->question_nid = $qinfo['nid'];
      $qra->question_vid = $qinfo['vid'];
      $qra
        ->save();
    }
  }
}