Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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 the gapselect question type.
  19   *
  20   * @package    qtype_gapselect
  21   * @copyright  2011 The Open University
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  
  28  /**
  29   * Restore plugin class for the gapselect question type plugin.
  30   *
  31   * @copyright  2011 The Open University
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class restore_qtype_gapselect_plugin extends restore_qtype_plugin {
  35  
  36      /**
  37       * Returns the paths to be handled by the plugin at question level.
  38       *
  39       * @return array
  40       */
  41      protected function define_question_plugin_structure() {
  42  
  43          $paths = array();
  44  
  45          // This qtype uses question_answers, add them.
  46          $this->add_question_question_answers($paths);
  47  
  48          // Add own qtype stuff.
  49          $elename = 'gapselect';
  50          // We used get_recommended_name() so this works.
  51          $elepath = $this->get_pathfor('/gapselect');
  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/gapselect element
  59       *
  60       * @param array|object $data gapselect object to work with.
  61       */
  62      public function process_gapselect($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_gapselect too.
  74          if ($questioncreated) {
  75              // Adjust some columns.
  76              $data->questionid = $newquestionid;
  77              // Insert record.
  78              $newitemid = $DB->insert_record('question_gapselect', $data);
  79              // Create mapping (needed for decoding links).
  80              $this->set_mapping('question_gapselect', $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_gapselect',
  95                  $fields, 'question_gapselect');
  96  
  97          return $contents;
  98      }
  99  }