You are here

public function MultichoiceQuestion::validateNode in Quiz 7.5

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

Implementation of validateNode().

Overrides QuizQuestion::validateNode

See also

QuizQuestion::validateNode()

File

question_types/multichoice/multichoice.classes.inc, line 270
Multichoice classes.

Class

MultichoiceQuestion
Extension of QuizQuestion.

Code

public function validateNode(array &$form) {
  if ($this->node->choice_multi == 0) {
    $found_one_correct = FALSE;
    for ($i = 0; isset($this->node->alternatives[$i]) && is_array($this->node->alternatives[$i]); $i++) {
      $short = $this->node->alternatives[$i];
      if (drupal_strlen($this
        ->checkMarkup($i, 'answer')) < 1) {
        continue;
      }
      if ($short['correct'] == 1) {
        if ($found_one_correct) {

          // We don't display an error message here since we allow
          // alternatives to be partially correct.
        }
        else {
          $found_one_correct = TRUE;
        }
      }
    }
    if (!$found_one_correct) {
      form_set_error('choice_multi', t('You have not marked any alternatives as correct. If there are no correct alternatives you should allow multiple answers.'));
    }
  }
  else {
    for ($i = 0; isset($this->node->alternatives[$i]); $i++) {
      $short = $this->node->alternatives[$i];
      if (strlen($this
        ->checkMarkup($i, 'answer')) < 1) {
        continue;
      }
      if ($short['score_if_chosen'] < $short['score_if_not_chosen'] && $short['correct']) {
        form_set_error("alternatives][{$i}][score_if_not_chosen", t("The alternative is marked as correct, but gives more points if you don't select it."));
      }
      elseif ($short['score_if_chosen'] > $short['score_if_not_chosen'] && !$short['correct']) {
        form_set_error("alternatives][{$i}][score_if_chosen", t('The alternative is not marked as correct, but gives more points if you select it.'));
      }
    }
  }
}