Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.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   * Support for restore API
  19   *
  20   * @package    gradingform_rubric
  21   * @copyright  2011 David Mudrak <david@moodle.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 rubric specific data from grading.xml file
  29   *
  30   * @package    gradingform_rubric
  31   * @copyright  2011 David Mudrak <david@moodle.com>
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class restore_gradingform_rubric_plugin extends restore_gradingform_plugin {
  35  
  36      /**
  37       * Declares the rubric 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_rubric_criterion',
  46              $this->get_pathfor('/criteria/criterion'));
  47  
  48          $paths[] = new restore_path_element('gradingform_rubric_level',
  49              $this->get_pathfor('/criteria/criterion/levels/level'));
  50  
  51          return $paths;
  52      }
  53  
  54      /**
  55       * Declares the rubric XML paths attached to the form instance element
  56       *
  57       * @return array of {@link restore_path_element}
  58       */
  59      protected function define_instance_plugin_structure() {
  60  
  61          $paths = array();
  62  
  63          $paths[] = new restore_path_element('gradinform_rubric_filling',
  64              $this->get_pathfor('/fillings/filling'));
  65  
  66          return $paths;
  67      }
  68  
  69      /**
  70       * Processes criterion element data
  71       *
  72       * Sets the mapping 'gradingform_rubric_criterion' to be used later by
  73       * {@link self::process_gradinform_rubric_filling()}
  74       *
  75       * @param stdClass|array $data
  76       */
  77      public function process_gradingform_rubric_criterion($data) {
  78          global $DB;
  79  
  80          $data = (object)$data;
  81          $oldid = $data->id;
  82          $data->definitionid = $this->get_new_parentid('grading_definition');
  83  
  84          $newid = $DB->insert_record('gradingform_rubric_criteria', $data);
  85          $this->set_mapping('gradingform_rubric_criterion', $oldid, $newid);
  86      }
  87  
  88      /**
  89       * Processes level element data
  90       *
  91       * Sets the mapping 'gradingform_rubric_level' to be used later by
  92       * {@link self::process_gradinform_rubric_filling()}
  93       *
  94       * @param stdClass|array $data
  95       */
  96      public function process_gradingform_rubric_level($data) {
  97          global $DB;
  98  
  99          $data = (object)$data;
 100          $oldid = $data->id;
 101          $data->criterionid = $this->get_new_parentid('gradingform_rubric_criterion');
 102  
 103          $newid = $DB->insert_record('gradingform_rubric_levels', $data);
 104          $this->set_mapping('gradingform_rubric_level', $oldid, $newid);
 105      }
 106  
 107      /**
 108       * Processes filling element data
 109       *
 110       * @param stdClass|array $data
 111       */
 112      public function process_gradinform_rubric_filling($data) {
 113          global $DB;
 114  
 115          $data = (object)$data;
 116          $data->instanceid = $this->get_new_parentid('grading_instance');
 117          $data->criterionid = $this->get_mappingid('gradingform_rubric_criterion', $data->criterionid);
 118          $data->levelid = $this->get_mappingid('gradingform_rubric_level', $data->levelid);
 119  
 120          if (!empty($data->criterionid)) {
 121              $DB->insert_record('gradingform_rubric_fillings', $data);
 122          }
 123  
 124      }
 125  }