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  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * @package    workshopform_accumulative
  20   * @copyright  2010 David Mudrak <david@moodle.com>
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  defined('MOODLE_INTERNAL') || die();
  24  
  25  /**
  26   * Provides the information to backup accumulative grading strategy information
  27   */
  28  class backup_workshopform_accumulative_subplugin extends backup_subplugin {
  29  
  30      /**
  31       * Returns the assessment form definition to attach to 'workshop' XML element
  32       */
  33      protected function define_workshop_subplugin_structure() {
  34  
  35          // XML nodes declaration
  36          $subplugin = $this->get_subplugin_element(); // virtual optigroup element
  37          $subpluginwrapper = new backup_nested_element($this->get_recommended_name());
  38          $subplugindimension = new backup_nested_element('workshopform_accumulative_dimension', array('id'), array(
  39              'sort', 'description', 'descriptionformat', 'grade', 'weight'));
  40  
  41          // connect XML elements into the tree
  42          $subplugin->add_child($subpluginwrapper);
  43          $subpluginwrapper->add_child($subplugindimension);
  44  
  45          // set source to populate the data
  46          $subplugindimension->set_source_table('workshopform_accumulative', array('workshopid' => backup::VAR_ACTIVITYID));
  47  
  48          // id annotations
  49          $subplugindimension->annotate_ids('scale', 'grade');
  50  
  51          // file annotations
  52          $subplugindimension->annotate_files('workshopform_accumulative', 'description', 'id');
  53  
  54          return $subplugin;
  55      }
  56  
  57      /**
  58       * Returns the dimension grades to attach to 'referenceassessment' XML element
  59       */
  60      protected function define_referenceassessment_subplugin_structure() {
  61          return $this->dimension_grades_structure('workshopform_accumulative_referencegrade');
  62      }
  63  
  64      /**
  65       * Returns the dimension grades to attach to 'exampleassessment' XML element
  66       */
  67      protected function define_exampleassessment_subplugin_structure() {
  68          return $this->dimension_grades_structure('workshopform_accumulative_examplegrade');
  69      }
  70  
  71      /**
  72       * Returns the dimension grades to attach to 'assessment' XML element
  73       */
  74      protected function define_assessment_subplugin_structure() {
  75          return $this->dimension_grades_structure('workshopform_accumulative_grade');
  76      }
  77  
  78      ////////////////////////////////////////////////////////////////////////////
  79      // internal private methods
  80      ////////////////////////////////////////////////////////////////////////////
  81  
  82      /**
  83       * Returns the structure of dimension grades
  84       *
  85       * @param string first parameter of {@link backup_nested_element} constructor
  86       */
  87      private function dimension_grades_structure($elementname) {
  88  
  89          // create XML elements
  90          $subplugin = $this->get_subplugin_element(); // virtual optigroup element
  91          $subpluginwrapper = new backup_nested_element($this->get_recommended_name());
  92          $subplugingrade = new backup_nested_element($elementname, array('id'), array(
  93              'dimensionid', 'grade', 'peercomment', 'peercommentformat'));
  94  
  95          // connect XML elements into the tree
  96          $subplugin->add_child($subpluginwrapper);
  97          $subpluginwrapper->add_child($subplugingrade);
  98  
  99          // set source to populate the data
 100          $subplugingrade->set_source_sql(
 101              "SELECT id, dimensionid, grade, peercomment, peercommentformat
 102                 FROM {workshop_grades}
 103                WHERE strategy = 'accumulative' AND assessmentid = ?",
 104                array(backup::VAR_PARENTID));
 105  
 106          return $subplugin;
 107      }
 108  }