You are here

class ScaleResponse in Quiz 6.4

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.6 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

Extension of QuizQuestionResponse

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 509
The main classes for the scale question type.

View source
class ScaleResponse extends QuizQuestionResponse {

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

  /**
   * Constructor
   */
  public function __construct($result_id, stdClass $question_node, $answer = NULL) {
    parent::__construct($result_id, $question_node, $answer);
    if (isset($answer)) {
      $this->answer_id = intval($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, $result_id, $this->question->nid, $this->question->vid);
      $this->answer_id = db_result($res);
    }
    $sql = 'SELECT answer
            FROM {quiz_scale_answer}
            WHERE id = %d';
    $res = db_query($sql, $this->answer_id);
    $this->answer = check_plain(db_result($res));
  }
  public function isValid() {
    if (empty($this->answer_id)) {
      return t('You must provide an answer');
    }
    return TRUE;
  }

  /**
   * Implementation of save
   *
   * @see QuizQuestionResponse#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
   *
   * @see QuizQuestionResponse#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
   *
   * @see QuizQuestionResponse#score()
   */
  public function score() {
    return $this
      ->isValid() ? 1 : 0;
  }

  /**
   * Implementation of getResponse
   *
   * @see QuizQuestionResponse#getResponse()
   */
  public function getResponse() {
    return $this->answer_id;
  }

  /**
   * Implementation of getReportFormResponse
   *
   * @see getReportFormResponse($showpoints, $showfeedback, $allow_scoring)
   */
  public function getReportFormResponse($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) {
    $form = array();
    $form['#theme'] = 'scale_response_form';
    $form['answer'] = array(
      '#type' => 'markup',
      '#value' => check_plain($this->answer),
    );
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
QuizQuestionResponse::$answer protected property
QuizQuestionResponse::$evaluated protected property
QuizQuestionResponse::$is_correct protected property
QuizQuestionResponse::$is_skipped public property
QuizQuestionResponse::$question public property
QuizQuestionResponse::$rid protected property
QuizQuestionResponse::$score protected property 7
QuizQuestionResponse::getMaxScore public function Returns stored max score if it exists, if not the max score is calculated and returned.
QuizQuestionResponse::getReport public function Get data suitable for reporting a user's score on the question. This expects an object with the following attributes:
QuizQuestionResponse::getReportForm public function Creates the report form for the admin pages, and for when a user gets feedback after answering questions. 1
QuizQuestionResponse::getReportFormAnswerFeedback public function 2
QuizQuestionResponse::getReportFormQuestion public function get the question part of the reportForm
QuizQuestionResponse::getReportFormScore public function Get the score part of the report form 2
QuizQuestionResponse::getReportFormSubmit public function Get the submit function for the reportForm 2
QuizQuestionResponse::getReportFormTheme public function Get the theme key for the reportForm
QuizQuestionResponse::getReportFormValidate public function Get the validate function for the reportForm 2
QuizQuestionResponse::getScore function Returns stored score if it exists, if not the score is calculated and returned.
QuizQuestionResponse::isCorrect function Check to see if the answer is marked as correct. 1
QuizQuestionResponse::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.
QuizQuestionResponse::refreshQuestionNode public function Used to refresh this instances question node in case drupal has changed it.
QuizQuestionResponse::saveResult public function Saves the quiz result. This is not used when a question is skipped!
QuizQuestionResponse::toBareObject function Represent the response as a stdClass object.
ScaleResponse::$answer_id protected property ID of the answer.
ScaleResponse::delete public function Implementation of delete Overrides QuizQuestionResponse::delete
ScaleResponse::getReportFormResponse public function Implementation of getReportFormResponse Overrides QuizQuestionResponse::getReportFormResponse
ScaleResponse::getResponse public function Implementation of getResponse Overrides QuizQuestionResponse::getResponse
ScaleResponse::isValid public function Validates response from a quiz taker. If the response isn't valid the quiz taker won't be allowed to proceed. Overrides QuizQuestionResponse::isValid
ScaleResponse::save public function Implementation of save Overrides QuizQuestionResponse::save
ScaleResponse::score public function Implementation of score Overrides QuizQuestionResponse::score
ScaleResponse::__construct public function Constructor Overrides QuizQuestionResponse::__construct