You are here

private function MultichoiceQuestion::forgive in Quiz 8.4

Forgive some possible logical flaws in the user input.

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

File

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

Class

MultichoiceQuestion
Extension of QuizQuestion.

Namespace

Drupal\multichoice

Code

private function forgive() {
  $config = \Drupal::config('multichoice.settings');
  if ($this->node->choice_multi == 1) {
    for ($i = 0; isset($this->node->alternatives[$i]); $i++) {
      $short =& $this->node->alternatives[$i];

      // If the scoring data doesn't make sense, use the data from the "correct" checkbox to set the score data
      if ($short['score_if_chosen'] == $short['score_if_not_chosen'] || !is_numeric($short['score_if_chosen']) || !is_numeric($short['score_if_not_chosen'])) {
        if ($short['correct'] == 1) {
          $short['score_if_chosen'] = 1;
          $short['score_if_not_chosen'] = 0;
        }
        else {
          if ($config
            ->get('multichoice_def_scoring') == 0) {
            $short['score_if_chosen'] = -1;
            $short['score_if_not_chosen'] = 0;
          }
          elseif ($config
            ->get('multichoice_def_scoring') == 1) {
            $short['score_if_chosen'] = 0;
            $short['score_if_not_chosen'] = 1;
          }
        }
      }
    }
  }
  else {

    // For questions with one, and only one, correct answer, there will be no points awarded for alternatives
    // not chosen.
    for ($i = 0; isset($this->node->alternatives[$i]); $i++) {
      $short =& $this->node->alternatives[$i];
      $short['score_if_not_chosen'] = 0;
      if (isset($short['correct']) && $short['correct'] == 1 && !_quiz_is_int($short['score_if_chosen'], 1)) {
        $short['score_if_chosen'] = 1;
      }
    }
  }
}