class TrueFalseQuestion in Quiz 6.6
Same name and namespace in other branches
- 6.3 question_types/quiz_question/quiz_question.truefalse.inc \TrueFalseQuestion
- 6.4 question_types/truefalse/truefalse.classes.inc \TrueFalseQuestion
- 6.5 question_types/quiz_question/quiz_question.truefalse.inc \TrueFalseQuestion
- 7.6 question_types/truefalse/truefalse.classes.inc \TrueFalseQuestion
- 7 question_types/truefalse/truefalse.classes.inc \TrueFalseQuestion
- 7.4 question_types/truefalse/truefalse.classes.inc \TrueFalseQuestion
- 7.5 question_types/truefalse/truefalse.classes.inc \TrueFalseQuestion
Implementation of QuizQuestion.
Hierarchy
- class \TrueFalseQuestion implements QuizQuestion
Expanded class hierarchy of TrueFalseQuestion
1 string reference to 'TrueFalseQuestion'
- truefalse_quiz_question_info in question_types/
truefalse/ truefalse.module - Implementation of hook_quiz_question_info().
File
- question_types/
truefalse/ truefalse.classes.inc, line 13 - Defines the classes necessary for a True/False quiz.
View source
class TrueFalseQuestion implements QuizQuestion {
/**
* The current node for this question.
*/
protected $node = NULL;
public function __construct($node) {
$this->node = $node;
}
public function save($is_new = FALSE) {
//drupal_set_message('Save called', 'status');
if (!isset($this->node->feedback)) {
$this->node->feedback = '';
}
if ($is_new || $this->node->revision == 1) {
$sql = "INSERT INTO {quiz_truefalse_node} (nid, vid, correct_answer, feedback) VALUES (%d, %d, %d, '%s')";
db_query($sql, $this->node->nid, $this->node->vid, (int) $this->node->correct_answer, $this->node->feedback);
}
else {
drupal_set_message('Updating', 'status');
$sql = "UPDATE {quiz_truefalse_node} SET correct_answer = %d, feedback = '%s' WHERE nid = %d AND vid = %d";
db_query($sql, (int) $this->node->correct_answer, $this->node->feedback, $this->node->nid, $this->node->vid);
}
}
public function validate($node, &$form) {
// This space intentionally left blank. :)
}
public function delete($only_this_version = FALSE) {
// Only delete a nid/vid.
if ($only_this_version) {
$sql = 'DELETE FROM {quiz_truefalse_node} WHERE nid = %d AND vid = %d';
db_query($sql, $this->node->nid, $this->node->vid);
}
else {
$sql = 'DELETE FROM {quiz_truefalse_node} WHERE nid = %d';
db_query($sql, $this->node->nid, $this->node->vid);
}
}
public function load() {
$sql = 'SELECT correct_answer, feedback FROM {quiz_truefalse_node} WHERE nid = %d AND vid = %d';
$result = db_fetch_object(db_query($sql, $this->node->nid, $this->node->vid));
return $result;
}
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) {
$taking_quiz = _quiz_is_taking_context();
// Question first
$form['question'] = array(
'#type' => 'markup',
'#value' => $node->body,
);
// 'tries' is unfortunately required by quiz.module
$form['tries'] = array(
'#type' => 'radios',
'#title' => t('Choose one'),
'#options' => array(
1 => $taking_quiz || $node->correct_answer == 0 ? t('True') : t('True (correct)'),
0 => $taking_quiz || $node->correct_answer == 1 ? t('False') : t('False (correct)'),
),
//'#default_value' => 1,
'#required' => TRUE,
);
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['correct_answer'] = array(
'#type' => 'radios',
'#title' => t('Correct answer'),
'#options' => array(
1 => t('True'),
0 => t('False'),
),
'#default_value' => isset($this->node->correct_answer) ? $this->node->correct_answer : 1,
'#required' => TRUE,
);
$form['feedback_fields'] = array(
'#type' => 'fieldset',
'#title' => t('Feedback Settings'),
'#description' => t('Settings pertaining to feedback given along with results.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['feedback_fields']['feedback'] = array(
'#type' => 'textarea',
'#title' => t('Feedback Text'),
'#description' => t('Text to be displayed when the results are displayed'),
'#rows' => 5,
'#cols' => 60,
'#required' => FALSE,
'#default_value' => isset($this->node->feedback) ? $this->node->feedback : '',
);
return $form;
}
public function getMaximumScore() {
return 1;
}
/**
* Get the answer to this question.
*
* This is a utility function. It is not defined in the interface.
*/
public function getCorrectAnswer() {
$sql = "SELECT correct_answer FROM {quiz_truefalse_node} WHERE nid = %d AND vid = %d";
return db_result(db_query($sql, $this->node->nid, $this->node->vid));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TrueFalseQuestion:: |
protected | property | The current node for this question. | |
TrueFalseQuestion:: |
public | function |
Deletes a question from the database. Overrides QuizQuestion:: |
|
TrueFalseQuestion:: |
public | function |
Get the form that contains admin settings for this question type. Overrides QuizQuestion:: |
|
TrueFalseQuestion:: |
public | function | Get the answer to this question. | |
TrueFalseQuestion:: |
public | function |
Get the form used to create a new question. Overrides QuizQuestion:: |
|
TrueFalseQuestion:: |
public | function |
Get the maximum possible score for this question. Overrides QuizQuestion:: |
|
TrueFalseQuestion:: |
public | function |
Get the form that will be displayed to the test-taking user. Overrides QuizQuestion:: |
|
TrueFalseQuestion:: |
public | function |
Retrieve information about the question and add it to the node. Overrides QuizQuestion:: |
|
TrueFalseQuestion:: |
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:: |
|
TrueFalseQuestion:: |
public | function |
Provides validation for question before it is created. Overrides QuizQuestion:: |
|
TrueFalseQuestion:: |
public | function |
Retrieve information relevant for viewing the node.
This data is generally added to the node's extra field. Overrides QuizQuestion:: |
|
TrueFalseQuestion:: |
public | function |
Construct a new quiz question. Overrides QuizQuestion:: |