You are here

public function ChoiceResponse::formatReport in Quiz 6.6

Implementation of format report.

Parameters

$showpoints:

$showfeedback:

Return value

report as html

File

question_types/choice/choice.classes.inc, line 679
The main classes for the choice question type.

Class

ChoiceResponse
The short answer question response class.

Code

public function formatReport($showpoints = TRUE, $showfeedback = TRUE) {
  $slug = '<div class="quiz_summary_question"><span class="quiz_question_bullet">Q:</span> ' . check_markup($this->question->body, $this->question->filter, FALSE) . '</div>';
  $result = '<div class="quiz_answer_feedback">';
  $result .= '<H4>' . t('Alternatives') . ':</H4>';
  $i = 0;
  $this
    ->orderAlternatives($this->question->alternatives);
  while (is_array($this->question->alternatives[$i])) {
    $short = $this->question->alternatives[$i];
    if (drupal_strlen(strip_tags($short['answer'])) > 0) {
      $row = array();
      $the = $this->question->choice_multi == 1 ? t('a') : t('the');
      $p = drupal_get_path('module', 'choice');
      $rowspan = 1;
      $not = '';
      if ($short['score_if_chosen'] > $short['score_if_not_chosen']) {
        if (in_array($short['id'], $this->user_answer_ids)) {
          if (drupal_strlen(strip_tags($short['feedback_if_chosen'])) > 0) {
            $rowspan = 2;
          }
          $row[] = array(
            'data' => theme_image("{$p}./theme/images/correct.png", t('Correct'), t('You chose !the correct answer', array(
              '!the' => $the,
            )), NULL, FALSE),
            'width' => 35,
            'rowspan' => $rowspan,
          );
        }
        else {
          if (drupal_strlen(strip_tags($short['feedback_if_not_chosen'])) > 0) {
            $rowspan = 2;
            $not = '_not';
          }
          $row[] = array(
            'data' => theme_image("{$p}./theme/images/should.png", t('Should have chosen'), t('This is !the correct answer, but you didn\'t choose it', array(
              '!the' => $the,
            )), NULL, FALSE),
            'width' => 35,
            'rowspan' => $rowspan,
          );
        }
      }
      else {
        if (in_array($short['id'], $this->user_answer_ids)) {
          if (drupal_strlen(strip_tags($short['feedback_if_chosen'])) > 0) {
            $rowspan = 2;
          }
          $row[] = array(
            'data' => theme_image("{$p}./theme/images/wrong.png", t('Wrong'), t('You chose !the wrong answer', array(
              '!the' => $the,
            )), NULL, FALSE),
            'width' => 35,
            'rowspan' => $rowspan,
          );
        }
        else {
          if (drupal_strlen(strip_tags($short['feedback_if_not_chosen'])) > 0) {
            $rowspan = 2;
            $not = '_not';
          }
          $row[] = array(
            'data' => '',
            'width' => 35,
            'rowspan' => $rowspan,
          );
        }
      }
      $row[] = check_markup($short['answer'], $short['answer_format'], FALSE);
      $rows[] = $row;
      if ($rowspan > 1) {
        $feedback = check_markup($short['feedback_if' . $not . '_chosen'], $short['feedback_if' . $not . '_chosen_format'], FALSE);
        $rows[] = array(
          "<H5>Feedback:</H5>{$feedback}",
        );
      }
    }
    $i++;
  }
  $result .= theme('table', NULL, $rows);
  $result .= '</div>';
  return $slug . $result;
}