You are here

private function MultichoiceQuestion::forgive in Quiz 8.6

Same name and namespace in other branches
  1. 8.5 question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php \Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceQuestion::forgive()
  2. 6.x question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php \Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceQuestion::forgive()

Forgive some possible logical flaws in the user input.

File

question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php, line 39

Class

MultichoiceQuestion
@QuizQuestion ( id = "multichoice", label = Plugin annotation @Translation("Multiple choice question"), handlers = { "response" = "\Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceResponse" } )

Namespace

Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion

Code

private function forgive() {
  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 (!empty($short['correct'])) {
          $short['score_if_chosen'] = 1;
          $short['score_if_not_chosen'] = 0;
        }
        else {
          if (variable_get('multichoice_def_scoring', 0) == 0) {
            $short['score_if_chosen'] = -1;
            $short['score_if_not_chosen'] = 0;
          }
          elseif (variable_get('multichoice_def_scoring', 0) == 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;
      }
    }
  }
}