You are here

function multichoice_insert in Quiz 5

Same name and namespace in other branches
  1. 5.2 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 221
Multiple choice question type for quiz module

Code

function multichoice_insert(&$node) {
  db_query("INSERT INTO {quiz_question} (nid, properties) VALUES(%d, '%s')", $node->nid, serialize(array(
    'multiple_answers' => $node->multiple_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_questions} (quiz_nid, question_nid, question_status) VALUES (%d, %d, %d)', $node->quiz_id, $node->nid, QUESTION_ALWAYS);
  }
  while (list($key, $value) = each($node->answers)) {
    if (trim($value['answer']) != "") {
      db_query("INSERT INTO {quiz_question_answer} (aid, question_nid, answer, feedback, points) VALUES(%d, %d, '%s', '%s', %d)", db_next_id('{quiz_question_answer}_aid'), $node->nid, $value['answer'], $value['feedback'], $value['correct']);
    }
  }
}