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   * Support for restore API
  19   *
  20   * @package    gradingform_guide
  21   * @copyright  2012 Dan Marsden <dan@danmarsden.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Restores the marking guide specific data from grading.xml file
  29   *
  30   * @package    gradingform_guide
  31   * @copyright  2012 Dan Marsden <dan@danmarsden.com>
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class restore_gradingform_guide_plugin extends restore_gradingform_plugin {
  35  
  36      /**
  37       * Declares the marking guide XML paths attached to the form definition element
  38       *
  39       * @return array of {@link restore_path_element}
  40       */
  41      protected function define_definition_plugin_structure() {
  42  
  43          $paths = array();
  44  
  45          $paths[] = new restore_path_element('gradingform_guide_criterion',
  46              $this->get_pathfor('/guidecriteria/guidecriterion'));
  47  
  48          $paths[] = new restore_path_element('gradingform_guide_comment',
  49              $this->get_pathfor('/guidecomments/guidecomment'));
  50  
  51          // MDL-37714: Correctly locate frequent used comments in both the
  52          // current and incorrect old format.
  53          $paths[] = new restore_path_element('gradingform_guide_comment_legacy',
  54              $this->get_pathfor('/guidecriteria/guidecomments/guidecomment'));
  55  
  56          return $paths;
  57      }
  58  
  59      /**
  60       * Declares the marking guide XML paths attached to the form instance element
  61       *
  62       * @return array of {@link restore_path_element}
  63       */
  64      protected function define_instance_plugin_structure() {
  65  
  66          $paths = array();
  67  
  68          $paths[] = new restore_path_element('gradinform_guide_filling',
  69              $this->get_pathfor('/fillings/filling'));
  70  
  71          return $paths;
  72      }
  73  
  74      /**
  75       * Processes criterion element data
  76       *
  77       * Sets the mapping 'gradingform_guide_criterion' to be used later by
  78       * {@link self::process_gradinform_guide_filling()}
  79       *
  80       * @param array|stdClass $data
  81       */
  82      public function process_gradingform_guide_criterion($data) {
  83          global $DB;
  84  
  85          $data = (object)$data;
  86          $oldid = $data->id;
  87          $data->definitionid = $this->get_new_parentid('grading_definition');
  88  
  89          $newid = $DB->insert_record('gradingform_guide_criteria', $data);
  90          $this->set_mapping('gradingform_guide_criterion', $oldid, $newid);
  91      }
  92  
  93      /**
  94       * Processes comments element data
  95       *
  96       * @param array|stdClass $data The data to insert as a comment
  97       */
  98      public function process_gradingform_guide_comment($data) {
  99          global $DB;
 100  
 101          $data = (object)$data;
 102          $data->definitionid = $this->get_new_parentid('grading_definition');
 103  
 104          $DB->insert_record('gradingform_guide_comments', $data);
 105      }
 106  
 107      /**
 108       * Processes comments element data
 109       *
 110       * @param array|stdClass $data The data to insert as a comment
 111       */
 112      public function process_gradingform_guide_comment_legacy($data) {
 113          global $DB;
 114  
 115          $data = (object)$data;
 116          $data->definitionid = $this->get_new_parentid('grading_definition');
 117  
 118          $DB->insert_record('gradingform_guide_comments', $data);
 119      }
 120  
 121      /**
 122       * Processes filling element data
 123       *
 124       * @param array|stdClass $data The data to insert as a filling
 125       */
 126      public function process_gradinform_guide_filling($data) {
 127          global $DB;
 128  
 129          $data = (object)$data;
 130          $data->instanceid = $this->get_new_parentid('grading_instance');
 131          $data->criterionid = $this->get_mappingid('gradingform_guide_criterion', $data->criterionid);
 132  
 133          $DB->insert_record('gradingform_guide_fillings', $data);
 134      }
 135  }