class LongAnswerQuestion in Quiz 7.5
Same name and namespace in other branches
- 6.6 question_types/long_answer/long_answer.classes.inc \LongAnswerQuestion
- 6.3 question_types/long_answer/long_answer.classes.inc \LongAnswerQuestion
- 6.4 question_types/long_answer/long_answer.classes.inc \LongAnswerQuestion
- 6.5 question_types/long_answer/long_answer.classes.inc \LongAnswerQuestion
- 7.6 question_types/long_answer/long_answer.classes.inc \LongAnswerQuestion
- 7 question_types/long_answer/long_answer.classes.inc \LongAnswerQuestion
- 7.4 question_types/long_answer/long_answer.classes.inc \LongAnswerQuestion
Extension of QuizQuestion.
Hierarchy
- class \QuizQuestion
- class \LongAnswerQuestion
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
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LongAnswerQuestion:: |
public | function |
Implementation of delete(). Overrides QuizQuestion:: |
|
LongAnswerQuestion:: |
public | function |
Implementation of getAnsweringForm(). Overrides QuizQuestion:: |
|
LongAnswerQuestion:: |
public | function |
Question response validator. Overrides QuizQuestion:: |
|
LongAnswerQuestion:: |
public | function |
Implementation of getCreationForm(). Overrides QuizQuestion:: |
|
LongAnswerQuestion:: |
public | function |
Implementation of getMaximumScore(). Overrides QuizQuestion:: |
|
LongAnswerQuestion:: |
public | function |
Implementation of getNodeProperties(). Overrides QuizQuestion:: |
|
LongAnswerQuestion:: |
public | function |
Implementation of getNodeView(). Overrides QuizQuestion:: |
|
LongAnswerQuestion:: |
public | function |
Implementation of saveNodeProperties(). Overrides QuizQuestion:: |
|
LongAnswerQuestion:: |
public | function |
Implementation of validateNode(). Overrides QuizQuestion:: |
|
QuizQuestion:: |
public | property | The current node for this question. | |
QuizQuestion:: |
public | property | ||
QuizQuestion:: |
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:: |
public | function | Allow question types to override the body field title. | 4 |
QuizQuestion:: |
protected | function | Utility function that returns the format of the node body. | |
QuizQuestion:: |
public | function | Returns a node form to quiz_question_form. | |
QuizQuestion:: |
public | function | Finds out if a question has been answered or not. | |
QuizQuestion:: |
public | function | Does this question type give feedback? | 3 |
QuizQuestion:: |
public | function | Is this question graded? | 2 |
QuizQuestion:: |
public | function | Is this "question" an actual question? | 2 |
QuizQuestion:: |
public | function | Responsible for handling insert/update of question-specific data. | |
QuizQuestion:: |
public | function | Save this Question to the specified Quiz. | |
QuizQuestion:: |
public | function | Determines if the user can view the correct answers. | |
QuizQuestion:: |
public | function | QuizQuestion constructor stores the node object. | 1 |