You are here

function quiz_copy_questions in Quiz 6.4

Same name and namespace in other branches
  1. 8.6 quiz.module \quiz_copy_questions()
  2. 8.4 quiz.module \quiz_copy_questions()
  3. 8.5 quiz.module \quiz_copy_questions()
  4. 7.6 quiz.module \quiz_copy_questions()
  5. 7 quiz.module \quiz_copy_questions()
  6. 7.4 quiz.module \quiz_copy_questions()
  7. 7.5 quiz.module \quiz_copy_questions()

Copies questions when a quiz is translated.

Parameters

$node: The new translated quiz node.

1 call to quiz_copy_questions()
quiz_insert in ./quiz.module
Implementation of hook_insert().

File

./quiz.module, line 3786
Quiz Module

Code

function quiz_copy_questions($node) {

  // Find original questions.
  $sql = 'SELECT child_nid, child_vid, question_status, weight, max_score
          FROM {quiz_node_relationship}
          WHERE parent_vid = %d';
  $res = db_query($sql, $node->translation_source->vid);
  while ($res_o = db_fetch_object($res)) {
    $original_question = node_load($res_o->child_nid);

    // Set variables we can't or won't carry with us to the translated node to
    // NULL.
    $original_question->nid = $original_question->vid = $original_question->created = $original_question->changed = NULL;
    $original_question->revision_timestamp = $original_question->menu = $original_question->path = NULL;
    $original_question->files = array();
    if (isset($original_question->book['mlid'])) {
      $original_question->book['mlid'] = NULL;
    }

    // Set the correct language.
    $original_question->language = $node->language;

    // Save the node.
    node_save($original_question);

    // Save the relationship between the new question and the quiz.
    $sql = 'INSERT INTO {quiz_node_relationship}
            (parent_nid, parent_vid, child_nid, child_vid, question_status, weight, max_score)
            VALUES(%d, %d, %d, %d, %d, %d, %d)';
    db_query($sql, $node->nid, $node->vid, $original_question->nid, $original_question->vid, $res_o->question_status, $res_o->weight, $res_o->max_score);
  }
}