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 backup 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   * Defines marking guide backup structures
  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 backup_gradingform_guide_plugin extends backup_gradingform_plugin {
  35  
  36      /**
  37       * Declares marking guide structures to append to the grading form definition
  38       * @return backup_plugin_element
  39       */
  40      protected function define_definition_plugin_structure() {
  41  
  42          // Append data only if the grand-parent element has 'method' set to 'guide'.
  43          $plugin = $this->get_plugin_element(null, '../../method', 'guide');
  44  
  45          // Create a visible container for our data.
  46          $pluginwrapper = new backup_nested_element($this->get_recommended_name());
  47  
  48          // Connect our visible container to the parent.
  49          $plugin->add_child($pluginwrapper);
  50  
  51          // Define our elements.
  52  
  53          $criteria = new backup_nested_element('guidecriteria');
  54  
  55          $criterion = new backup_nested_element('guidecriterion', array('id'), array(
  56              'sortorder', 'shortname', 'description', 'descriptionformat',
  57              'descriptionmarkers', 'descriptionmarkersformat', 'maxscore'));
  58  
  59          $comments = new backup_nested_element('guidecomments');
  60  
  61          $comment = new backup_nested_element('guidecomment', array('id'), array(
  62              'sortorder', 'description', 'descriptionformat'));
  63  
  64          // Build elements hierarchy.
  65  
  66          $pluginwrapper->add_child($criteria);
  67          $criteria->add_child($criterion);
  68          $pluginwrapper->add_child($comments);
  69          $comments->add_child($comment);
  70  
  71          // Set sources to populate the data.
  72  
  73          $criterion->set_source_table('gradingform_guide_criteria',
  74                  array('definitionid' => backup::VAR_PARENTID));
  75  
  76          $comment->set_source_table('gradingform_guide_comments',
  77                  array('definitionid' => backup::VAR_PARENTID));
  78  
  79          // No need to annotate ids or files yet (one day when criterion definition supports
  80          // embedded files, they must be annotated here).
  81  
  82          return $plugin;
  83      }
  84  
  85      /**
  86       * Declares marking guide structures to append to the grading form instances
  87       * @return backup_plugin_element
  88       */
  89      protected function define_instance_plugin_structure() {
  90  
  91          // Append data only if the ancestor 'definition' element has 'method' set to 'guide'.
  92          $plugin = $this->get_plugin_element(null, '../../../../method', 'guide');
  93  
  94          // Create a visible container for our data.
  95          $pluginwrapper = new backup_nested_element($this->get_recommended_name());
  96  
  97          // Connect our visible container to the parent.
  98          $plugin->add_child($pluginwrapper);
  99  
 100          // Define our elements.
 101  
 102          $fillings = new backup_nested_element('fillings');
 103  
 104          $filling = new backup_nested_element('filling', array('id'), array(
 105              'criterionid', 'remark', 'remarkformat', 'score'));
 106  
 107          // Build elements hierarchy.
 108  
 109          $pluginwrapper->add_child($fillings);
 110          $fillings->add_child($filling);
 111  
 112          // Set sources to populate the data.
 113  
 114          $filling->set_source_table('gradingform_guide_fillings',
 115              array('instanceid' => backup::VAR_PARENTID));
 116  
 117          // No need to annotate ids or files yet (one day when remark field supports
 118          // embedded fileds, they must be annotated here).
 119  
 120          return $plugin;
 121      }
 122  }