You are here

class LongAnswerQuestion in Quiz 6.4

Same name and namespace in other branches
  1. 6.6 question_types/long_answer/long_answer.classes.inc \LongAnswerQuestion
  2. 6.3 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

Extension 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 14
Long answer classes.

View source
class LongAnswerQuestion extends QuizQuestion {

  /**
   * Implementation of saveNodeProperties
   *
   * @see QuizQuestion#saveNodeProperties($is_new)
   */
  public function saveNodeProperties($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}\n        (nid, vid, rubric)\n        VALUES (%d, %d, '%s')";
      db_query($sql, $this->node->nid, $this->node->vid, $this->node->rubric);
    }
    else {
      $sql = "UPDATE {quiz_long_answer_node_properties}\n        SET rubric = '%s'\n        WHERE nid = %d AND vid = %d";
      db_query($sql, $this->node->rubric, $this->node->nid, $this->node->vid);
    }
  }

  /**
   * Implementation of validateNode
   *
   * @see QuizQuestion#validateNode($form)
   */
  public function validateNode(array &$form) {
  }

  /**
   * Implementation of delete
   *
   * @see QuizQuestion#delete($only_this_version)
   */
  public function delete($only_this_version = FALSE) {
    if ($only_this_version) {
      db_query('DELETE FROM {quiz_long_answer_user_answers} WHERE question_nid = %d AND question_vid = %d', $this->node->nid, $this->node->vid);
      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);
      db_query('DELETE FROM {quiz_long_answer_user_answers} WHERE question_nid = %d', $this->node->nid);
    }
    parent::delete($only_this_version);
  }

  /**
   * Implementation of getNodeProperties
   *
   * @see QuizQuestion#getNodeProperties()
   */
  public function getNodeProperties() {
    if (isset($this->nodeProperties)) {
      return $this->nodeProperties;
    }
    $props = parent::getNodeProperties();
    $sql = 'SELECT rubric
      FROM {quiz_long_answer_node_properties}
      WHERE nid = %d AND vid = %d';
    $res = db_query($sql, $this->node->nid, $this->node->vid);
    $res_a = db_fetch_array($res);
    if (is_array($res_a)) {
      $props = array_merge($props, $res_a);
    }
    $this->nodeProperties = $props;
    return $props;
  }

  /**
   * Implementation of getNodeView
   *
   * @see QuizQuestion#getNodeView()
   */
  public function getNodeView() {
    $content = parent::getNodeView();
    if ($this
      ->viewCanRevealCorrect()) {
      $rubric_html = check_markup($this->node->rubric, $this->node->format, FALSE);
      $content['answers'] = array(
        '#type' => 'item',
        '#title' => t('Rubric'),
        '#value' => '<div class="quiz-solution">' . $rubric_html . '</div>',
        '#weight' => 1,
      );
    }
    else {
      $content['answers'] = array(
        '#type' => 'markup',
        '#value' => '<div class="quiz-answer-hidden">Answer hidden</div>',
        '#weight' => 1,
      );
    }
    return $content;
  }

  /**
   * Implementation of getAnweringForm
   *
   * @see QuizQuestion#getAnsweringForm($form_state, $rid)
   */
  public function getAnsweringForm(array $form_state = NULL, $rid) {
    $form = parent::getAnsweringForm($form_state, $rid);
    $form['#theme'] = 'long_answer_answering_form';
    $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,
    );
    if (isset($rid)) {
      $response = new LongAnswerResponse($rid, $this->node);
      $form['tries']['#default_value'] = $response
        ->getResponse();
    }
    return $form;
  }

  /**
   * Implementation of getCreationForm
   *
   * @see QuizQuestion#getCreationForm($form_state)
   */
  public function getCreationForm(array $form_state = NULL) {
    $form['rubric'] = array(
      '#type' => 'textarea',
      '#title' => t('Rubric'),
      '#description' => t('Specify the criteria for grading the response.'),
      '#default_value' => isset($this->node->rubric) ? $this->node->rubric : '',
      '#size' => 60,
      '#maxlength' => 512,
      '#required' => FALSE,
    );
    return $form;
  }

  /**
   * Implementation of getMaximumScore
   *
   * @see QuizQuestion#getMaximumScore()
   */
  public function getMaximumScore() {
    return 10;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LongAnswerQuestion::delete public function Implementation of delete Overrides QuizQuestion::delete
LongAnswerQuestion::getAnsweringForm public function Implementation of getAnweringForm Overrides QuizQuestion::getAnsweringForm
LongAnswerQuestion::getCreationForm public function Implementation of getCreationForm Overrides QuizQuestion::getCreationForm
LongAnswerQuestion::getMaximumScore public function Implementation of getMaximumScore Overrides QuizQuestion::getMaximumScore
LongAnswerQuestion::getNodeProperties public function Implementation of getNodeProperties Overrides QuizQuestion::getNodeProperties
LongAnswerQuestion::getNodeView public function Implementation of getNodeView Overrides QuizQuestion::getNodeView
LongAnswerQuestion::saveNodeProperties public function Implementation of saveNodeProperties Overrides QuizQuestion::saveNodeProperties
LongAnswerQuestion::validateNode public function Implementation of validateNode Overrides QuizQuestion::validateNode
QuizQuestion::$node public property The current node for this question.
QuizQuestion::$nodeProperties public property
QuizQuestion::getBodyFieldTitle public function Allow question types to override the body field title 3
QuizQuestion::getNodeForm public function Returns a node form to quiz_question_form
QuizQuestion::hasBeenAnswered public function Finds out if a question has been answered or not
QuizQuestion::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.
QuizQuestion::saveRelationships function Handle the add to quiz part of the quiz_question_form
QuizQuestion::viewCanRevealCorrect public function Determines if the user can view the correct answers
QuizQuestion::__construct public function QuizQuestion constructor stores the node object. 2