You are here

private function MultichoiceQuestion::warn in Quiz 6.4

Same name and namespace in other branches
  1. 7.6 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::warn()
  2. 7 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::warn()
  3. 7.4 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::warn()
  4. 7.5 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::warn()

Warn the user about possible user errors

1 call to MultichoiceQuestion::warn()
MultichoiceQuestion::saveNodeProperties in question_types/multichoice/multichoice.classes.inc
Implementation of save

File

question_types/multichoice/multichoice.classes.inc, line 70
The main classes for the multichoice question type.

Class

MultichoiceQuestion
Extension of QuizQuestion.

Code

private function warn() {

  // Count the number of correct answers
  $num_corrects = 0;
  for ($i = 0; isset($this->node->alternatives[$i]); $i++) {
    $alt =& $this->node->alternatives[$i];
    if ($alt['score_if_chosen'] > $alt['score_if_not_chosen']) {
      $num_corrects++;
    }
  }
  if ($num_corrects == 1 && $this->node->choice_multi == 1 || $num_corrects > 1 && $this->node->choice_multi == 0) {
    $link_options = array();
    if (isset($_GET['destination'])) {
      $link_options['query'] = array(
        'destination' => $_GET['destination'],
      );
    }
    $go_back = l(t('go back'), 'node/' . $this->node->nid . '/edit', $link_options);
    if ($num_corrects == 1) {
      drupal_set_message(t('Your question allows multiple answers. Only one of the alternatives have been marked as correct. If this wasn\'t intended please !go_back and correct it.', array(
        '!go_back' => $go_back,
      )), 'warning');
    }
    else {
      drupal_set_message(t('Your question doesn\'t allow multiple answers. More than one of the alternatives have been marked as correct. If this wasn\'t intended please !go_back and correct it.', array(
        '!go_back' => $go_back,
      )), 'warning');
    }
  }
}