You are here

class LongAnswerQuestion in Quiz 7.5

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.4 question_types/long_answer/long_answer.classes.inc \LongAnswerQuestion
  4. 6.5 question_types/long_answer/long_answer.classes.inc \LongAnswerQuestion
  5. 7.6 question_types/long_answer/long_answer.classes.inc \LongAnswerQuestion
  6. 7 question_types/long_answer/long_answer.classes.inc \LongAnswerQuestion
  7. 7.4 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
Implements 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()
   */
  public function saveNodeProperties($is_new = FALSE) {
    db_merge('quiz_long_answer_node_properties')
      ->key(array(
      'nid' => $this->node->nid,
      'vid' => $this->node->vid,
    ))
      ->fields(array(
      'nid' => $this->node->nid,
      'vid' => $this->node->vid,
      'rubric' => $this->node->rubric['value'],
      'rubric_format' => $this->node->rubric['format'],
      'answer_text_processing' => $this->node->answer_text_processing,
    ))
      ->execute();
  }

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

  /**
   * Implementation of delete().
   *
   * @see QuizQuestion::delete()
   */
  public function delete($only_this_version = FALSE) {
    $delete_node = db_delete('quiz_long_answer_node_properties');
    $delete_node
      ->condition('nid', $this->node->nid);
    if ($only_this_version) {
      $delete_node
        ->condition('vid', $this->node->vid);
    }
    $delete_node
      ->execute();
    parent::delete($only_this_version);
  }

  /**
   * Implementation of getNodeProperties().
   *
   * @see QuizQuestion::getNodeProperties()
   */
  public function getNodeProperties() {
    if (isset($this->nodeProperties)) {
      return $this->nodeProperties;
    }
    $props = parent::getNodeProperties();
    $res_a = db_query('SELECT rubric as value, rubric_format as format, answer_text_processing FROM {quiz_long_answer_node_properties}
      WHERE nid = :nid AND vid = :vid', array(
      ':nid' => $this->node->nid,
      ':vid' => $this->node->vid,
    ))
      ->fetchAssoc();
    if (is_array($res_a)) {
      $props['rubric'] = array(
        'value' => $res_a['value'],
        'format' => $res_a['format'],
      );
      $props['answer_text_processing'] = $res_a['answer_text_processing'];
    }
    $this->nodeProperties = $props;
    return $props;
  }

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

  /**
   * Implementation of getAnsweringForm().
   *
   * @see QuizQuestion::getAnsweringForm()
   */
  public function getAnsweringForm(array $form_state = NULL, $result_id) {
    $element = parent::getAnsweringForm($form_state, $result_id);
    $element += array(
      '#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,
    );
    if ($this->node->answer_text_processing) {
      $element['#type'] = 'text_format';
    }
    else {
      $element['#type'] = 'textarea';
    }
    if (isset($result_id)) {
      if ($response = _quiz_question_response_get_instance($result_id, $this->node)) {
        if ($user_response = $response
          ->getResponse()) {
          $element['#default_value'] = $user_response;
          $element['#format'] = $response->answer_format;
        }
      }
    }
    return $element;
  }

  /**
   * Question response validator.
   */
  public function getAnsweringFormValidate(array &$element, &$value) {
    if ($value == '') {
      form_error($element, t('You must provide an answer.'));
    }
  }

  /**
   * Implementation of getCreationForm().
   *
   * @see QuizQuestion::getCreationForm()
   */
  public function getCreationForm(array &$form_state = NULL) {
    $form = array();
    $form['rubric'] = array(
      '#type' => 'text_format',
      '#title' => t('Rubric'),
      '#description' => t('Specify the criteria for grading the response.'),
      '#default_value' => isset($this->node->rubric['value']) ? $this->node->rubric['value'] : '',
      '#format' => isset($this->node->rubric['format']) ? $this->node->rubric['format'] : filter_default_format(),
      '#size' => 60,
      '#required' => FALSE,
    );
    $form['answer_text_processing'] = array(
      '#title' => t('Answer text processing'),
      '#description' => t('Allowing filtered text may enable the user to input HTML tags in their answer.'),
      '#type' => 'radios',
      '#options' => array(
        0 => t('Plain text'),
        1 => t('Filtered text (user selects text format)'),
      ),
      '#default_value' => isset($this->node->answer_text_processing) ? $this->node->answer_text_processing : 0,
    );
    return $form;
  }

  /**
   * Implementation of getMaximumScore().
   *
   * @see QuizQuestion::getMaximumScore()
   */
  public function getMaximumScore() {
    return variable_get('long_answer_default_max_score', 10);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LongAnswerQuestion::delete public function Implementation of delete(). Overrides QuizQuestion::delete
LongAnswerQuestion::getAnsweringForm public function Implementation of getAnsweringForm(). Overrides QuizQuestion::getAnsweringForm
LongAnswerQuestion::getAnsweringFormValidate public function Question response validator. Overrides QuizQuestion::getAnsweringFormValidate
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::autoUpdateMaxScore protected function This may be overridden in subclasses. If it returns true, it means the max_score is updated for all occurrences of this question in quizzes.
QuizQuestion::getBodyFieldTitle public function Allow question types to override the body field title. 4
QuizQuestion::getFormat protected function Utility function that returns the format of the node body.
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::hasFeedback public function Does this question type give feedback? 3
QuizQuestion::isGraded public function Is this question graded? 2
QuizQuestion::isQuestion public function Is this "question" an actual question? 2
QuizQuestion::save public function Responsible for handling insert/update of question-specific data.
QuizQuestion::saveRelationships public function Save this Question to the specified Quiz.
QuizQuestion::viewCanRevealCorrect public function Determines if the user can view the correct answers.
QuizQuestion::__construct public function QuizQuestion constructor stores the node object. 1