You are here

function quiz_update in Quiz 7

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

Implements hook_update().

File

./quiz.module, line 673
Quiz Module

Code

function quiz_update($node) {
  _quiz_save_user_settings($node);

  // Quiz node vid (revision) was updated.
  if ($node->revision) {

    // Insert a new row in the quiz_node_properties table.
    $old_auto = isset($node->auto_created);
    $node->auto_created = TRUE;
    quiz_insert($node);
    if (!$old_auto) {
      unset($node->auto_created);
    }

    // Create new quiz-question relation entries in the quiz_node_relationship
    // table.
    quiz_update_quiz_question_relationship($node->old_vid, $node->vid, $node->nid);
  }
  else {

    // Update an existing row in the quiz_node_properties table.
    _quiz_common_presave_actions($node);
    $resource = db_update('quiz_node_properties')
      ->fields(array(
      'vid' => $node->vid,
      'aid' => $node->aid,
      'randomization' => $node->randomization,
      'backwards_navigation' => $node->backwards_navigation,
      'repeat_until_correct' => $node->repeat_until_correct,
      'quiz_open' => $node->quiz_open,
      'quiz_close' => $node->quiz_close,
      'takes' => $node->takes,
      'show_attempt_stats' => $node->show_attempt_stats,
      'keep_results' => $node->keep_results,
      'time_limit' => $node->time_limit,
      'pass_rate' => $node->pass_rate,
      'summary_pass' => is_array($node->summary_pass) ? $node->summary_pass['value'] : $node->summary_pass,
      'summary_pass_format' => is_array($node->summary_pass) ? $node->summary_pass['format'] : $node->summary_pass_format,
      'summary_default' => is_array($node->summary_default) ? $node->summary_default['value'] : $node->summary_default,
      'summary_default_format' => is_array($node->summary_default) ? $node->summary_default['format'] : $node->summary_default_format,
      'quiz_always' => $node->quiz_always,
      'feedback_time' => $node->feedback_time,
      'display_feedback' => $node->display_feedback,
      'number_of_random_questions' => $node->number_of_random_questions,
      'has_userpoints' => isset($node->has_userpoints) ? $node->has_userpoints : 0,
      'allow_skipping' => $node->allow_skipping,
      'allow_resume' => $node->allow_resume,
      'allow_jumping' => $node->allow_jumping,
    ))
      ->condition('vid', $node->vid)
      ->condition('nid', $node->nid)
      ->execute();
    _quiz_update_resultoptions($node);
  }
  _quiz_check_num_random($node);
  _quiz_check_num_always($node);
  quiz_update_max_score_properties(array(
    $node->vid,
  ));

  // If the node has no questions redirect to the manage questions tab
  _quiz_redirect_if_empty($node);
}