class LongAnswerResponse in Quiz 6.3
Same name and namespace in other branches
- 6.6 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
- 7.5 question_types/long_answer/long_answer.classes.inc \LongAnswerResponse
Hierarchy
- class \AbstractQuizQuestionResponse implements 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 - Implementation of hook_quiz_question_info().
File
- question_types/
long_answer/ long_answer.classes.inc, line 108 - Long answer classes.
View source
class LongAnswerResponse extends AbstractQuizQuestionResponse {
/**
* Get all quiz scores that have not yet been evaluated.
*
* @param $count
* Number of items to return (default: 50).
* @param $offset
* Where in the results we should start (default: 0).
*
* @return
* Array of objects describing unanswered questions. Each object will have result_id, question_nid, and question_vid.
*/
public static function fetchAllUnscoredAnswers($count = 50, $offset = 0) {
$sql = 'SELECT a.result_id, a.question_nid, a.question_vid, r.title, n.time_end, n.time_start, n.uid
FROM {quiz_long_answer_user_answers} AS a
INNER JOIN {node_revisions} AS r ON a.question_vid = r.vid
INNER JOIN {quiz_node_results} AS n ON a.result_id = n.result_id
WHERE a.is_evaluated = 0';
$results = db_query_range($sql, $offset, $count);
$unscored = array();
if ($results) {
while ($row = db_fetch_object($results)) {
$unscored[] = $row;
}
}
return $unscored;
}
/**
* Given a quiz, return a list of all of the unscored answers.
*
* @param $nid
* Node ID for the quiz to check.
* @param $vid
* Version ID for the quiz to check.
* @param $count
* Number of items to return (default: 50).
* @param $offset
* Where in the results we should start (default: 0).
*
* @return
* Indexed array of result IDs that need to be scored.
*/
public static function fetchUnscoredAnswersByQuestion($nid, $vid, $count = 50, $offset = 0) {
$results = db_query_range('SELECT result_id FROM {quiz_long_answer_user_answers} WHERE is_evaluated = 0 AND question_nid = %d AND question_vid = %d', $nid, $vid, $offset, $count);
$unscored = array();
foreach (db_fetch_object($results) as $row) {
$unscored[] = $row->result_id;
}
return $unscored;
}
/**
* ID of the answer.
*/
protected $answer_id = 0;
public function __construct($rid, $question, $answer = NULL) {
$this->rid = $rid;
$this->question = $question;
if (!isset($answer)) {
$sql = "SELECT answer_id, answer, is_evaluated, score, question_vid, question_nid, result_id\n FROM {quiz_long_answer_user_answers}\n WHERE question_nid = %d AND question_vid = %d AND result_id = %d";
$r = db_fetch_object(db_query($sql, $question->nid, $question->vid, $rid));
if (!empty($r)) {
$this->answer = $r->answer;
$this->score = $r->score;
$this->evaluated = $r->is_evaluated;
$this->answer_id = $r->answer_id;
}
}
else {
$this->answer = $answer;
}
}
public function save() {
$sql = "INSERT INTO {quiz_long_answer_user_answers} (answer, question_nid, question_vid, result_id) VALUES ('%s', %d, %d, %d)";
db_query($sql, $this->answer, $this->question->nid, $this->question->vid, $this->rid);
$this->answer_id = db_last_insert_id('quiz_long_answer_user_answers', 'answer_id');
}
public function delete() {
$sql = 'DELETE FROM {quiz_long_answer_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);
}
public function score() {
$sql = "SELECT score FROM {quiz_long_answer_user_answers} WHERE result_id = %d AND question_vid = %d";
$score = (int) db_result(db_query($sql, $this->rid, $this->question->vid));
$this->score = $score;
return $score;
}
public function isCorrect() {
$possible = _quiz_question_get_instance($this->question)
->getMaximumScore();
$actual = $this->score;
// To prevent Division by zero warning
$possible = $possible == 0 ? 1 : $possible;
return $actual / $possible * 100 > 50;
}
public function getResponse() {
return $this->answer;
}
public function formatReport($showpoints = TRUE, $showfeedback = TRUE) {
$slug = '<div class="quiz_summary_question"><span class="quiz_question_bullet">' . t('Q:') . '</span> ' . check_markup($this->question->body, $this->question->filter) . '</div>';
$result = '<div class="quiz_answer_feedback">';
if ($this->question && !empty($this->question->answers)) {
$answer = (object) current($this->question->answers);
if ($answer->is_evaluated == 1) {
// Show score:
if ($showpoints) {
$args = array(
'@yours' => $answer->score,
'@total' => $this->question->maximum_score,
);
$result .= t('Score: @yours of @total possible points', $args);
}
// Show feedback, if any.
if ($showfeedback && !empty($answer->feedback)) {
$result .= '</div><div class="quiz_answer_feedback">' . check_markup($answer->feedback, $this->question->format);
}
}
else {
$result .= t('This answer has not yet been scored.') . '<br/>' . t('Until the answer is scored, the total score will not be correct.');
}
if (user_access('score long answer')) {
$path = sprintf('admin/quiz/score-long-answer/%s/%s', $this->question->vid, $this->rid);
$result .= '<p>' . l(t('Score this answer'), $path) . '</p>';
}
}
else {
$result .= t('This question was not answered.');
}
$result .= '</div>';
return $slug . $result;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AbstractQuizQuestionResponse:: |
protected | property | ||
AbstractQuizQuestionResponse:: |
protected | property | ||
AbstractQuizQuestionResponse:: |
public | property | ||
AbstractQuizQuestionResponse:: |
protected | property | ||
AbstractQuizQuestionResponse:: |
public | property | ||
AbstractQuizQuestionResponse:: |
public | property | ||
AbstractQuizQuestionResponse:: |
public | function |
Get data suitable for reporting a user's score on the question.
This expects an object with the following attributes: Overrides QuizQuestionResponse:: |
|
AbstractQuizQuestionResponse:: |
function |
Get the integer score. Overrides QuizQuestionResponse:: |
||
AbstractQuizQuestionResponse:: |
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. Overrides QuizQuestionResponse:: |
|
AbstractQuizQuestionResponse:: |
function |
Repesent the response as a stdClass object. Overrides QuizQuestionResponse:: |
||
LongAnswerResponse:: |
protected | property | ID of the answer. | |
LongAnswerResponse:: |
public | function |
Delete the response. Overrides QuizQuestionResponse:: |
|
LongAnswerResponse:: |
public static | function | Get all quiz scores that have not yet been evaluated. | |
LongAnswerResponse:: |
public static | function | Given a quiz, return a list of all of the unscored answers. | |
LongAnswerResponse:: |
public | function |
Return an HTML marked-up report for displaying the results of this question. Overrides QuizQuestionResponse:: |
|
LongAnswerResponse:: |
public | function |
Get the user's response. Overrides QuizQuestionResponse:: |
|
LongAnswerResponse:: |
public | function |
Check to see if the answer is marked as correct. Overrides AbstractQuizQuestionResponse:: |
|
LongAnswerResponse:: |
public | function |
Save the current response. Overrides QuizQuestionResponse:: |
|
LongAnswerResponse:: |
public | function |
Calculate the score for the response.
This MUST set the $score instance variable. Overrides QuizQuestionResponse:: |
|
LongAnswerResponse:: |
public | function |
Create a new user response. Overrides QuizQuestionResponse:: |