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_ddimageortext.
  19   * @package   qtype_ddimageortext
  20   * @copyright 2011 The Open University
  21   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  defined('MOODLE_INTERNAL') || die();
  25  
  26  /**
  27   * Restore plugin class for the ddimageortext question type.
  28   *
  29   * @copyright 2011 The Open University
  30   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31   */
  32  class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin {
  33      /**
  34       * Returns the qtype name.
  35       *
  36       * @return string The type name
  37       */
  38      protected static function qtype_name() {
  39          return 'ddimageortext';
  40      }
  41  
  42      /**
  43       * Returns the paths to be handled by the plugin at question level.
  44       *
  45       * @return array
  46       */
  47      protected function define_question_plugin_structure() {
  48  
  49          $paths = array();
  50  
  51          // Add own qtype stuff.
  52          $elename = 'dds';
  53          $elepath = $this->get_pathfor('/'.self::qtype_name());
  54          $paths[] = new restore_path_element($elename, $elepath);
  55  
  56          $elename = 'drag';
  57          $elepath = $this->get_pathfor('/drags/drag');
  58          $paths[] = new restore_path_element($elename, $elepath);
  59  
  60          $elename = 'drop';
  61          $elepath = $this->get_pathfor('/drops/drop');
  62          $paths[] = new restore_path_element($elename, $elepath);
  63  
  64          return $paths; // And we return the interesting paths.
  65      }
  66  
  67      /**
  68       * Process the qtype/{qtypename} element.
  69       *
  70       * @param array|object $data Drag and drop data to work with.
  71       */
  72      public function process_dds($data) {
  73          global $DB;
  74  
  75          $prefix = 'qtype_'.self::qtype_name();
  76  
  77          $data = (object)$data;
  78          $oldid = $data->id;
  79  
  80          // Detect if the question is created or mapped.
  81          $oldquestionid   = $this->get_old_parentid('question');
  82          $newquestionid   = $this->get_new_parentid('question');
  83          $questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false;
  84  
  85          // If the question has been created by restore,
  86          // we need to create its qtype_ddimageortext too.
  87          if ($questioncreated) {
  88              // Adjust some columns.
  89              $data->questionid = $newquestionid;
  90              // Insert record.
  91              $newitemid = $DB->insert_record($prefix, $data);
  92              // Create mapping (needed for decoding links).
  93              $this->set_mapping($prefix, $oldid, $newitemid);
  94          }
  95      }
  96  
  97      /**
  98       * Process the qtype/drags/drag element.
  99       *
 100       * @param array|object $data Drag and drop drag data to work with.
 101       */
 102      public function process_drag($data) {
 103          global $DB;
 104  
 105          $prefix = 'qtype_'.self::qtype_name();
 106  
 107          $data = (object)$data;
 108          $oldid = $data->id;
 109  
 110          // Detect if the question is created or mapped.
 111          $oldquestionid   = $this->get_old_parentid('question');
 112          $newquestionid   = $this->get_new_parentid('question');
 113          $questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false;
 114  
 115          if ($questioncreated) {
 116              $data->questionid = $newquestionid;
 117              // Insert record.
 118              $newitemid = $DB->insert_record("{$prefix}_drags", $data);
 119              // Create mapping (there are files and states based on this).
 120              $this->set_mapping("{$prefix}_drags", $oldid, $newitemid);
 121  
 122          }
 123      }
 124  
 125      /**
 126       * Process the qtype/drags/drop element.
 127       *
 128       * @param array|object $data Drad and drop drops data to work with.
 129       */
 130      public function process_drop($data) {
 131          global $DB;
 132  
 133          $prefix = 'qtype_'.self::qtype_name();
 134  
 135          $data = (object)$data;
 136          $oldid = $data->id;
 137  
 138          // Detect if the question is created or mapped.
 139          $oldquestionid   = $this->get_old_parentid('question');
 140          $newquestionid   = $this->get_new_parentid('question');
 141          $questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false;
 142  
 143          if ($questioncreated) {
 144              $data->questionid = $newquestionid;
 145              // Insert record.
 146              $newitemid = $DB->insert_record("{$prefix}_drops", $data);
 147              // Create mapping (there are files and states based on this).
 148              $this->set_mapping("{$prefix}_drops", $oldid, $newitemid);
 149          }
 150      }
 151  
 152      /**
 153       * Return the contents of this qtype to be processed by the links decoder.
 154       *
 155       * @return array
 156       */
 157      public static function define_decode_contents() {
 158  
 159          $prefix = 'qtype_'.self::qtype_name();
 160  
 161          $contents = array();
 162  
 163          $fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback');
 164          $contents[] =
 165              new restore_decode_content($prefix, $fields, $prefix);
 166  
 167          return $contents;
 168      }
 169  }