class TrueFalseResponse in Quiz 7.6
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.4 question_types/truefalse/truefalse.classes.inc \TrueFalseResponse
- 6.5 question_types/quiz_question/quiz_question.truefalse.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 - Implements hook_quiz_question_info().
File
- question_types/
truefalse/ truefalse.classes.inc, line 202 - 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)) {
// Get from DB
$r = $this
->getUserAnswer();
if (!empty($r)) {
$this->answer = $r->answer;
$this->score = $r->score;
}
}
else {
// Load from input
$this->answer = $answer;
}
}
/**
* Implementation of save
*
* @see QuizQuestionResponse#save()
*/
public function save() {
db_insert('quiz_truefalse_user_answers')
->fields(array(
'question_nid' => $this->question->nid,
'question_vid' => $this->question->vid,
'result_id' => $this->result_id,
'answer' => (int) $this->answer,
'score' => (int) $this
->getScore(),
))
->execute();
}
/**
* Implementation of delete
*
* @see QuizQuestionResponse#delete()
*/
public function delete() {
db_delete('quiz_truefalse_user_answers')
->condition('question_nid', $this->question->nid)
->condition('question_vid', $this->question->vid)
->condition('result_id', $this->result_id)
->execute();
}
/**
* 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() {
return $this->answer;
}
/**
* Implementation of getCorrectAnswer
*/
public function getUserAnswer() {
return db_query('SELECT answer, score FROM {quiz_truefalse_user_answers} WHERE question_vid = :qvid AND result_id = :rid', array(
':qvid' => $this->question->vid,
':rid' => $this->result_id,
))
->fetch();
}
/**
* Implementation of getReportFormResponse
*/
public function getFeedbackValues() {
$answer = $this->question->answers[0]['answer'];
$correct_answer = $this->question->correct_answer;
$data = array();
$data[] = array(
'choice' => t('True'),
'attempt' => $answer ? quiz_icon('selected') : '',
'correct' => $answer == 1 ? quiz_icon($correct_answer ? 'correct' : 'incorrect') : '',
'score' => intval($correct_answer == 1 && $answer == 1),
'answer_feedback' => '',
'solution' => $correct_answer == 1 ? quiz_icon('should') : '',
);
$data[] = array(
'choice' => t('False'),
'attempt' => !$answer ? quiz_icon('selected') : '',
'correct' => $answer == 0 ? quiz_icon(!$correct_answer ? 'correct' : 'incorrect') : '',
'score' => intval($correct_answer == 0 && $answer == 0),
'answer_feedback' => '',
'solution' => $correct_answer == 0 ? quiz_icon('should') : '',
);
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | 8 | |
QuizQuestionResponse:: |
public | function | Can the quiz taker view the requested review? | |
QuizQuestionResponse:: |
public | function | Returns a renderable array of question feedback. | |
QuizQuestionResponse:: |
protected | function | Utility function that returns the format of the node body | |
QuizQuestionResponse:: |
public | function | Returns stored max score if it exists, if not the max score is calculated and returned. | |
QuizQuestionResponse:: |
function | |||
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. | 2 |
QuizQuestionResponse:: |
public | function | 2 | |
QuizQuestionResponse:: |
public | function | Implementation of getReportFormScore | |
QuizQuestionResponse:: |
public | function | Get the submit function for the reportForm | 2 |
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. | 2 | |
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 | Validates response from a quiz taker. If the response isn't valid the quiz taker won't be allowed to proceed. | |
QuizQuestionResponse:: |
public | function | Used to refresh this instances question node in case drupal has changed it. | |
QuizQuestionResponse:: |
public | function | Set the target result ID for this Question response. | |
QuizQuestionResponse:: |
function | Represent the response as a stdClass object. | ||
TrueFalseResponse:: |
public | function |
Implementation of delete Overrides QuizQuestionResponse:: |
|
TrueFalseResponse:: |
public | function |
Implementation of getReportFormResponse Overrides QuizQuestionResponse:: |
|
TrueFalseResponse:: |
public | function |
Implementation of getResponse Overrides QuizQuestionResponse:: |
|
TrueFalseResponse:: |
public | function | Implementation of getCorrectAnswer | |
TrueFalseResponse:: |
public | function |
Implementation of save Overrides QuizQuestionResponse:: |
|
TrueFalseResponse:: |
public | function |
Implementation of score Overrides QuizQuestionResponse:: |
|
TrueFalseResponse:: |
public | function |
Constructor Overrides QuizQuestionResponse:: |