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  
   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   * Defines all the backup steps that will be used by {@link backup_workshop_activity_task}
  20   *
  21   * @package     mod_workshop
  22   * @category    backup
  23   * @copyright   2010 David Mudrak <david.mudrak@gmail.com>
  24   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Defines the complete workshop structure for backup, with file and id annotations
  31   *
  32   * @link http://docs.moodle.org/dev/Workshop for XML structure diagram
  33   */
  34  class backup_workshop_activity_structure_step extends backup_activity_structure_step {
  35  
  36      /**
  37       * Defines the structure of the 'workshop' element inside the workshop.xml file
  38       *
  39       * @return backup_nested_element
  40       */
  41      protected function define_structure() {
  42  
  43          // are we including userinfo?
  44          $userinfo = $this->get_setting_value('userinfo');
  45  
  46          ////////////////////////////////////////////////////////////////////////
  47          // XML nodes declaration - non-user data
  48          ////////////////////////////////////////////////////////////////////////
  49  
  50          // root element describing workshop instance
  51          $workshop = new backup_nested_element('workshop', array('id'), array(
  52              'name', 'intro', 'introformat', 'instructauthors',
  53              'instructauthorsformat', 'instructreviewers',
  54              'instructreviewersformat', 'timemodified', 'phase', 'useexamples',
  55              'usepeerassessment', 'useselfassessment', 'grade', 'gradinggrade',
  56              'strategy', 'evaluation', 'gradedecimals', 'submissiontypetext', 'submissiontypefile', 'nattachments',
  57              'submissionfiletypes', 'latesubmissions', 'maxbytes', 'examplesmode', 'submissionstart',
  58              'submissionend', 'assessmentstart', 'assessmentend',
  59              'conclusion', 'conclusionformat', 'overallfeedbackmode',
  60              'overallfeedbackfiles', 'overallfeedbackfiletypes', 'overallfeedbackmaxbytes'));
  61  
  62          // assessment forms definition
  63          $this->add_subplugin_structure('workshopform', $workshop, true);
  64  
  65          // grading evaluations data
  66          $this->add_subplugin_structure('workshopeval', $workshop, true);
  67  
  68          // example submissions
  69          $examplesubmissions = new backup_nested_element('examplesubmissions');
  70          $examplesubmission  = new backup_nested_element('examplesubmission', array('id'), array(
  71              'timecreated', 'timemodified', 'title', 'content', 'contentformat',
  72              'contenttrust', 'attachment'));
  73  
  74          // reference assessment of the example submission
  75          $referenceassessment  = new backup_nested_element('referenceassessment', array('id'), array(
  76              'timecreated', 'timemodified', 'grade', 'feedbackauthor', 'feedbackauthorformat',
  77              'feedbackauthorattachment'));
  78  
  79          // dimension grades for the reference assessment (that is how the form is filled)
  80          $this->add_subplugin_structure('workshopform', $referenceassessment, true);
  81  
  82          ////////////////////////////////////////////////////////////////////////
  83          // XML nodes declaration - user data
  84          ////////////////////////////////////////////////////////////////////////
  85  
  86          // assessments of example submissions
  87          $exampleassessments = new backup_nested_element('exampleassessments');
  88          $exampleassessment  = new backup_nested_element('exampleassessment', array('id'), array(
  89              'reviewerid', 'weight', 'timecreated', 'timemodified', 'grade',
  90              'gradinggrade', 'gradinggradeover', 'gradinggradeoverby',
  91              'feedbackauthor', 'feedbackauthorformat', 'feedbackauthorattachment',
  92              'feedbackreviewer', 'feedbackreviewerformat'));
  93  
  94          // dimension grades for the assessment of example submission (that is assessment forms are filled)
  95          $this->add_subplugin_structure('workshopform', $exampleassessment, true);
  96  
  97          // submissions
  98          $submissions = new backup_nested_element('submissions');
  99          $submission  = new backup_nested_element('submission', array('id'), array(
 100              'authorid', 'timecreated', 'timemodified', 'title', 'content',
 101              'contentformat', 'contenttrust', 'attachment', 'grade',
 102              'gradeover', 'gradeoverby', 'feedbackauthor',
 103              'feedbackauthorformat', 'timegraded', 'published', 'late'));
 104  
 105          // allocated assessments
 106          $assessments = new backup_nested_element('assessments');
 107          $assessment  = new backup_nested_element('assessment', array('id'), array(
 108              'reviewerid', 'weight', 'timecreated', 'timemodified', 'grade',
 109              'gradinggrade', 'gradinggradeover', 'gradinggradeoverby',
 110              'feedbackauthor', 'feedbackauthorformat', 'feedbackauthorattachment',
 111              'feedbackreviewer', 'feedbackreviewerformat'));
 112  
 113          // dimension grades for the assessment (that is assessment forms are filled)
 114          $this->add_subplugin_structure('workshopform', $assessment, true);
 115  
 116          // aggregations of grading grades in this workshop
 117          $aggregations = new backup_nested_element('aggregations');
 118          $aggregation = new backup_nested_element('aggregation', array('id'), array(
 119              'userid', 'gradinggrade', 'timegraded'));
 120  
 121          ////////////////////////////////////////////////////////////////////////
 122          // build the tree in the order needed for restore
 123          ////////////////////////////////////////////////////////////////////////
 124          $workshop->add_child($examplesubmissions);
 125          $examplesubmissions->add_child($examplesubmission);
 126  
 127          $examplesubmission->add_child($referenceassessment);
 128  
 129          $examplesubmission->add_child($exampleassessments);
 130          $exampleassessments->add_child($exampleassessment);
 131  
 132          $workshop->add_child($submissions);
 133          $submissions->add_child($submission);
 134  
 135          $submission->add_child($assessments);
 136          $assessments->add_child($assessment);
 137  
 138          $workshop->add_child($aggregations);
 139          $aggregations->add_child($aggregation);
 140  
 141          ////////////////////////////////////////////////////////////////////////
 142          // data sources - non-user data
 143          ////////////////////////////////////////////////////////////////////////
 144  
 145          $workshop->set_source_table('workshop', array('id' => backup::VAR_ACTIVITYID));
 146  
 147          $examplesubmission->set_source_sql("
 148              SELECT *
 149                FROM {workshop_submissions}
 150               WHERE workshopid = ? AND example = 1",
 151              array(backup::VAR_PARENTID));
 152  
 153          $referenceassessment->set_source_sql("
 154              SELECT *
 155                FROM {workshop_assessments}
 156               WHERE weight = 1 AND submissionid = ?",
 157              array(backup::VAR_PARENTID));
 158  
 159          ////////////////////////////////////////////////////////////////////////
 160          // data sources - user related data
 161          ////////////////////////////////////////////////////////////////////////
 162  
 163          if ($userinfo) {
 164  
 165              $exampleassessment->set_source_sql("
 166                  SELECT *
 167                    FROM {workshop_assessments}
 168                   WHERE weight = 0 AND submissionid = ?",
 169                  array(backup::VAR_PARENTID));
 170  
 171              $submission->set_source_sql("
 172                  SELECT *
 173                    FROM {workshop_submissions}
 174                   WHERE workshopid = ? AND example = 0",
 175                   array(backup::VAR_PARENTID));  // must use SQL here, for the same reason as above
 176  
 177              $assessment->set_source_table('workshop_assessments', array('submissionid' => backup::VAR_PARENTID));
 178  
 179              $aggregation->set_source_table('workshop_aggregations', array('workshopid' => backup::VAR_PARENTID));
 180          }
 181  
 182          ////////////////////////////////////////////////////////////////////////
 183          // id annotations
 184          ////////////////////////////////////////////////////////////////////////
 185  
 186          $exampleassessment->annotate_ids('user', 'reviewerid');
 187          $submission->annotate_ids('user', 'authorid');
 188          $submission->annotate_ids('user', 'gradeoverby');
 189          $assessment->annotate_ids('user', 'reviewerid');
 190          $assessment->annotate_ids('user', 'gradinggradeoverby');
 191          $aggregation->annotate_ids('user', 'userid');
 192  
 193          ////////////////////////////////////////////////////////////////////////
 194          // file annotations
 195          ////////////////////////////////////////////////////////////////////////
 196  
 197          $workshop->annotate_files('mod_workshop', 'intro', null); // no itemid used
 198          $workshop->annotate_files('mod_workshop', 'instructauthors', null); // no itemid used
 199          $workshop->annotate_files('mod_workshop', 'instructreviewers', null); // no itemid used
 200          $workshop->annotate_files('mod_workshop', 'conclusion', null); // no itemid used
 201  
 202          $examplesubmission->annotate_files('mod_workshop', 'submission_content', 'id');
 203          $examplesubmission->annotate_files('mod_workshop', 'submission_attachment', 'id');
 204  
 205          $referenceassessment->annotate_files('mod_workshop', 'overallfeedback_content', 'id');
 206          $referenceassessment->annotate_files('mod_workshop', 'overallfeedback_attachment', 'id');
 207  
 208          $exampleassessment->annotate_files('mod_workshop', 'overallfeedback_content', 'id');
 209          $exampleassessment->annotate_files('mod_workshop', 'overallfeedback_attachment', 'id');
 210  
 211          $submission->annotate_files('mod_workshop', 'submission_content', 'id');
 212          $submission->annotate_files('mod_workshop', 'submission_attachment', 'id');
 213  
 214          $assessment->annotate_files('mod_workshop', 'overallfeedback_content', 'id');
 215          $assessment->annotate_files('mod_workshop', 'overallfeedback_attachment', 'id');
 216  
 217          // return the root element (workshop), wrapped into standard activity structure
 218          return $this->prepare_activity_structure($workshop);
 219      }
 220  }