class ShortAnswerResponse in Quiz 7.5
Same name and namespace in other branches
- 6.6 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse
- 6.3 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse
- 6.4 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse
- 6.5 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse
- 7.6 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse
- 7 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse
- 7.4 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse
Extension of QuizQuestionResponse.
Hierarchy
- class \QuizQuestionResponse
- class \ShortAnswerResponse
Expanded class hierarchy of ShortAnswerResponse
1 string reference to 'ShortAnswerResponse'
- short_answer_quiz_question_info in question_types/
short_answer/ short_answer.module - Implements hook_quiz_question_info().
File
- question_types/
short_answer/ short_answer.classes.inc, line 270 - Short answer classes.
View source
class ShortAnswerResponse extends QuizQuestionResponse {
/**
* ID of the answer.
*/
protected $answer_id = 0;
private $answer_feedback;
private $answer_feedback_format;
/**
* Constructor.
*
* @param int $result_id
* The result ID for the user's result set. There is one result ID per time
* the user takes a quiz.
* @param stdClass $question_node
* The question node.
* @param mixed $answer
* The answer (dependent on question type).
*/
public function __construct($result_id, stdClass $question_node, $answer = NULL) {
parent::__construct($result_id, $question_node, $answer);
if (!isset($answer)) {
$r = db_query('SELECT *
FROM {quiz_short_answer_user_answers}
WHERE result_answer_id = :raid', array(
':raid' => $this->result_answer_id,
))
->fetch();
if (!empty($r)) {
$this->answer = $r->answer;
$this->score = $r->score;
$this->evaluated = $r->is_evaluated;
$this->answer_id = $r->answer_id;
$this->answer_feedback = $r->answer_feedback;
$this->answer_feedback_format = $r->answer_feedback_format;
}
}
else {
if (is_array($answer)) {
$this->answer = $answer['answer'];
}
else {
$this->answer = $answer;
$this->evaluated = $this->question->correct_answer_evaluation != ShortAnswerQuestion::ANSWER_MANUAL;
}
}
}
/**
* Implementation of save().
*
* @see QuizQuestionResponse::save()
*/
public function save() {
// We need to set is_evaluated depending on whether the type requires
// evaluation.
$this->is_evaluated = (int) ($this->question->correct_answer_evaluation != ShortAnswerQuestion::ANSWER_MANUAL);
db_merge('quiz_short_answer_user_answers')
->key(array(
'result_answer_id' => $this->result_answer_id,
))
->fields(array(
'answer' => $this->answer,
'result_answer_id' => $this->result_answer_id,
'score' => $this
->getScore(FALSE),
'is_evaluated' => $this->is_evaluated,
))
->execute();
}
/**
* Implementation of delete().
*
* @see QuizQuestionResponse::delete()
*/
public function delete() {
db_delete('quiz_short_answer_user_answers')
->condition('result_answer_id', $this->result_answer_id)
->execute();
}
/**
* Implementation of score().
*
* @see QuizQuestionResponse::score()
*/
public function score() {
// Manual scoring means we go with what is in the DB.
if ($this->question->correct_answer_evaluation == ShortAnswerQuestion::ANSWER_MANUAL) {
$score = db_query('SELECT score FROM {quiz_short_answer_user_answers} WHERE result_answer_id = :raid', array(
':raid' => $this->result_answer_id,
))
->fetchField();
if (!$score) {
$score = 0;
}
}
else {
$shortAnswer = new ShortAnswerQuestion($this->question);
$score = $shortAnswer
->evaluateAnswer($this
->getResponse());
}
return $score;
}
/**
* Implementation of getResponse().
*
* @see QuizQuestionResponse::getResponse()
*/
public function getResponse() {
return $this->answer;
}
/**
* Implementation of getFeedbackValues().
*
* @see QuizQuestionResponse::getFeedbackValues()
*/
public function getFeedbackValues() {
$data = array();
$score = $this
->score();
$max = $this
->getMaxScore(FALSE);
if ($this->evaluated) {
// Question has been graded.
if ($score == 0) {
$icon = quiz_icon('incorrect');
}
if ($score > 0) {
$icon = quiz_icon('almost');
}
if ($score == $max) {
$icon = quiz_icon('correct');
}
}
else {
$icon = quiz_icon('unknown');
}
$data[] = array(
// Hide this column. Does not make sense for short answer as there are no
// choices.
'choice' => NULL,
'attempt' => $this->answer,
'correct' => $icon,
'score' => !$this->evaluated ? t('This answer has not yet been scored.') : $this
->getScore(),
'answer_feedback' => check_markup($this->answer_feedback, $this->answer_feedback_format),
'solution' => $this->question->correct_answer,
);
return $data;
}
/**
* Implementation of getReportFormAnswerFeedback().
*
* @see QuizQuestionResponse::getReportFormAnswerFeedback()
*/
public function getReportFormAnswerFeedback() {
return array(
'#title' => t('Enter feedback'),
'#type' => 'text_format',
'#default_value' => $this->answer_feedback,
'#format' => isset($this->answer_feedback_format) ? $this->answer_feedback_format : filter_default_format(),
'#attributes' => array(
'class' => array(
'quiz-report-score',
),
),
);
}
/**
* Implementation of getReportFormSubmit().
*
* @see QuizQuestionResponse::getReportFormSubmit()
*/
public function getReportFormSubmit() {
return 'short_answer_report_submit';
}
}
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 | 9 | |
QuizQuestionResponse:: |
public | function | Can the quiz taker view the requested review? | |
QuizQuestionResponse:: |
protected | function | Utility function that returns the format of the node body. | |
QuizQuestionResponse:: |
public | function | Get the max score of this question response. | 1 |
QuizQuestionResponse:: |
public | function | Get the question of this question response. | |
QuizQuestionResponse:: |
public | function | Get data suitable for reporting a user's score on the question. | 1 |
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 | Implementation of getReportFormScore(). | |
QuizQuestionResponse:: |
public | function | Get the validate function for the reportForm. | |
QuizQuestionResponse:: |
public | function | Get the score of this question response. | |
QuizQuestionResponse:: |
public | function | Get the weighted score ratio. | |
QuizQuestionResponse:: |
public | function | Check to see if the answer is marked as correct. | 2 |
QuizQuestionResponse:: |
public | function | Indicate whether the response has been evaluated (scored) yet. | |
QuizQuestionResponse:: |
public | function | Used to refresh this instances question node in case drupal has changed it. | |
QuizQuestionResponse:: |
public | function | Set the target result answer ID for this Question response. | |
QuizQuestionResponse:: |
public | function | Represent the response as a stdClass object. | |
QuizQuestionResponse:: |
public static | function | Get answers for a question in a result. | 3 |
ShortAnswerResponse:: |
private | property | ||
ShortAnswerResponse:: |
private | property | ||
ShortAnswerResponse:: |
protected | property | ID of the answer. | |
ShortAnswerResponse:: |
public | function |
Implementation of delete(). Overrides QuizQuestionResponse:: |
|
ShortAnswerResponse:: |
public | function |
Implementation of getFeedbackValues(). Overrides QuizQuestionResponse:: |
|
ShortAnswerResponse:: |
public | function |
Implementation of getReportFormAnswerFeedback(). Overrides QuizQuestionResponse:: |
|
ShortAnswerResponse:: |
public | function |
Implementation of getReportFormSubmit(). Overrides QuizQuestionResponse:: |
|
ShortAnswerResponse:: |
public | function |
Implementation of getResponse(). Overrides QuizQuestionResponse:: |
|
ShortAnswerResponse:: |
public | function |
Implementation of save(). Overrides QuizQuestionResponse:: |
|
ShortAnswerResponse:: |
public | function |
Implementation of score(). Overrides QuizQuestionResponse:: |
|
ShortAnswerResponse:: |
public | function |
Constructor. Overrides QuizQuestionResponse:: |