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