From f57afdd88278674d177d1631767a479dd1ae4e0d Mon Sep 17 00:00:00 2001 From: michaelk Date: Mon, 3 Dec 2012 17:30:38 -0800 Subject: [PATCH] Allow Quiz nodes to be cloned with the node_clone module and maintain their associated questions --- quiz.module | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/quiz.module b/quiz.module index 4612590..f253beb 100644 --- a/quiz.module +++ b/quiz.module @@ -683,6 +683,21 @@ function quiz_insert($node) { quiz_copy_questions($node); } + // Add references to all the questions belonging to the quiz if this is a cloned quiz (node_clone compatibility) + if ($node->is_new && isset($node->clone_from_original_nid)) { + $old_quiz = node_load($node->clone_from_original_nid); + + $questions = quiz_get_questions($old_quiz->nid, $old_quiz->vid, TRUE, TRUE, FALSE, TRUE); + + // Format the current questions for referencing + foreach ($questions as $nid => $q) { + $questions[$nid]->state = $q->question_status; + $questions[$nid]->refresh = 0; + } + + quiz_set_questions($node, $questions); + } + _quiz_common_presave_actions($node); // If the quiz is saved as not randomized we have to make sure that questions belonging to the quiz are saved as not random @@ -697,6 +712,7 @@ function quiz_insert($node) { 'nid' => $node->nid, 'aid' => !empty($node->aid) ? $node->aid : 0, 'number_of_random_questions' => $node->number_of_random_questions, + 'max_score_for_random' => $node->max_score_for_random, 'randomization' => $node->randomization, 'backwards_navigation' => $node->backwards_navigation, 'repeat_until_correct' => $node->repeat_until_correct, @@ -3022,8 +3038,9 @@ function quiz_set_questions(&$quiz, $questions, $set_new_revision = FALSE) { if ($set_new_revision) { // Create a new Quiz VID, even if nothing changed. $quiz->revision = 1; + + node_save($quiz); } - node_save($quiz); // When node_save() calls all of the node API hooks, old quiz info is // automatically inserted into quiz_node_relationship. We could get clever and -- 1.7.3.1.msysgit.0