function multichoice_update in Quiz 5
Same name and namespace in other branches
- 5.2 multichoice.module \multichoice_update()
- 6.6 question_types/multichoice/multichoice.module \multichoice_update()
- 6.2 multichoice.module \multichoice_update()
- 6.3 question_types/multichoice/multichoice.module \multichoice_update()
- 6.5 question_types/multichoice/multichoice.module \multichoice_update()
Implementation of hook_update().
File
- ./
multichoice.module, line 238 - Multiple choice question type for quiz module
Code
function multichoice_update($node) {
db_query("UPDATE {quiz_question} SET properties = '%s' WHERE nid = %d", serialize(array(
'multiple_answers' => $node->multiple_answers,
)), $node->nid);
while (list($key, $value) = each($node->answers)) {
if ($value['aid']) {
$value['answer'] = trim($value['answer']);
if ($value['delete'] == 1 || !isset($value['answer']) || $value['answer'] == '') {
//Delete this entry
db_query("DELETE FROM {quiz_question_answer} WHERE aid = %d", $value['aid']);
}
else {
//Update this entry
db_query("UPDATE {quiz_question_answer} SET answer = '%s', feedback = '%s', points = %s WHERE aid = %d", $value['answer'], $value['feedback'], $value['correct'], $value['aid']);
}
}
else {
if (trim($value['answer']) != "") {
//If there is an answer, insert a new row
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']);
}
}
}
}