You are here

function multichoice_store_answer in Quiz 6.6

Same name and namespace in other branches
  1. 5.2 multichoice.module \multichoice_store_answer()
  2. 6.2 multichoice.module \multichoice_store_answer()
  3. 6.3 question_types/multichoice/multichoice.module \multichoice_store_answer()
  4. 6.5 question_types/multichoice/multichoice.module \multichoice_store_answer()

Store one response to a multichoice question.

Parameters

$nid: Question node id.

$vid: Question node revision id.

$rid: Result id.

$answer_id: The answer id.

$numanswers: Number of answers expected. (Unused)

1 call to multichoice_store_answer()
multichoice_evaluate_question in question_types/multichoice/multichoice.module
Evaluate whether a question is correct.

File

question_types/multichoice/multichoice.module, line 930
Multiple choice question type for the Quiz module.

Code

function multichoice_store_answer($nid, $vid, $rid, $answer_id, $numanswers = 1) {
  db_query("INSERT INTO {quiz_multichoice_user_answers} (question_nid, question_vid, result_id, answer_id)\n     VALUES (%d, %d, %d, %d)", $nid, $vid, $rid, $answer_id);

  /*
  $result = db_result(db_query(
  "SELECT COUNT('result_id') AS count FROM {quiz_multichoice_user_answers}
  WHERE question_nid = %d AND question_vid = %d AND result_id = %d",
  $nid,
  $vid,
  $rid
  ));
  // If there are N results for this nid/vid/rid and the number of total answers is also N,
  // then update instead of inserting. When, exactly, would this case obtain? It is impossible
  // to answer the same question with the same answer twice, and we must delete retries before
  // re-marking the quiz. :. This is unnecessary:
  if (!empty($result) && $result == $numanswers) {
  //drupal_set_message("Updating");
  db_query(
  "UPDATE {quiz_multichoice_user_answers} SET answer_id = %d
  WHERE question_nid = %d AND question_vid = %d AND result_id = %d",
  $answer_id,
  $nid,
  $vid,
  $rid
  );
  }
  else {
  db_query(
  "INSERT INTO {quiz_multichoice_user_answers} (question_nid, question_vid, result_id, answer_id)
  VALUES (%d, %d, %d, %d)",
  $nid,
  $vid,
  $rid,
  $answer_id
  );
  }
  */
}