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   * Restore code for qtype_ddwtos.
  19   *
  20   * @package   qtype_ddwtos
  21   * @copyright 2011 The Open University
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  
  29  /**
  30   * Restore plugin class that provides the necessary information needed to restore one ddwtos qtype plugin.
  31   *
  32   * @copyright 2011 The Open University
  33   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class restore_qtype_ddwtos_plugin extends restore_qtype_plugin {
  36  
  37      /**
  38       * Returns the paths to be handled by the plugin at question level.
  39       *
  40       * @return array
  41       */
  42      protected function define_question_plugin_structure() {
  43  
  44          $paths = array();
  45  
  46          // This qtype uses question_answers, add them.
  47          $this->add_question_question_answers($paths);
  48  
  49          // Add own qtype stuff.
  50          $elename = 'ddwtos';
  51          $elepath = $this->get_pathfor('/ddwtos'); // We used get_recommended_name() so this works.
  52          $paths[] = new restore_path_element($elename, $elepath);
  53  
  54          return $paths; // And we return the interesting paths.
  55      }
  56  
  57      /**
  58       * Process the qtype/ddwtos element.
  59       *
  60       * @param array|object $data ddwtos object to work with.
  61       */
  62      public function process_ddwtos($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 question_ddwtos too.
  74          if ($questioncreated) {
  75              // Adjust some columns.
  76              $data->questionid = $newquestionid;
  77              // Insert record.
  78              $newitemid = $DB->insert_record('question_ddwtos', $data);
  79              // Create mapping (needed for decoding links).
  80              $this->set_mapping('question_ddwtos', $oldid, $newitemid);
  81          }
  82      }
  83  
  84      /**
  85       * Return the contents of this qtype to be processed by the links decoder.
  86       *
  87       * @return array
  88       */
  89      public static function define_decode_contents() {
  90  
  91          $contents = array();
  92  
  93          $fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback');
  94          $contents[] = new restore_decode_content('question_ddwtos', $fields, 'question_ddwtos');
  95  
  96          return $contents;
  97      }
  98  }