Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Upgrade library code for the truefalse question type.
  19   *
  20   * @package    qtype
  21   * @subpackage truefalse
  22   * @copyright  2010 The Open University
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  
  30  /**
  31   * Class for converting attempt data for truefalse questions when upgrading
  32   * attempts to the new question engine.
  33   *
  34   * This class is used by the code in question/engine/upgrade/upgradelib.php.
  35   *
  36   * @copyright  2010 The Open University
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class qtype_truefalse_qe2_attempt_updater extends question_qtype_attempt_updater {
  40      public function right_answer() {
  41          foreach ($this->question->options->answers as $ans) {
  42              if ($ans->fraction > 0.999) {
  43                  return $ans->answer;
  44              }
  45          }
  46      }
  47  
  48      public function response_summary($state) {
  49          if (is_numeric($state->answer)) {
  50              if (array_key_exists($state->answer, $this->question->options->answers)) {
  51                  return $this->question->options->answers[$state->answer]->answer;
  52              } else {
  53                  $this->logger->log_assumption("Dealing with a place where the
  54                          student selected a choice that was later deleted for
  55                          true/false question {$this->question->id}");
  56                  return null;
  57              }
  58          } else {
  59              return null;
  60          }
  61      }
  62  
  63      public function was_answered($state) {
  64          return !empty($state->answer);
  65      }
  66  
  67      public function set_first_step_data_elements($state, &$data) {
  68      }
  69  
  70      public function supply_missing_first_step_data(&$data) {
  71      }
  72  
  73      public function set_data_elements_for_step($state, &$data) {
  74          if (is_numeric($state->answer)) {
  75              $data['answer'] = (int) ($state->answer == $this->question->options->trueanswer);
  76          }
  77      }
  78  }