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   * @package    mod_assignment
  20   * @subpackage backup-moodle2
  21   * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  /**
  26   * Define all the backup steps that will be used by the backup_assignment_activity_task
  27   */
  28  
  29  /**
  30   * Define the complete assignment structure for backup, with file and id annotations
  31   */
  32  class backup_assignment_activity_structure_step extends backup_activity_structure_step {
  33  
  34      protected function define_structure() {
  35  
  36          // To know if we are including userinfo
  37          $userinfo = $this->get_setting_value('userinfo');
  38  
  39          // Define each element separated
  40          $assignment = new backup_nested_element('assignment', array('id'), array(
  41              'name', 'intro', 'introformat', 'assignmenttype',
  42              'resubmit', 'preventlate', 'emailteachers', 'var1',
  43              'var2', 'var3', 'var4', 'var5',
  44              'maxbytes', 'timedue', 'timeavailable', 'grade',
  45              'timemodified'));
  46  
  47          $submissions = new backup_nested_element('submissions');
  48  
  49          $submission = new backup_nested_element('submission', array('id'), array(
  50              'userid', 'timecreated', 'timemodified', 'numfiles',
  51              'data1', 'data2', 'grade', 'submissioncomment',
  52              'format', 'teacher', 'timemarked', 'mailed'));
  53  
  54          // Build the tree
  55  
  56          // Apply for 'assignment' subplugins optional stuff at assignment level (not multiple)
  57          // Remember that order is important, try moving this line to the end and compare XML
  58          $this->add_subplugin_structure('assignment', $assignment, false);
  59  
  60          $assignment->add_child($submissions);
  61          $submissions->add_child($submission);
  62  
  63          // Apply for 'assignment' subplugins optional stuff at submission level (not multiple)
  64          $this->add_subplugin_structure('assignment', $submission, false);
  65  
  66          // Define sources
  67          $assignment->set_source_table('assignment', array('id' => backup::VAR_ACTIVITYID));
  68  
  69          // All the rest of elements only happen if we are including user info
  70          if ($userinfo) {
  71              $submission->set_source_table('assignment_submissions', array('assignment' => backup::VAR_PARENTID));
  72          }
  73  
  74          // Define id annotations
  75          $assignment->annotate_ids('scale', 'grade');
  76          $submission->annotate_ids('user', 'userid');
  77          $submission->annotate_ids('user', 'teacher');
  78  
  79          // Define file annotations
  80          $assignment->annotate_files('mod_assignment', 'intro', null); // This file area hasn't itemid
  81          $submission->annotate_files('mod_assignment', 'submission', 'id');
  82          $submission->annotate_files('mod_assignment', 'response', 'id');
  83  
  84          // Return the root element (assignment), wrapped into standard activity structure
  85          return $this->prepare_activity_structure($assignment);
  86      }
  87  }