You are here

function short_answer_score_an_answer in Quiz 6.6

Same name and namespace in other branches
  1. 8.4 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
  2. 6.3 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
  3. 6.4 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
  4. 6.5 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
  5. 7.6 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
  6. 7 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
  7. 7.4 question_types/short_answer/short_answer.module \short_answer_score_an_answer()
  8. 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

$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.

Return value

int Number of scores adjusted. If a change was made, this should be 1.

1 call to short_answer_score_an_answer()
short_answer_score_form_submit in question_types/short_answer/short_answer.admin.inc

File

question_types/short_answer/short_answer.module, line 121
The main file for short_answer.

Code

function short_answer_score_an_answer($quiz, $nid, $vid, $rid, $score) {

  // See long_answer.module for details on how this works.
  db_query("UPDATE {quiz_short_answer_user_answers} SET score = %d, is_evaluated = 1 WHERE question_nid = %d AND question_vid = %d AND result_id = %d", $score, $nid, $vid, $rid);
  $changed = db_affected_rows();
  if ($changed > 0) {

    // What do we do about the quiz_node_results_answers table? It assumes strict
    // bivalence (is_correct). I guess we consider any essay with over 50% to be correct?
    $max = db_result(db_query('SELECT maximum_score FROM {quiz_short_answer_node_properties} WHERE vid = %d', $vid));
    if ($max <= 0) {
      $is_correct = 0;
      $points_awarded = 0;
    }
    else {
      $is_correct = $score / $max > 0.5 ? 1 : 0;
      $points_awarded = $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, $vid, $rid);

    // Third, we update the main quiz results table
    quiz_update_total_score($quiz, $rid);
  }
  return $changed;
}