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   * @package    qtype
  19   * @subpackage numerical
  20   * @copyright  2011 David Mudrak <david@moodle.com>
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  defined('MOODLE_INTERNAL') || die();
  25  
  26  /**
  27   * Multichoice question type conversion handler
  28   */
  29  class moodle1_qtype_numerical_handler extends moodle1_qtype_handler {
  30  
  31      /**
  32       * @return array
  33       */
  34      public function get_question_subpaths() {
  35          return array(
  36              'ANSWERS/ANSWER',
  37              'NUMERICAL',
  38              'NUMERICAL/NUMERICAL_UNITS/NUMERICAL_UNIT',
  39          );
  40      }
  41  
  42      /**
  43       * Appends the numerical specific information to the question
  44       */
  45      public function process_question(array $data, array $raw) {
  46  
  47          // Convert and write the answers first.
  48          if (isset($data['answers'])) {
  49              $this->write_answers($data['answers'], $this->pluginname);
  50          }
  51  
  52          // Convert and write the numerical units and numerical options.
  53          if (isset($data['numerical'][0]['numerical_units'])) {
  54              $numericalunits = $data['numerical'][0]['numerical_units'];
  55          } else {
  56              $numericalunits = array();
  57          }
  58          $numericaloptions = $this->get_default_numerical_options(
  59                  $data['oldquestiontextformat'], $numericalunits);
  60  
  61          $this->write_numerical_units($numericalunits);
  62          $this->write_numerical_options($numericaloptions);
  63  
  64          // And finally numerical_records.
  65          $this->xmlwriter->begin_tag('numerical_records');
  66          foreach ($data['numerical'] as $numericalrecord) {
  67              // We do not use write_xml() here because $numericalrecords contains more than we want.
  68              $this->xmlwriter->begin_tag('numerical_record', array('id' => $this->converter->get_nextid()));
  69              $this->xmlwriter->full_tag('answer', $numericalrecord['answer']);
  70              $this->xmlwriter->full_tag('tolerance', $numericalrecord['tolerance']);
  71              $this->xmlwriter->end_tag('numerical_record');
  72          }
  73          $this->xmlwriter->end_tag('numerical_records');
  74      }
  75  }