class LongAnswerResponse in Quiz 7.5
Same name and namespace in other branches
- 6.6 question_types/long_answer/long_answer.classes.inc \LongAnswerResponse
- 6.3 question_types/long_answer/long_answer.classes.inc \LongAnswerResponse
- 6.4 question_types/long_answer/long_answer.classes.inc \LongAnswerResponse
- 6.5 question_types/long_answer/long_answer.classes.inc \LongAnswerResponse
- 7.6 question_types/long_answer/long_answer.classes.inc \LongAnswerResponse
- 7 question_types/long_answer/long_answer.classes.inc \LongAnswerResponse
- 7.4 question_types/long_answer/long_answer.classes.inc \LongAnswerResponse
Extension of QuizQuestionResponse.
Hierarchy
- class \QuizQuestionResponse
- class \LongAnswerResponse
Expanded class hierarchy of LongAnswerResponse
1 string reference to 'LongAnswerResponse'
- 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 201 - Long answer classes.
View source
class LongAnswerResponse 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)) {
// Question has been answered already. We fetch the answer data from the
// database.
$r = db_query('SELECT *
FROM {quiz_long_answer_user_answers}
WHERE result_answer_id = :raid', array(
':raid' => $this->result_answer_id,
))
->fetch();
if (!empty($r)) {
$this->answer = $r->answer;
$this->answer_format = $r->answer_format;
$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 {
$this->answer = $answer;
$this->evaluated = FALSE;
}
}
/**
* Implementation of save().
*
* @see QuizQuestionResponse::save()
*/
public function save() {
if (!$this->quizQuestion->node->answer_text_processing) {
$answer = $this->answer;
$this->answer = array();
$this->answer['value'] = $answer;
$this->answer['format'] = 'plain_text';
}
db_merge('quiz_long_answer_user_answers')
->key(array(
'result_answer_id' => $this->result_answer_id,
))
->fields(array(
'answer' => $this->answer['value'],
'answer_format' => $this->answer['format'],
'result_answer_id' => $this->result_answer_id,
))
->execute();
}
/**
* Implementation of delete().
*
* @see QuizQuestionResponse::delete()
*/
public function delete() {
db_delete('quiz_long_answer_user_answers')
->condition('result_answer_id', $this->result_answer_id)
->execute();
}
/**
* Implementation of score().
*
* @see QuizQuestionResponse::score()
*/
public function score() {
return (int) db_query('SELECT score FROM {quiz_long_answer_user_answers}
WHERE result_answer_id = :raid', array(
':raid' => $this->result_answer_id,
))
->fetchField();
}
/**
* 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 long answer as there are no
// choices.
'choice' => NULL,
'attempt' => check_markup($this->answer, $this->answer_format),
'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' => check_markup($this->question->rubric['value'], $this->question->rubric['format']),
);
return $data;
}
/**
* Implementation of getReportFormAnswerFeedback().
*
* @see QuizQuestionResponse::getReportFormAnswerFeedback()
*/
public function getReportFormAnswerFeedback() {
return array(
'#title' => t('Enter feedback'),
'#type' => 'text_format',
'#default_value' => isset($this->answer_feedback) ? check_markup($this->answer_feedback, $this->answer_feedback_format) : '',
'#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 'long_answer_report_submit';
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LongAnswerResponse:: |
private | property | ||
LongAnswerResponse:: |
private | property | ||
LongAnswerResponse:: |
protected | property | ID of the answer. | |
LongAnswerResponse:: |
public | function |
Implementation of delete(). Overrides QuizQuestionResponse:: |
|
LongAnswerResponse:: |
public | function |
Implementation of getFeedbackValues(). Overrides QuizQuestionResponse:: |
|
LongAnswerResponse:: |
public | function |
Implementation of getReportFormAnswerFeedback(). Overrides QuizQuestionResponse:: |
|
LongAnswerResponse:: |
public | function |
Implementation of getReportFormSubmit(). Overrides QuizQuestionResponse:: |
|
LongAnswerResponse:: |
public | function |
Implementation of getResponse(). Overrides QuizQuestionResponse:: |
|
LongAnswerResponse:: |
public | function |
Implementation of save(). Overrides QuizQuestionResponse:: |
|
LongAnswerResponse:: |
public | function |
Implementation of score(). Overrides QuizQuestionResponse:: |
|
LongAnswerResponse:: |
public | function |
Constructor. Overrides QuizQuestionResponse:: |
|
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 |