You are here

private function MultichoiceQuestion::warn in Quiz 8.4

Warn the user about possible user errors

1 call to MultichoiceQuestion::warn()
MultichoiceQuestion::saveNodeProperties in question_types/multichoice/lib/Drupal/multichoice/MultichoiceQuestion.php
Implementation of save

File

question_types/multichoice/lib/Drupal/multichoice/MultichoiceQuestion.php, line 76
The main classes for the multichoice question type.

Class

MultichoiceQuestion
Extension of QuizQuestion.

Namespace

Drupal\multichoice

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
      ->id() . '/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');
    }
  }
}