function multichoice_insert in Quiz 6.5
Same name and namespace in other branches
- 5.2 multichoice.module \multichoice_insert()
- 5 multichoice.module \multichoice_insert()
- 6.6 question_types/multichoice/multichoice.module \multichoice_insert()
- 6.2 multichoice.module \multichoice_insert()
- 6.3 question_types/multichoice/multichoice.module \multichoice_insert()
Implementation of hook_insert().
File
- question_types/
multichoice/ multichoice.module, line 532 - 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;
//$multi_answer = $quiz->multiple_answers ? 1 : 0;
// 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, isset($node->question_status) ? $node->question_status : QUESTION_ALWAYS);
}
foreach ($node->answers as $value) {
// Result options are for personality questions.
if (!isset($value['result_option'])) {
$value['result_option'] = 0;
}
if (!isset($value['correct'])) {
$value['correct'] = 0;
}
if (trim($value['answer']) != "") {
db_query("INSERT INTO {quiz_multichoice_answers} (nid, vid, answer, feedback, is_correct, result_option)\n VALUES (%d, %d, '%s', '%s', %d, %d)", $node->nid, $question_vid, $value['answer'], $value['feedback'], $value['correct'], $value['result_option']);
}
}
}