You are here

function quiz_copy_questions in Quiz 7.6

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. 6.4 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
Implements hook_insert().

File

./quiz.module, line 3348
quiz.module Main file for the Quiz module.

Code

function quiz_copy_questions($node) {

  // Find original questions.
  $query = db_query('SELECT child_nid, child_vid, question_status, weight, max_score, auto_update_max_score
    FROM {quiz_node_relationship}
    WHERE parent_vid = :parent_vid', array(
    ':parent_vid' => $node->translation_source->vid,
  ));
  foreach ($query as $res_o) {
    $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.
    $quiz_question_relationship = (object) array(
      'parent_nid' => $node->nid,
      'parent_vid' => $node->vid,
      'child_nid' => $original_question->nid,
      'child_vid' => $original_question->vid,
      'question_status' => $res_o->question_status,
      'weight' => $res_o->weight,
      'max_score' => $res_o->max_score,
      'auto_update_max_score' => $res_o->auto_update_max_score,
    );
    entity_save('quiz_question_relationship', $quiz_question_relationship);
  }
}