function quiz_user_results in Quiz 8.4
Same name and namespace in other branches
- 8.6 quiz.pages.inc \quiz_user_results()
- 8.5 quiz.pages.inc \quiz_user_results()
- 5.2 quiz.module \quiz_user_results()
- 5 quiz.module \quiz_user_results()
- 6.6 quiz.pages.inc \quiz_user_results()
- 6.2 quiz.pages.inc \quiz_user_results()
- 6.3 quiz.pages.inc \quiz_user_results()
- 6.4 quiz.pages.inc \quiz_user_results()
- 6.5 quiz.pages.inc \quiz_user_results()
- 7.6 quiz.pages.inc \quiz_user_results()
- 7 quiz.pages.inc \quiz_user_results()
- 7.4 quiz.pages.inc \quiz_user_results()
- 7.5 quiz.pages.inc \quiz_user_results()
Show result page for a given result id
Parameters
$result_id: Result id
2 calls to quiz_user_results()
- QuizController::quizMyResultsPage in lib/
Drupal/ quiz/ Controller/ QuizController.php - QuizController::quizUserResults in lib/
Drupal/ quiz/ Controller/ QuizController.php
File
- ./
quiz.pages.inc, line 568 - Page callback file for the quiz module.
Code
function quiz_user_results($result_id) {
$user = \Drupal::currentUser();
$result = db_query('SELECT qnp.nid, qnp.vid, qnrs.uid
FROM {quiz_node_properties} qnp
INNER JOIN {quiz_node_results} qnrs ON qnrs.vid = qnp.vid
WHERE qnrs.result_id = :rid', array(
':rid' => $result_id,
))
->fetch();
if ($result->nid) {
// User can view own results (quiz_menu sets access to 'own results').
// User with role 'user results' can view other user's results.
if ($result->uid != $user
->id() && !$user
->hasPermission('view any quiz results')) {
drupal_access_denied();
return;
}
$quiz = node_load($result->nid, $result->vid);
$questions = _quiz_get_answers($quiz, $result_id);
$score = quiz_calculate_score($quiz, $result_id);
$summary = _quiz_get_summary_text($quiz, $score);
$data = array(
'quiz' => $quiz,
'questions' => $questions,
'score' => $score,
'summary' => $summary,
'rid' => $result_id,
);
return theme('quiz_user_summary', $data);
}
else {
throw new NotFoundHttpException();
}
}