You are here

function quiz_user_results in Quiz 7

Same name and namespace in other branches
  1. 8.6 quiz.pages.inc \quiz_user_results()
  2. 8.4 quiz.pages.inc \quiz_user_results()
  3. 8.5 quiz.pages.inc \quiz_user_results()
  4. 5.2 quiz.module \quiz_user_results()
  5. 5 quiz.module \quiz_user_results()
  6. 6.6 quiz.pages.inc \quiz_user_results()
  7. 6.2 quiz.pages.inc \quiz_user_results()
  8. 6.3 quiz.pages.inc \quiz_user_results()
  9. 6.4 quiz.pages.inc \quiz_user_results()
  10. 6.5 quiz.pages.inc \quiz_user_results()
  11. 7.6 quiz.pages.inc \quiz_user_results()
  12. 7.4 quiz.pages.inc \quiz_user_results()
  13. 7.5 quiz.pages.inc \quiz_user_results()

Show result page for a given result id

Parameters

$result_id: Result id

1 string reference to 'quiz_user_results'
quiz_menu in ./quiz.module
Implements hook_menu().

File

./quiz.pages.inc, line 14
User pages.

Code

function quiz_user_results($result_id) {
  global $user;
  $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->uid && !user_access('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);
    return theme('quiz_user_summary', array(
      'quiz' => $quiz,
      'questions' => $questions,
      'score' => $score,
      'summary' => $summary,
    ));
  }
  else {
    drupal_not_found();
  }
}