You are here

function quiz_report_form_submit in Quiz 7

Same name and namespace in other branches
  1. 8.4 quiz.pages.inc \quiz_report_form_submit()
  2. 6.4 quiz.pages.inc \quiz_report_form_submit()
  3. 7.6 quiz.pages.inc \quiz_report_form_submit()
  4. 7.4 quiz.pages.inc \quiz_report_form_submit()
  5. 7.5 quiz.pages.inc \quiz_report_form_submit()

Submit the report form

1 string reference to 'quiz_report_form_submit'
quiz_report_form in ./quiz.pages.inc
Form for showing feedback, and for editing the feedback if necessary...

File

./quiz.pages.inc, line 115
User pages.

Code

function quiz_report_form_submit($form, &$form_state) {

  /* We go through the form state values and submit all
   * questiontypes with validation functions declared.
   */
  foreach ($form_state['values'] as $key => $q_values) {

    // Questions has numeric keys in the report form
    if (!is_numeric($key)) {
      continue;
    }

    // Questions store the name of the validation function with the key 'submit'
    if (!isset($q_values['submit'])) {
      continue;
    }

    // The submit function must exist
    if (!function_exists($q_values['submit'])) {
      continue;
    }

    // Load the quiz
    if (!isset($quiz)) {
      $sql = 'SELECT nid, vid FROM {quiz_node_results} WHERE result_id = %d';
      $result = db_fetch_object(db_query('SELECT nid, vid FROM {quiz_node_results} WHERE result_id = :result_id', array(
        ':result_id' => $q_values['rid'],
      )));
      $quiz = node_load($result->nid, $result->vid);
      $rid = $q_values['rid'];
    }
    $q_values['quiz'] = $quiz;

    // We call the submit function provided by the question
    call_user_func($q_values['submit'], $q_values);
  }

  // Scores may have been changed. We take the necessary actions
  quiz_update_total_score_fast($rid, $quiz->vid);

  // TODO Please review the conversion of this statement to the D7 database API syntax.

  /* db_query('UPDATE {quiz_node_results} SET is_evaluated = 1 WHERE result_id = %d', $rid) */
  db_update('quiz_node_results')
    ->fields(array(
    'is_evaluated' => 1,
  ))
    ->condition('result_id', $rid)
    ->execute();
  $results_got_deleted = _quiz_maintain_results($quiz, $rid);

  // A message saying the quiz is unscored has already been set. We unset it here...
  _quiz_remove_unscored_message();

  // Notify the user if results got deleted as a result of him scoring an answer.
  $add = $quiz->quiz_keep_results == QUIZ_KEEP_BEST && $results_got_deleted ? ' ' . t('Note that this quiz is set to only keep each users best answer.') : '';
  $score_data = quiz_get_score_array($rid, $quiz->vid, TRUE);
  module_invoke_all('quiz_scored', $quiz, $score_data, $rid);
  drupal_set_message(t('The scoring data you provided has been saved.') . $add);
  $form_state['redirect'] = 'node/' . $quiz->nid . '/results';
}