You are here

class ScaleResponse in Quiz 6.6

Same name and namespace in other branches
  1. 8.6 question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleResponse.php \ScaleResponse
  2. 8.5 question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleResponse.php \ScaleResponse
  3. 6.4 question_types/scale/scale.classes.inc \ScaleResponse
  4. 7.6 question_types/scale/scale.classes.inc \ScaleResponse
  5. 7 question_types/scale/scale.classes.inc \ScaleResponse
  6. 7.4 question_types/scale/scale.classes.inc \ScaleResponse
  7. 7.5 question_types/scale/scale.classes.inc \ScaleResponse

The short answer question response class.

Hierarchy

Expanded class hierarchy of ScaleResponse

1 string reference to 'ScaleResponse'
scale_quiz_question_info in question_types/scale/scale.module
Implementation of hook_quiz_question_info().

File

question_types/scale/scale.classes.inc, line 484
The main classes for the scale question type.

View source
class ScaleResponse extends AbstractQuizQuestionResponse {

  /**
   * ID of the answer.
   */
  protected $answer_id = 0;

  /**
   * Constructor
   *
   * @param $rid - response_id
   * @param $question - as an object
   * @param $answer - answer_id
   */
  public function __construct($rid, $question, $answer = NULL) {
    $this->rid = $rid;
    $this->question = $question;
    if (isset($answer)) {
      $this->answer_id = $answer;
    }
    else {
      $sql = 'SELECT answer_id
              FROM {quiz_scale_user_answers}
              WHERE result_id = %d AND question_nid = %d AND question_vid = %d';
      $res = db_query($sql, $rid, $this->question->nid, $this->question->vid);
      $res_o = db_fetch_object($res);
      $this->answer_id = $res_o->answer_id;
    }
    $sql = 'SELECT answer
            FROM {quiz_scale_answer}
            WHERE id = %d';
    $res = db_query($sql, $this->answer_id);
    $res_o = db_fetch_object($res);
    $this->answer = check_plain($res_o->answer);
  }

  /**
   * Implementation of save
   */
  public function save() {
    $sql = "INSERT INTO {quiz_scale_user_answers}\n      (answer_id, result_id, question_vid, question_nid)\n      VALUES (%d, %d, %d, %d)";
    db_query($sql, $this->answer_id, $this->rid, $this->question->vid, $this->question->nid);
  }

  /**
   * Implementation of delete
   */
  public function delete() {
    $sql = 'DELETE FROM {quiz_scale_user_answers}
    		WHERE result_id = %d AND question_nid = %d AND question_vid = %d';
    db_query($sql, $this->rid, $this->question->nid, $this->question->vid);
  }

  /**
   * Implementation of score
   *
   * @return 0 - this question type is never scored.
   */
  public function score() {
    return 0;
  }

  /**
   * Implementation of isCorrect
   *
   * @return 0 - this question type is never scored
   * (non-PHPdoc)
   * @see sites/all/modules/quiz-HEAD/question_types/quiz_question/AbstractQuizQuestionResponse#isCorrect()
   */
  public function isCorrect() {
    return TRUE;
  }

  /**
   * Implementation of getResponse
   *
   * @return answer
   */
  public function getResponse() {
    return $this->answer;
  }

  /**
   * Implementation of format report.
   *
   * @param $showpoints
   * @param $showfeedback
   * @return report as html
   */
  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->format, FALSE) . '</div>';
    $result = '<div class="quiz_answer_feedback">';
    $result .= t('You answered:');
    $result .= '<BR/>';
    $result .= check_plain($this->answer);
    $result .= '</div>';
    return $slug . $result;
  }

}

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 protected property
AbstractQuizQuestionResponse::getReport public function
AbstractQuizQuestionResponse::getScore function
AbstractQuizQuestionResponse::isEvaluated public function
AbstractQuizQuestionResponse::toBareObject function
ScaleResponse::$answer_id protected property ID of the answer.
ScaleResponse::delete public function Implementation of delete
ScaleResponse::formatReport public function Implementation of format report.
ScaleResponse::getResponse public function Implementation of getResponse
ScaleResponse::isCorrect public function Implementation of isCorrect Overrides AbstractQuizQuestionResponse::isCorrect
ScaleResponse::save public function Implementation of save
ScaleResponse::score public function Implementation of score
ScaleResponse::__construct public function Constructor