You are here

function quiz_end_actions in Quiz 6.6

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

Actions to take at the end of a quiz.

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

File

./quiz.module, line 1308
Quiz Module

Code

function quiz_end_actions($quiz, $rid) {
  global $user;
  $score = quiz_calculate_score($quiz, $rid);
  if (!isset($score['percentage_score'])) {
    $score['percentage_score'] = 0;
  }

  // Why is this using the $_SESSION's RID?
  db_query("UPDATE {quiz_node_results} SET time_end = %d, score = %d WHERE result_id = %d", time(), $score['percentage_score'], $_SESSION['quiz_' . $quiz->nid]['result_id']);
  $score['passing'] = quiz_is_passed($user->uid, $quiz->nid, $quiz->vid);

  // Lets piggy back here to perform the quiz defined action since were done with this quiz.
  // We will verify that there is an associated action with this quiz and then perform that action.
  if (!empty($quiz->aid)) {

    /*
     * Some actions are reliant on objects and I am unsure which ones, for now I have simply
     * passed the actions_do() function an empty array.  By passing this function a single id
     * then it will retrieve the callback, get the parameters and perform that function (action)
     * for you.
     * @TODO: Add ability to assign multiple actions and pass the actions_do() an array of aid's
     * @TODO: Create feature to only fire action if certain score is reached.
     */
    $context = array(
      'result_id' => $rid,
      'score' => $score,
    );
    actions_do($quiz->aid, $quiz, $context, $score);
  }

  // Call hook_quiz_finished().
  module_invoke_all('quiz_finished', $quiz, $score, $rid);
  return $score;
}