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   * @package    mod_feedback
  19   * @subpackage backup-moodle2
  20   * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  21   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  /**
  25   * Define all the backup steps that will be used by the backup_feedback_activity_task
  26   */
  27  
  28  /**
  29   * Define the complete feedback structure for backup, with file and id annotations
  30   */
  31  class backup_feedback_activity_structure_step extends backup_activity_structure_step {
  32  
  33      protected function define_structure() {
  34  
  35          // To know if we are including userinfo
  36          $userinfo = $this->get_setting_value('userinfo');
  37  
  38          // Define each element separated
  39          $feedback = new backup_nested_element('feedback', array('id'), array(
  40                                                  'name',
  41                                                  'intro',
  42                                                  'introformat',
  43                                                  'anonymous',
  44                                                  'email_notification',
  45                                                  'multiple_submit',
  46                                                  'autonumbering',
  47                                                  'site_after_submit',
  48                                                  'page_after_submit',
  49                                                  'page_after_submitformat',
  50                                                  'publish_stats',
  51                                                  'timeopen',
  52                                                  'timeclose',
  53                                                  'timemodified',
  54                                                  'completionsubmit'));
  55  
  56          $completeds = new backup_nested_element('completeds');
  57  
  58          $completed = new backup_nested_element('completed', array('id'), array(
  59                                                  'userid',
  60                                                  'timemodified',
  61                                                  'random_response',
  62                                                  'anonymous_response',
  63                                                  'courseid'));
  64  
  65          $items = new backup_nested_element('items');
  66  
  67          $item = new backup_nested_element('item', array('id'), array(
  68                                                  'template',
  69                                                  'name',
  70                                                  'label',
  71                                                  'presentation',
  72                                                  'typ',
  73                                                  'hasvalue',
  74                                                  'position',
  75                                                  'required',
  76                                                  'dependitem',
  77                                                  'dependvalue',
  78                                                  'options'));
  79  
  80          $values = new backup_nested_element('values');
  81  
  82          $value = new backup_nested_element('value', array('id'), array(
  83                                                  'item',
  84                                                  'template',
  85                                                  'completed',
  86                                                  'value',
  87                                                  'course_id'));
  88  
  89          // Build the tree
  90          $feedback->add_child($items);
  91          $items->add_child($item);
  92  
  93          $feedback->add_child($completeds);
  94          $completeds->add_child($completed);
  95  
  96          $completed->add_child($values);
  97          $values->add_child($value);
  98  
  99          // Define sources
 100          $feedback->set_source_table('feedback', array('id' => backup::VAR_ACTIVITYID));
 101  
 102          $item->set_source_table('feedback_item', array('feedback' => backup::VAR_PARENTID));
 103  
 104          // All these source definitions only happen if we are including user info
 105          if ($userinfo) {
 106              $completed->set_source_sql('
 107                  SELECT *
 108                    FROM {feedback_completed}
 109                   WHERE feedback = ?',
 110                  array(backup::VAR_PARENTID));
 111  
 112              $value->set_source_table('feedback_value', array('completed' => backup::VAR_PARENTID));
 113          }
 114  
 115          // Define id annotations
 116  
 117          $completed->annotate_ids('user', 'userid');
 118  
 119          // Define file annotations
 120  
 121          $feedback->annotate_files('mod_feedback', 'intro', null); // This file area hasn't itemid
 122          $feedback->annotate_files('mod_feedback', 'page_after_submit', null); // This file area hasn't itemid
 123  
 124          $item->annotate_files('mod_feedback', 'item', 'id');
 125  
 126          // Return the root element (feedback), wrapped into standard activity structure
 127          return $this->prepare_activity_structure($feedback);
 128      }
 129  
 130  }