You are here

abstract class AbstractQuizQuestionResponse in Quiz 6.3

Same name and namespace in other branches
  1. 6.6 question_types/quiz_question/ \AbstractQuizQuestionResponse
  2. 6.5 question_types/quiz_question/ \AbstractQuizQuestionResponse

A base implementation of QuizQuestionResponse.


Expanded class hierarchy of AbstractQuizQuestionResponse


question_types/quiz_question/, line 212
Classes used in the Quiz Question module.

View source
abstract class AbstractQuizQuestionResponse implements QuizQuestionResponse {

  // These are only public until we can
  // adjust all of Quiz. DO NOT EXPECT THESE
  public $score = 0;
  public $rid = 0;
  public $is_correct = FALSE;
  protected $evaluated = TRUE;
  protected $question = NULL;
  protected $answer = NULL;

  public function __construct($rid, $question, $answer) {
    $this->rid = $rid;
    $this->question = $question;
    $this->answer = $answer;
  public function isEvaluated() {
    return $this->evaluated;

   * Check to see if the answer is marked as correct.
   * This default version returns TRUE iff the score is equal to the maximum possible score.
  function isCorrect() {
    $possible = _quiz_question_get_instance($this->question)
    $actual = $this->score;
    return $possible == $actual;
  function getScore() {
    return $this->score;
  function toBareObject() {
    $obj = new stdClass();
    $obj->score = $this->score;

    // This can be 0 for unscored.
    $obj->nid = $this->question->nid;
    $obj->vid = $this->question->vid;
    $obj->rid = $this->rid;
    $obj->is_correct = $this
    $obj->is_evaluated = $this
    $obj->is_skipped = FALSE;
    return $obj;
  public function getReport() {

    // Basically, we encode internal information in a
    // legacy array format for Quiz.
    $report = array(
      'answer_id' => 0,
      // <-- Stupid vestige of multichoice.
      'answer' => $this->answer,
      'is_evaluated' => $this
      'is_correct' => $this
      'score' => $this->score,
      'question_vid' => $this->question->vid,
      'question_nid' => $this->question->nid,
      'result_id' => $this->rid,
    return $report;



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
QuizQuestionResponse::delete public function Delete the response. 5
QuizQuestionResponse::formatReport public function Return an HTML marked-up report for displaying the results of this question. 5
QuizQuestionResponse::getResponse public function Get the user's response. 5
QuizQuestionResponse::save public function Save the current response. 5
QuizQuestionResponse::score public function Calculate the score for the response. This MUST set the $score instance variable. 5
QuizQuestionResponse::__construct public function Create a new user response. 5