You are here

function quiz_quiz_finished in Quiz 6.6

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

File

./quiz.module, line 1348
Quiz Module

Code

function quiz_quiz_finished($quiz, $score, $rid) {
  global $user;

  //function to send results over e-mail

  /*
   * For personality kind of quizzes
   * if the user is an anonymous and configured to send user result to author
   * send mail to author's e-mail id
   */
  if ($user->uid == 0 && variable_get('quiz_results_to_quiz_author', 1)) {
    $author = user_load($quiz->uid);
    drupal_mail('quiz', 'notice', $author->mail, NULL, array(
      $quiz,
      $score,
      $rid,
    ));
  }

  /*
   * For e-Learning kind of quizzes
   * if quiz has pass/fail, configured to send results to attendee and attendee is
   * NOT an anonymous send result to his/her e-mail ID.
   */
  if (variable_get('quiz_email_results', 1) && variable_get('quiz_use_passfail', 1) && $user->uid != 0) {
    drupal_mail('quiz', 'notice', $user->mail, NULL, array(
      $quiz,
      $score,
      $rid,
    ));
    drupal_set_message(t('Results has been sent to your e-mail ID.'));
  }

  //calls userpoints functions to credit user point based on number of correct answers

  //print_r($quiz);exit;
  if ($quiz->has_userpoints) {
    $variables = array(
      '@title' => $quiz->title,
      '@quiz' => variable_get('quiz_name', QUIZ_NAME),
      '@time' => date('l jS \\of F Y h:i:s A'),
    );
    $params = array(
      'points' => $score['numeric_score'],
      'description' => t('Attened @title @quiz on @time', $variables),
    );
    userpoints_userpointsapi($params);
  }
}