You are here

function quiz_questions_form_submit in Quiz 5

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

Submit function for quiz_questions

Updates from the "add questions" tab

Parameters

$form_id: A string containing the form id

$values: Array containing the form values

File

./quiz.module, line 1170
Quiz Module

Code

function quiz_questions_form_submit($form_id, $values) {

  // load the node
  $quiz = node_load(arg(1));

  // Update quiz with selected question options
  if (!quiz_update_questions($values['question_status'])) {
    form_set_error('', t('Either no questions were selected, or there was a problem updating your @quiz. Please try again.', array(
      '@quiz' => QUIZ_NAME,
    )));
    return;
  }

  // Determine how many more questions are required
  $qnum = $quiz->number_of_questions;
  $anum_random = quiz_get_num_questions($quiz->nid, QUESTION_RANDOM);
  $anum_always = quiz_get_num_questions($quiz->nid, QUESTION_ALWAYS);
  $anum_total = $anum_always + $anum_random;

  // If we have some random questions, increase this number by one.
  if ($anum_random > 0) {
    $anum_always++;
  }

  // If there are not enough questions, lower the number of questions and let the user know.
  if ($anum_total < $qnum) {
    drupal_set_message(t('The number of questions for this @quiz have been lowered to %anum to match the number of questions you assigned.', array(
      '@quiz' => QUIZ_NAME,
      '%anum' => $anum_total,
    )), 'status');
    db_query("UPDATE {quiz} SET number_of_questions = %d WHERE nid = %d", $anum_total, $quiz->nid);
  }
  else {
    if ($anum_always > $qnum) {
      drupal_set_message(t('The number of questions for this @quiz have been increased to %anum to match the number of questions you assigned.', array(
        '@quiz' => QUIZ_NAME,
        '%anum' => $anum_always,
      )), 'status');
      db_query("UPDATE {quiz} SET number_of_questions = %d WHERE nid = %d", $anum_always, $quiz->nid);
    }
    else {
      drupal_set_message(t('Questions updated successfully.'));
    }
  }
}