You are here

class TrueFalseResponse in Quiz 6.3

Same name and namespace in other branches
  1. 6.6 question_types/truefalse/truefalse.classes.inc \TrueFalseResponse
  2. 6.4 question_types/truefalse/truefalse.classes.inc \TrueFalseResponse
  3. 6.5 question_types/quiz_question/quiz_question.truefalse.inc \TrueFalseResponse
  4. 7.6 question_types/truefalse/truefalse.classes.inc \TrueFalseResponse
  5. 7 question_types/truefalse/truefalse.classes.inc \TrueFalseResponse
  6. 7.4 question_types/truefalse/truefalse.classes.inc \TrueFalseResponse
  7. 7.5 question_types/truefalse/truefalse.classes.inc \TrueFalseResponse

Hierarchy

Expanded class hierarchy of TrueFalseResponse

1 string reference to 'TrueFalseResponse'
quiz_question_quiz_question_info in question_types/quiz_question/quiz_question.module
Implementation of hook_quiz_question_info().

File

question_types/quiz_question/quiz_question.truefalse.inc, line 150
Defines the classes necessary for a True/False quiz.

View source
class TrueFalseResponse extends AbstractQuizQuestionResponse {
  public function __construct($rid, $question, $answer = NULL) {
    $this->rid = $rid;
    $this->question = $question;
    if (!isset($answer)) {
      $r = $this
        ->getCorrectAnswer();
      if (!empty($r)) {
        $this->answer = $r->answer;
        $this->score = $r->score;
      }
    }
    else {
      $this->answer = $answer;
    }
  }
  public function save() {
    $sql = "INSERT INTO {quiz_truefalse_user_answers} (question_nid, question_vid, result_id, answer, score) VALUES (%d, %d, %d, %d, %d)";
    db_query($sql, $this->question->nid, $this->question->vid, $this->rid, (int) $this->answer, (int) $this->score);
  }
  public function delete() {
    $sql = "DELETE FROM {quiz_truefalse_user_answers} WHERE question_nid = %d AND question_vid = %d AND result_id = %d";
    db_query($sql, $this->question->nid, $this->question->vid, $this->rid);
  }
  public function score() {
    $tfQuestion = new TrueFalseQuestion($this->question);
    $this->score = $this
      ->getResponse() == $tfQuestion
      ->getCorrectAnswer() ? 1 : 0;
    return $this->score;
  }
  public function getResponse() {
    if (!isset($this->answer)) {
      $correct_answer = $this
        ->getCorrectAnswer();
      $this->answer = $correct_answer->answer;
    }
    return $this->answer;
  }
  public function getCorrectAnswer() {
    $sql = "SELECT answer, score FROM {quiz_truefalse_user_answers} WHERE question_vid = %d AND result_id = %d";
    return db_fetch_object(db_query($sql, $this->question->vid, $this->rid));
  }
  public function formatReport($showpoints = TRUE, $showfeedback = TRUE) {

    // Build the question answers header (add blank space for IE).
    if ($showpoints) {
      $innerheader[] = t('Correct Answer');
    }
    $innerheader[] = t('User Answer');
    if ($showfeedback) {
      $innerheader[] = ' ';
    }
    if (empty($this->question->answers)) {
      return t('Missing question.');
    }
    $answer = $this->question->answers[0];
    $correct_answer = $answer['is_correct'] ? $answer['answer'] : !$answer['answer'];
    $user_answer = $answer['answer'];
    if ($showpoints) {
      $rows[0][] = $correct_answer ? t('True') : t('False');
    }
    $rows[0][] = $user_answer ? t('True') : t('False');
    if ($showfeedback && !empty($this->question->feedback)) {
      $rows[0][] = $this->question->feedback;
    }

    // Add the cell with the question and the answers.
    $q_output = '<div class="quiz_summary_question"><span class="quiz_question_bullet">' . t('Q:') . '</span> ' . check_markup($this->question->body, $this->question->format) . '</div>';
    $q_output .= theme('table', $innerheader, $rows) . '<br />';
    return $q_output;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractQuizQuestionResponse::$answer protected property
AbstractQuizQuestionResponse::$evaluated protected property
AbstractQuizQuestionResponse::$is_correct public property
AbstractQuizQuestionResponse::$question protected property
AbstractQuizQuestionResponse::$rid public property
AbstractQuizQuestionResponse::$score public property
AbstractQuizQuestionResponse::getReport public function Get data suitable for reporting a user's score on the question. This expects an object with the following attributes: Overrides QuizQuestionResponse::getReport
AbstractQuizQuestionResponse::getScore function Get the integer score. Overrides QuizQuestionResponse::getScore
AbstractQuizQuestionResponse::isCorrect function Check to see if the answer is marked as correct. Overrides QuizQuestionResponse::isCorrect 3
AbstractQuizQuestionResponse::isEvaluated public function Indicate whether the response has been evaluated (scored) yet. Questions that require human scoring (e.g. essays) may need to manually toggle this. Overrides QuizQuestionResponse::isEvaluated
AbstractQuizQuestionResponse::toBareObject function Repesent the response as a stdClass object. Overrides QuizQuestionResponse::toBareObject
TrueFalseResponse::delete public function Delete the response. Overrides QuizQuestionResponse::delete
TrueFalseResponse::formatReport public function Return an HTML marked-up report for displaying the results of this question. Overrides QuizQuestionResponse::formatReport
TrueFalseResponse::getCorrectAnswer public function
TrueFalseResponse::getResponse public function Get the user's response. Overrides QuizQuestionResponse::getResponse
TrueFalseResponse::save public function Save the current response. Overrides QuizQuestionResponse::save
TrueFalseResponse::score public function Calculate the score for the response. This MUST set the $score instance variable. Overrides QuizQuestionResponse::score
TrueFalseResponse::__construct public function Create a new user response. Overrides QuizQuestionResponse::__construct