You are here

function quiz_update_quiz_question_relationship in Quiz 8.4

Same name and namespace in other branches
  1. 5.2 quiz.module \quiz_update_quiz_question_relationship()
  2. 6.6 quiz.module \quiz_update_quiz_question_relationship()
  3. 6.2 quiz.module \quiz_update_quiz_question_relationship()
  4. 6.3 quiz.module \quiz_update_quiz_question_relationship()
  5. 6.4 quiz.module \quiz_update_quiz_question_relationship()
  6. 6.5 quiz.module \quiz_update_quiz_question_relationship()
  7. 7.6 quiz.module \quiz_update_quiz_question_relationship()
  8. 7 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.

1 call to quiz_update_quiz_question_relationship()
quiz_options_form_submit in ./quiz.pages.inc
Page callback for quiz options submit

File

./quiz.module, line 1634
Quiz Module

Code

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

  // query for questions in previous version
  $result = db_select('quiz_node_relationship', 'qnr')
    ->fields('qnr', array(
    'parent_nid',
    'child_nid',
    'child_vid',
    'question_status',
    'weight',
    'max_score',
    'auto_update_max_score',
  ))
    ->condition('parent_nid', $quiz_nid)
    ->condition('parent_vid', $old_quiz_vid)
    ->condition('question_status', QUESTION_NEVER, '!=')
    ->execute();

  // only proceed if query returned data
  if ($result
    ->rowCount()) {
    $insert_query = db_insert('quiz_node_relationship')
      ->fields(array(
      'parent_nid',
      'parent_vid',
      'child_nid',
      'child_vid',
      'question_status',
      'weight',
      'max_score',
      'auto_update_max_score',
    ));
    while ($quiz_question = $result
      ->fetchAssoc()) {
      $insert_query
        ->values(array(
        'parent_nid' => $quiz_nid,
        'parent_vid' => $new_quiz_vid,
        'child_nid' => $quiz_question['child_nid'],
        'child_vid' => $quiz_question['child_vid'],
        'question_status' => $quiz_question['question_status'],
        'weight' => $quiz_question['weight'],
        'max_score' => $quiz_question['max_score'],
        'auto_update_max_score' => $quiz_question['auto_update_max_score'],
      ));
    }
    $insert_query
      ->execute();
  }

  /* Update terms if any */
  $result = db_select('quiz_terms', 'qt')
    ->fields('qt', array(
    'nid',
    'tid',
    'weight',
    'max_score',
    'number',
  ))
    ->condition('vid', $old_quiz_vid)
    ->execute();

  // only proceed if query returned data
  if ($result
    ->rowCount()) {
    $insert_query = db_insert('quiz_terms')
      ->fields(array(
      'nid',
      'vid',
      'tid',
      'weight',
      'max_score',
      'number',
    ));
    while ($quiz_term = $result
      ->fetchAssoc()) {
      $insert_query
        ->values(array(
        'nid' => $quiz_nid,
        'vid' => $new_quiz_vid,
        'tid' => $quiz_term['tid'],
        'weight' => $quiz_term['weight'],
        'max_score' => $quiz_term['max_score'],
        'number' => $quiz_term['number'],
      ));
    }
    $insert_query
      ->execute();
  }

  /*$sql = "INSERT INTO {quiz_terms} (nid, vid, tid, weight, max_score, number)
    SELECT qt.nid, %d, qt.tid, qt.weight, qt.max_score, qt.number
    FROM {quiz_terms} qt
    WHERE qt.vid = %d";*/
}