function short_answer_score_an_answer in Quiz 6.4
Same name and namespace in other branches
- 8.4 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
- 6.6 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
- 6.3 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
- 6.5 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
- 7.6 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
- 7 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
- 7.4 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
- 7.5 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
Set a score for a short answer question.
This stores a score for a short answer question and marks that question as having been evaluated. The function updates all of the necessary data sources so that the individual answer results should be reflected in the total scoring table.
Parameters
array $values: quiz => Quiz node, nid => Node ID of question. vid => Version ID of question. rid => Result ID for the quiz results. score => The numeric score to assign the result. max_score => The max score for this question
$update_total: Shall the total score be updated?
Return value
int Number of scores adjusted. If a change was made, this should be 1.
2 calls to short_answer_score_an_answer()
- short_answer_report_submit in question_types/
short_answer/ short_answer.module - Submit the result report for short answer
- short_answer_score_form_submit in question_types/
short_answer/ short_answer.admin.inc - Submit the score form
File
- question_types/
short_answer/ short_answer.module, line 138 - The main file for short_answer.
Code
function short_answer_score_an_answer($values, $update_total = TRUE) {
// When we set the score we make sure that the max score in the quiz the question belongs to is considered
db_query("UPDATE {quiz_short_answer_user_answers}\n SET score = %d * (\n SELECT max_score\n FROM {quiz_question_properties}\n WHERE vid = %d\n ) / %d, is_evaluated = 1, answer_feedback = '%s'\n WHERE question_nid = %d\n AND question_vid = %d\n AND result_id = %d", $values['score'], $values['vid'], $values['max_score'], $values['answer_feedback'], $values['nid'], $values['vid'], $values['rid']);
$changed = db_affected_rows();
// Now the short answer user data has been updated. We also need to update the data in the quiz tables
if ($changed > 0) {
$max = db_result(db_query('SELECT max_score FROM {quiz_question_properties} WHERE vid = %d', $values['vid']));
if ($max <= 0) {
$is_correct = 0;
$points_awarded = 0;
}
else {
$is_correct = $values['score'] / $max > 0.5 ? 1 : 0;
$points_awarded = $values['score'];
}
$sql = 'UPDATE {quiz_node_results_answers}
SET points_awarded = %d, is_correct = %d
WHERE question_vid = %d AND result_id = %d';
db_query($sql, $points_awarded, $is_correct, $values['vid'], $values['rid']);
// Third, we update the main quiz results table
if ($update_total) {
quiz_update_total_score($values['quiz'], $values['rid']);
}
}
return $changed;
}