class TrueFalseResponse in Quiz 6.4
Same name and namespace in other branches
- 6.6 question_types/truefalse/truefalse.classes.inc \TrueFalseResponse
- 6.3 question_types/quiz_question/quiz_question.truefalse.inc \TrueFalseResponse
- 6.5 question_types/quiz_question/quiz_question.truefalse.inc \TrueFalseResponse
- 7.6 question_types/truefalse/truefalse.classes.inc \TrueFalseResponse
- 7 question_types/truefalse/truefalse.classes.inc \TrueFalseResponse
- 7.4 question_types/truefalse/truefalse.classes.inc \TrueFalseResponse
- 7.5 question_types/truefalse/truefalse.classes.inc \TrueFalseResponse
Extension of QuizQuestionResponse
Hierarchy
- class \QuizQuestionResponse
- class \TrueFalseResponse
Expanded class hierarchy of TrueFalseResponse
1 string reference to 'TrueFalseResponse'
- truefalse_quiz_question_info in question_types/
truefalse/ truefalse.module - Implementation of hook_quiz_question_info().
File
- question_types/
truefalse/ truefalse.classes.inc, line 206 - Defines the classes necessary for a True/False quiz.
View source
class TrueFalseResponse extends QuizQuestionResponse {
/**
* Constructor
*/
public function __construct($result_id, stdClass $question_node, $answer = NULL) {
parent::__construct($result_id, $question_node, $answer);
if (!isset($answer)) {
$r = $this
->getCorrectAnswer();
if (!empty($r)) {
$this->answer = $r->answer;
$this->score = $r->score;
}
}
else {
$this->answer = $answer;
}
}
/**
* Implementation of isValid
*
* @see QuizQuestionResponse#isValid()
*/
public function isValid() {
if ($this->answer['answer'] === NULL) {
return t('You must provide an answer');
}
else {
return TRUE;
}
}
/**
* Implementation of save
*
* @see QuizQuestionResponse#save()
*/
public function save() {
$sql = "INSERT INTO {quiz_truefalse_user_answers} (question_nid, question_vid, result_id, answer, score) VALUES (%d, %d, %d, %d, %d)";
db_query($sql, $this->question->nid, $this->question->vid, $this->rid, (int) $this->answer, (int) $this
->getScore());
}
/**
* Implementation of delete
*
* @see QuizQuestionResponse#delete()
*/
public function delete() {
$sql = "DELETE FROM {quiz_truefalse_user_answers} WHERE question_nid = %d AND question_vid = %d AND result_id = %d";
db_query($sql, $this->question->nid, $this->question->vid, $this->rid);
}
/**
* Implementation of score
*
* @see QuizQuestionResponse#score()
*/
public function score() {
$tfQuestion = new TrueFalseQuestion($this->question);
return $this
->getResponse() == $tfQuestion
->getCorrectAnswer() ? 1 : 0;
}
/**
* Implementation of getResponse
*
* @see QuizQuestionResponse#getResponse()
*/
public function getResponse() {
if (!isset($this->answer)) {
$correct_answer = $this
->getCorrectAnswer();
$this->answer = $correct_answer->answer;
}
return $this->answer;
}
/**
* Implementation of getCorrectAnswer
*/
public function getCorrectAnswer() {
$sql = "SELECT answer, score FROM {quiz_truefalse_user_answers} WHERE question_vid = %d AND result_id = %d";
return db_fetch_object(db_query($sql, $this->question->vid, $this->rid));
}
/**
* Implementation of getReportFormResponse
*
* @see QuizQuestionResponse#getReportFormResponse($showpoints, $showfeedback, $allow_scoring)
*/
public function getReportFormResponse($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) {
if (empty($this->question->answers)) {
return array(
'#type' => 'markup',
'#value' => t('Missing question.'),
);
}
$metadata = array();
$data = array();
// Build the question answers header (add blank space for IE).
if ($showpoints) {
$metadata[] = t('Correct Answer');
}
$metadata[] = t('User answer');
if ($showfeedback) {
$metadata[] = ' ';
}
$answer = $this->question->answers[0];
$correct_answer = $answer['is_correct'] ? $answer['answer'] : !$answer['answer'];
$user_answer = $answer['answer'];
if ($showpoints) {
$data[0]['correct_answer'] = $correct_answer ? t('True') : t('False');
}
$data[0]['user_answer'] = $user_answer === NULL ? '' : ($user_answer ? t('True') : t('False'));
if ($showfeedback && !empty($this->question->feedback)) {
$data[0]['feedback'] = check_markup($this->question->feedback, $this->question->format, FALSE);
}
// Return themed output
return array(
'#type' => 'markup',
'#value' => theme('truefalse_response', $metadata, $data),
);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | 7 | |
QuizQuestionResponse:: |
public | function | Returns stored max score if it exists, if not the max score is calculated and returned. | |
QuizQuestionResponse:: |
public | function | Get data suitable for reporting a user's score on the question. This expects an object with the following attributes: | |
QuizQuestionResponse:: |
public | function | Creates the report form for the admin pages, and for when a user gets feedback after answering questions. | 1 |
QuizQuestionResponse:: |
public | function | 2 | |
QuizQuestionResponse:: |
public | function | get the question part of the reportForm | |
QuizQuestionResponse:: |
public | function | Get the score part of the report form | 2 |
QuizQuestionResponse:: |
public | function | Get the submit function for the reportForm | 2 |
QuizQuestionResponse:: |
public | function | Get the theme key for the reportForm | |
QuizQuestionResponse:: |
public | function | Get the validate function for the reportForm | 2 |
QuizQuestionResponse:: |
function | Returns stored score if it exists, if not the score is calculated and returned. | ||
QuizQuestionResponse:: |
function | Check to see if the answer is marked as correct. | 1 | |
QuizQuestionResponse:: |
public | function | Indicate whether the response has been evaluated (scored) yet. Questions that require human scoring (e.g. essays) may need to manually toggle this. | |
QuizQuestionResponse:: |
public | function | Used to refresh this instances question node in case drupal has changed it. | |
QuizQuestionResponse:: |
public | function | Saves the quiz result. This is not used when a question is skipped! | |
QuizQuestionResponse:: |
function | Represent the response as a stdClass object. | ||
TrueFalseResponse:: |
public | function |
Implementation of delete Overrides QuizQuestionResponse:: |
|
TrueFalseResponse:: |
public | function | Implementation of getCorrectAnswer | |
TrueFalseResponse:: |
public | function |
Implementation of getReportFormResponse Overrides QuizQuestionResponse:: |
|
TrueFalseResponse:: |
public | function |
Implementation of getResponse Overrides QuizQuestionResponse:: |
|
TrueFalseResponse:: |
public | function |
Implementation of isValid Overrides QuizQuestionResponse:: |
|
TrueFalseResponse:: |
public | function |
Implementation of save Overrides QuizQuestionResponse:: |
|
TrueFalseResponse:: |
public | function |
Implementation of score Overrides QuizQuestionResponse:: |
|
TrueFalseResponse:: |
public | function |
Constructor Overrides QuizQuestionResponse:: |