function quiz_quiz_scored in Quiz 7.6
Same name and namespace in other branches
- 6.4 quiz.module \quiz_quiz_scored()
- 7 quiz.module \quiz_quiz_scored()
- 7.4 quiz.module \quiz_quiz_scored()
Implements hook_quiz_scored().
Performs actions like sending quiz results over email at the end of quiz.
Related topics
File
- ./
quiz.module, line 2084 - quiz.module Main file for the Quiz module.
Code
function quiz_quiz_scored($quiz, $score, $result_id) {
// @TODO Rules
$taker = db_query('SELECT u.uid, u.mail FROM {users} u JOIN {quiz_node_results} qnr ON u.uid = qnr.uid WHERE result_id = :rid', array(
':rid' => $result_id,
))
->fetch();
if (variable_get('quiz_email_results', 0) && $taker->uid != 0 && $score['is_evaluated']) {
drupal_mail('quiz', 'notice', $taker->mail, NULL, array(
$quiz,
$score,
$result_id,
'taker',
));
drupal_set_message(t("The results has been sent to the user's email 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_query("SELECT ti.tid\n FROM {taxonomy_index} ti\n JOIN {taxonomy_term_data} td\n ON td.tid = ti.tid AND td.vid = :vid\n WHERE ti.nid = :nid", array(
':nid' => $quiz->nid,
':vid' => userpoints_get_vid(),
))
->fetchField();
$variables = array(
'@title' => $quiz->title,
'@quiz' => 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,
);
if ($quiz->userpoints_tid != 0) {
$params['tid'] = $quiz->userpoints_tid;
}
userpoints_userpointsapi($params);
}
}