Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.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 shortanswer question type.
  19   *
  20   * @package    qtype
  21   * @subpackage shortanswer
  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 shortanswer 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_shortanswer_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 was_answered($state) {
  49          return !empty($state->answer);
  50      }
  51  
  52      public function response_summary($state) {
  53          if (!empty($state->answer)) {
  54              return $state->answer;
  55          } else {
  56              return null;
  57          }
  58      }
  59  
  60      public function set_first_step_data_elements($state, &$data) {
  61      }
  62  
  63      public function supply_missing_first_step_data(&$data) {
  64      }
  65  
  66      public function set_data_elements_for_step($state, &$data) {
  67          if (!empty($state->answer)) {
  68              $data['answer'] = $state->answer;
  69          }
  70      }
  71  }