You are here

class LongAnswerQuestion in Quiz 6.3

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

Implementation of QuizQuestion.

Hierarchy

Expanded class hierarchy of LongAnswerQuestion

1 string reference to 'LongAnswerQuestion'
long_answer_quiz_question_info in question_types/long_answer/long_answer.module
Implementation of hook_quiz_question_info().

File

question_types/long_answer/long_answer.classes.inc, line 13
Long answer classes.

View source
class LongAnswerQuestion implements QuizQuestion {

  /**
   * The current node for this question.
   */
  protected $node = NULL;
  public function __construct($node) {
    $this->node = $node;
  }
  public function save($is_new = FALSE) {
    if (!isset($this->node->feedback)) {
      $this->node->feedback = '';
    }
    if ($is_new || $this->node->revision == 1) {
      $sql = 'INSERT INTO {quiz_long_answer_node_properties} (nid, vid, maximum_score) VALUES (%d, %d, %d)';
      db_query($sql, $this->node->nid, $this->node->vid, $this->node->maximum_score);
    }
    else {
      $sql = 'UPDATE {quiz_long_answer_node_properties} SET maximum_score = %d WHERE nid = %d AND vid = %d';
      db_query($sql, $this->node->maximum_score, $this->node->nid, $this->node->vid);
    }
  }
  public function validate($node, &$form) {

    // Check to make sure that the maximum score is greater-than or equal-to 0.
    $maximum_score = $node->maximum_score;
    if ((int) $maximum_score != $maximum_score || (int) $maximum_score < 0) {
      form_set_error('maximum_score', t('Score must be a positive integer (0 or higher).'));
    }
  }
  public function delete($only_this_version = FALSE) {
    if ($only_this_version) {
      db_query('DELETE FROM {quiz_long_answer_node_properties} WHERE nid = %d AND vid = %d', $this->node->nid, $this->node->vid);
    }
    else {
      db_query('DELETE FROM {quiz_long_answer_node_properties} WHERE nid = %d', $this->node->nid);
    }
  }
  public function load() {
    $sql = 'SELECT maximum_score FROM {quiz_long_answer_node_properties} WHERE nid = %d AND vid = %d';
    return db_fetch_object(db_query($sql, $this->node->nid, $this->node->vid));
  }
  public function view() {
    return $this
      ->getQuestionForm($this->node);
  }

  // This is called whenever a question is rendered, either
  // to an administrator or to a quiz taker.
  public function getQuestionForm($node, $context = NULL) {

    //print_r($node);exit;
    $form['question'] = array(
      '#type' => 'markup',
      '#value' => $node->body,
    );
    $form['tries'] = array(
      '#type' => 'textarea',
      '#title' => t('Answer'),
      '#description' => t('Enter your answer here. If you need more space, click on the grey bar at the bottom of this area and drag it down.'),
      '#rows' => 15,
      '#cols' => 60,
      '#required' => FALSE,
    );
    return $form;
  }
  public function getAdminForm($edit = NULL) {
    $form['settings'] = array(
      '#type' => 'markup',
      '#value' => t('There are no settings for this question type.'),
    );
    return $form;
  }
  public function getCreationForm($edit) {
    $form['maximum_score'] = array(
      '#type' => 'textfield',
      '#title' => t('Maximum Possible Score'),
      '#description' => t('Long answer questions are scored manually. This field indicates to the person scoring what the maximum number of points per essay is. Multichoice questions have a score of 1.'),
      '#default_value' => isset($this->node->maximum_score) ? $this->node->maximum_score : variable_get('long_answer_default_maximum_score', 1),
      '#size' => 3,
      '#maxlength' => 3,
      '#required' => TRUE,
    );
    return $form;
  }
  public function getMaximumScore() {
    return $this->node->maximum_score;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LongAnswerQuestion::$node protected property The current node for this question.
LongAnswerQuestion::delete public function Deletes a question from the database. Overrides QuizQuestion::delete
LongAnswerQuestion::getAdminForm public function Get the form that contains admin settings for this question type. Overrides QuizQuestion::getAdminForm
LongAnswerQuestion::getCreationForm public function Get the form used to create a new question. Overrides QuizQuestion::getCreationForm
LongAnswerQuestion::getMaximumScore public function Get the maximum possible score for this question. Overrides QuizQuestion::getMaximumScore
LongAnswerQuestion::getQuestionForm public function Get the form that will be displayed to the test-taking user. Overrides QuizQuestion::getQuestionForm
LongAnswerQuestion::load public function Retrieve information about the question and add it to the node. Overrides QuizQuestion::load
LongAnswerQuestion::save public function Responsible for handling insert/update of question-specific data. This is typically called from within the Node API, so there is no need to save the node. This function is only responsible for saving data specific to the implement ation. Overrides QuizQuestion::save
LongAnswerQuestion::validate public function Provides validation for question before it is created. Overrides QuizQuestion::validate
LongAnswerQuestion::view public function Retrieve information relevant for viewing the node. This data is generally added to the node's extra field. Overrides QuizQuestion::view
LongAnswerQuestion::__construct public function Construct a new quiz question. Overrides QuizQuestion::__construct