You are here

function quiz_quiz_scored in Quiz 6.4

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

Implementation hook_quiz_scored().

Performs actions like sending quiz results over email at the end of quiz.

Related topics

File

./quiz.module, line 2227
Quiz Module

Code

function quiz_quiz_scored($quiz, $score, $rid) {
  $sql = 'SELECT u.uid, u.mail FROM {users} u JOIN {quiz_node_results} qnr ON u.uid = qnr.uid WHERE result_id = %d';
  $taker = db_fetch_object(db_query($sql, $rid));
  if (variable_get('quiz_email_results', 0) && $taker->uid != 0 && $score['is_evaluated']) {
    drupal_mail('quiz', 'notice', $taker->mail, NULL, array(
      $quiz,
      $score,
      $rid,
      'taker',
    ));
    drupal_set_message(t('The results has been sent to the users e-mail address.'));
  }

  // Calls userpoints functions to credit user point based on number of correct
  // answers.
  if ($quiz->has_userpoints && $taker->uid != 0 && $score['is_evaluated']) {

    //Looking up the tid of the selected Userpoint vocabulary
    $selected_tid = db_result(db_query("SELECT tid FROM {term_node}\n                WHERE nid = %d AND vid = %d AND tid IN (\n                  SELECT tid\n                  FROM {term_data}\n                  WHERE vid = %d\n                )", $quiz->nid, $quiz->vid, userpoints_get_vid()));
    $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('Attended @title @quiz on @time', $variables),
      'tid' => $selected_tid,
    );
    userpoints_userpointsapi($params);
  }
}