Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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    moodlecore
  19   * @subpackage backup-moodle2
  20   * @copyright  2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  
  28  /**
  29   * restore plugin class that provides the necessary information
  30   * needed to restore one numerical qtype plugin
  31   *
  32   * @copyright  2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class restore_qtype_numerical_plugin extends restore_qtype_plugin {
  36  
  37      /**
  38       * Returns the paths to be handled by the plugin at question level
  39       */
  40      protected function define_question_plugin_structure() {
  41  
  42          $paths = array();
  43  
  44          // This qtype uses question_answers, add them.
  45          $this->add_question_question_answers($paths);
  46  
  47          // This qtype uses question_numerical_options and question_numerical_units, add them.
  48          $this->add_question_numerical_options($paths);
  49          $this->add_question_numerical_units($paths);
  50  
  51          // Add own qtype stuff.
  52          $elename = 'numerical';
  53          $elepath = $this->get_pathfor('/numerical_records/numerical_record');
  54          $paths[] = new restore_path_element($elename, $elepath);
  55  
  56          return $paths; // And we return the interesting paths.
  57      }
  58  
  59      /**
  60       * Process the qtype/numerical element
  61       */
  62      public function process_numerical($data) {
  63          global $DB;
  64  
  65          $data = (object)$data;
  66          $oldid = $data->id;
  67  
  68          // Detect if the question is created or mapped.
  69          $oldquestionid   = $this->get_old_parentid('question');
  70          $newquestionid   = $this->get_new_parentid('question');
  71          $questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false;
  72  
  73          // If the question has been created by restore, we need to create its
  74          // question_numerical too.
  75          if ($questioncreated) {
  76              // Adjust some columns.
  77              $data->question = $newquestionid;
  78              $data->answer = $this->get_mappingid('question_answer', $data->answer);
  79              // Insert record.
  80              $newitemid = $DB->insert_record('question_numerical', $data);
  81          }
  82      }
  83  }