You are here

function quiz_options_form_submit in Quiz 8.4

Page callback for quiz options submit

File

./quiz.pages.inc, line 463
Page callback file for the quiz module.

Code

function quiz_options_form_submit($form, &$form_state) {
  $node = menu_get_object();
  $node->nid = $form_state['values']['nid'];
  $node->vid = $form_state['values']['vid'];

  //Taking
  $node->allow_resume = $form_state['values']['taking']['allow_resume'];
  $node->allow_skipping = $form_state['values']['taking']['allow_skipping'];
  $node->allow_jumping = $form_state['values']['taking']['allow_jumping'];
  $node->backwards_navigation = $form_state['values']['taking']['backwards_navigation'];
  $node->repeat_until_correct = $form_state['values']['taking']['repeat_until_correct'];
  $node->mark_doubtful = $form_state['values']['taking']['mark_doubtful'];
  $node->show_passed = $form_state['values']['taking']['show_passed'];
  $node->randomization = $form_state['values']['taking']['randomization'];
  $node->feedback_time = $form_state['values']['taking']['feedback']['feedback_time'];
  $node->display_feedback = $form_state['values']['taking']['feedback']['display_feedback'];
  $node->takes = $form_state['values']['taking']['multiple_takes']['takes'];
  $node->show_attempt_stats = $form_state['values']['taking']['multiple_takes']['show_attempt_stats'];
  $node->keep_results = $form_state['values']['taking']['multiple_takes']['keep_results'];
  $node->time_limit = $form_state['values']['taking']['addons']['time_limit'];

  //Availability
  $node->quiz_always = $form_state['values']['availability']['quiz_always'];
  $node->quiz_open = strtotime(str_replace(' ', '-', $form_state['values']['availability']['quiz_open']));

  //TODO: Need to verify
  $node->quiz_close = strtotime(str_replace(' ', '-', $form_state['values']['availability']['quiz_close']));

  //TODO: Need to verify

  //Pass/Fail
  $node->pass_rate = $form_state['values']['pass_fail']['pass_rate'];
  $node->summary_pass = $form_state['values']['pass_fail']['summary_pass'];
  $node->summary_default = $form_state['values']['pass_fail']['helper']['summary_default'];

  //Result comments
  $node->resultoptions = $form_state['values']['resultoptions'];
  $node->remember_settings = $form_state['values']['remember_settings'];
  $node->number_of_random_questions = $form_state['values']['number_of_random_questions'];
  $node->max_score_for_random = $form_state['values']['max_score_for_random'];
  $node->has_userpoints = isset($form_state['values']['taking']['has_userpoints']) ? $form_state['values']['taking']['has_userpoints'] : 0;
  _quiz_save_user_settings($node);

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

    //TODO: Need to handle new revisions.

    // Insert a new row in the quiz_node_properties table.
    $old_auto = isset($node->auto_created);
    $node->auto_created = TRUE;
    quiz_node_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
      ->getRevisionId(), $node
      ->id());

    //TODO: find equivalent for $node->old_vid in D8.
  }
  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
        ->getRevisionId(),
      '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' => $node->has_userpoints,
      '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,
    ))
      ->condition('vid', $node
      ->getRevisionId())
      ->condition('nid', $node
      ->id())
      ->execute();
    _quiz_update_resultoptions($node);
  }
  _quiz_check_num_random($node);
  _quiz_check_num_always($node);
  quiz_update_max_score_properties(array(
    $node
      ->getRevisionId(),
  ));
  drupal_set_message(t('Some of the updated settings may not apply to quiz being taken already. To see all changes in action you need to start again.'), 'warning');
}