You are here

function multichoice_insert in Quiz 5.2

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

Implementation of hook_insert().

File

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

Code

function multichoice_insert(&$node) {
  $node->number_of_answers = multichoice_get_number_of_corrects($node->answers);
  $quiz_vid = $node->quiz_vid;
  $question_vid = $node->vid;

  // Instead of just storing whether a question has multiple answers,
  // we will store the actual number of correct answers.
  db_query("INSERT INTO {quiz_node_question_properties} (nid, vid, number_of_answers) VALUES(%d, %d, %d)", $node->nid, $question_vid, $node->number_of_answers);

  // We came from editing a quiz, so we should add this question to the quiz directly.
  if ($node->quiz_id > 0) {
    db_query('INSERT INTO {quiz_node_relationship} ' . '(parent_nid, parent_vid, child_nid, child_vid, question_status) VALUES (%d, %d, %d, %d, %d)', $node->quiz_id, $quiz_vid, $node->nid, $node->vid, QUESTION_ALWAYS);
  }
  foreach ($node->answers as $value) {
    if (trim($value['answer']) != "") {
      db_query("INSERT INTO {quiz_multichoice_answers} " . "(answer_id, nid, vid, answer, feedback, is_correct, result_option) VALUES (%d, %d, %d, '%s', '%s', %d, %d)", db_next_id('{quiz_multichoice_answers}_answer_id'), $node->nid, $question_vid, $value['answer'], $value['feedback'], $value['correct'], $value['result_option']);
    }
  }
}