You are here

function quiz_insert in Quiz 7.4

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

Implements hook_insert().

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

File

./quiz.module, line 739
Quiz Module

Code

function quiz_insert($node) {

  // Need to set max_score if this is a cloned node
  $max_score = 0;

  // Apply defaults.
  $defaults = _quiz_load_user_settings(variable_get('quiz_def_uid', 1)) + _quiz_get_node_defaults();
  foreach ($defaults as $key => $value) {
    if (!isset($node->{$key})) {
      $node->{$key} = $value;
    }
  }
  _quiz_save_user_settings($node);

  // Copy all the questions belonging to the quiz if this is a new translation.
  if ($node->is_new && isset($node->translation_source)) {
    quiz_copy_questions($node);
  }

  // Add references to all the questions belonging to the quiz if this is a cloned quiz (node_clone compatibility)
  if ($node->is_new && isset($node->clone_from_original_nid)) {
    $old_quiz = node_load($node->clone_from_original_nid, NULL, TRUE);
    $max_score = $old_quiz->max_score;
    $questions = quiz_get_questions($old_quiz->nid, $old_quiz->vid, TRUE, TRUE, FALSE, TRUE);

    // Format the current questions for referencing
    foreach ($questions as $nid => $q) {
      $questions[$nid]->state = $q->question_status;
      $questions[$nid]->refresh = 0;
    }
    quiz_set_questions($node, $questions);
  }
  _quiz_common_presave_actions($node);

  // If the quiz is saved as not randomized we have to make sure that questions belonging to the quiz are saved as not random
  _quiz_check_num_random($node);
  _quiz_check_num_always($node);

  // TODO Please convert this statement to the D7 database API syntax.

  /* db_query($sql, $node->vid, $node->nid, $node->aid, $node->number_of_random_questions, $node->randomization, $node->backwards_navigation, $node->repeat_until_correct, $node->quiz_open, $node->quiz_close, $node->takes, $node->show_attempt_stats, $node->keep_results, $node->time_limit, $node->pass_rate, $node->summary_pass, $node->summary_default, $node->quiz_always, $node->feedback_time, $node->display_feedback, $tid, isset($node->has_userpoints) ? $node->has_userpoints : 0, $node->allow_skipping, $node->allow_resume, $node->allow_jumping) */
  db_insert('quiz_node_properties')
    ->fields(array(
    'vid' => $node->vid,
    'nid' => $node->nid,
    'aid' => !empty($node->aid) ? $node->aid : 0,
    'number_of_random_questions' => $node->number_of_random_questions,
    'max_score_for_random' => $node->max_score_for_random,
    '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,
    'tid' => isset($node->tid) ? $node->tid : 0,
    'has_userpoints' => isset($node->has_userpoints) ? $node->has_userpoints : 0,
    'userpoints_tid' => isset($node->userpoints_tid) ? $node->userpoints_tid : 0,
    'allow_skipping' => $node->allow_skipping,
    'allow_resume' => $node->allow_resume,
    'allow_jumping' => $node->allow_jumping,
    'show_passed' => $node->show_passed,
    'mark_doubtful' => $node->mark_doubtful,
    'max_score' => $max_score,
  ))
    ->execute();
  _quiz_insert_resultoptions($node);
}