You are here

function quiz_node_insert in Quiz 8.4

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

File

./quiz.module, line 1316
Quiz Module

Code

function quiz_node_insert(EntityInterface $node) {
  if ($node
    ->getType() == 'quiz') {

    // Apply defaults.
    $defaults = _quiz_load_user_settings(\Drupal::config('quiz.settings')
      ->get('quiz_def_uid')) + _quiz_get_node_defaults(TRUE);
    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
      ->isNew() && 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);
    db_insert('quiz_node_properties')
      ->fields(array(
      'vid' => $node
        ->getRevisionId(),
      'nid' => $node
        ->id(),
      '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' => strtotime('now'),
      //TODO:// verify with strtotime($node->quiz_open),
      'quiz_close' => strtotime('+1 month'),
      //TODO:// verify with strtotime($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,
      'show_passed' => $node->show_passed,
      'mark_doubtful' => $node->mark_doubtful,
    ))
      ->execute();
    _quiz_insert_resultoptions($node);
  }
}