You are here

function theme_short_answer_report in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 question_types/short_answer/short_answer.theme.inc \theme_short_answer_report()
  2. 6.3 question_types/short_answer/short_answer.theme.inc \theme_short_answer_report()

Implementation of theme_$type_report(). Theme the feedback report for a quiz. This report is generated (typically) at the end of the quiz.

File

question_types/short_answer/short_answer.theme.inc, line 12
Theme functions for short_answer.

Code

function theme_short_answer_report($question, $show_points, $show_feedback) {
  if (is_array($question)) {

    // Cast this if it is an assoc array.
    $question = (object) $question;
  }
  $slug = '<div class="quiz_summary_question"><span class="quiz_question_bullet">Q:</span> ' . check_markup($question->body, $question->format) . '</div>';
  $result = '<div class="quiz_answer_feedback">';
  if ($question && !empty($question->answers)) {
    $answer = (object) current($question->answers);
    if ($answer->is_evaluated == 1) {

      // Show score:
      if ($show_points) {
        $args = array(
          '@yours' => $answer->score,
          '@total' => $question->maximum_score,
        );
        $result .= t('Score: @yours of @total possible points', $args);
      }

      // Show feedback, if any.
      if ($show_feedback && !empty($answer->feedback)) {
        $result .= '</div><div class="quiz_answer_feedback">' . check_markup($answer->feedback, $question->format);
      }
    }
    else {
      $result .= t('This answer has not yet been scored.') . '<br/>' . t('Until the answer is scored, the total score will not be correct.');

      // Add scoring link for admins.
      if (user_access('score short answer')) {
        $path = sprintf('admin/quiz/score-short-answer/%s/%s', $question->vid, $answer->result_id);
        $result .= '<p>' . l(t('Score this answer'), $path) . '</p>';
      }
    }
  }
  else {
    $result .= t('This question was not answered.');
  }
  $result .= '</div>';
  return $slug . $result;
}