You are here

function quiz_insert in Quiz 7

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.4 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 607
Quiz Module

Code

function quiz_insert($node) {
  _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);
  }
  _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,
    '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,
    'allow_skipping' => $node->allow_skipping,
    'allow_resume' => $node->allow_resume,
    'allow_jumping' => $node->allow_jumping,
  ))
    ->execute();
  _quiz_insert_resultoptions($node);
  if (!isset($node->auto_created) && $node->revision == 0) {
    drupal_set_message(t('You just created a new quiz. Now you have to add questions to it. This page is for adding and managing questions. Here you can create new questions or add some of your already created questions. If you want to change the quiz settings, you can use the "edit" tab.'));
    $_GET['destination'] = url("node/{$node->nid}/questions");
  }

  // If the quiz don't have any questions and have been created manually jump to
  // the manage questions tab.
  if (!isset($node->auto_created)) {
    _quiz_redirect_if_empty($node);
  }
}