You are here

function quiz_update_quiz_question_relationship in Quiz 7

Same name and namespace in other branches
  1. 8.4 quiz.module \quiz_update_quiz_question_relationship()
  2. 5.2 quiz.module \quiz_update_quiz_question_relationship()
  3. 6.6 quiz.module \quiz_update_quiz_question_relationship()
  4. 6.2 quiz.module \quiz_update_quiz_question_relationship()
  5. 6.3 quiz.module \quiz_update_quiz_question_relationship()
  6. 6.4 quiz.module \quiz_update_quiz_question_relationship()
  7. 6.5 quiz.module \quiz_update_quiz_question_relationship()
  8. 7.6 quiz.module \quiz_update_quiz_question_relationship()
  9. 7.4 quiz.module \quiz_update_quiz_question_relationship()
  10. 7.5 quiz.module \quiz_update_quiz_question_relationship()

Copies quiz-question relation entries in the quiz_node_relationship table from an old version of a quiz to a new.

Parameters

$old_quiz_vid: The quiz vid prior to a new revision.

$new_quiz_vid: The quiz vid of the latest revision.

$quiz_nid: The quiz node id.

Related topics

1 call to quiz_update_quiz_question_relationship()
quiz_update in ./quiz.module
Implements hook_update().

File

./quiz.module, line 1705
Quiz Module

Code

function quiz_update_quiz_question_relationship($old_quiz_vid, $new_quiz_vid, $quiz_nid) {

  /*
    $sql = "INSERT INTO {quiz_node_relationship} (parent_nid, parent_vid, child_nid, child_vid, question_status, weight, max_score)
            SELECT src.parent_nid, %d, src.child_nid, src.child_vid, src.question_status, src.weight, src.max_score
            FROM {quiz_node_relationship} AS src
            WHERE src.parent_vid = %d AND src.parent_nid = %d AND src.question_status != %d";
    // TODO Please convert this statement to the D7 database API syntax.
    /* db_query($sql, $new_quiz_vid, $old_quiz_vid, $quiz_nid, QUESTION_NEVER) */
  $quiz_questions = db_select('quiz_node_relationship', 'qnr')
    ->fields('qnr', array(
    'parent_nid',
    'child_nid',
    'child_vid',
    'question_status',
    'weight',
    'max_score',
  ))
    ->condition('parent_vid', $old_quiz_vid)
    ->condition('parent_nid', $quiz_nid)
    ->condition('question_status', QUESTION_NEVER)
    ->execute()
    ->fetchAll();
  $query = db_insert('quiz_node_relationship')
    ->fields(array(
    'parent_nid',
    'child_nid',
    'child_vid',
    'question_status',
    'weight',
    'max_score',
    'parent_vid',
  ));
  foreach ($quiz_questions as $quiz_question) {
    $value = array(
      'parent_nid' => $quiz_nid,
      'parent_vid' => $old_quiz_vid,
      'child_nid' => $quiz_question['child_nid'],
      'child_vid' => $quiz_question['child_vid'],
      'question_status' => QUESTION_NEVER,
      'weight' => $quiz_question['weight'],
      'max_score' => $quiz_question['max_score'],
    );
    $query
      ->values($record);
  }
  $query
    ->execute();
}