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_survey
  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_survey_activity_task
  27   */
  28  
  29  /**
  30   * Define the complete survey structure for backup, with file and id annotations
  31   */
  32  class backup_survey_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          $survey = new backup_nested_element('survey', array('id'), array(
  41              'name', 'intro', 'introformat', 'template',
  42              'questions', 'days', 'timecreated', 'timemodified', 'completionsubmit'));
  43  
  44          $answers = new backup_nested_element('answers');
  45  
  46          $answer = new backup_nested_element('answer', array('id'), array(
  47              'userid', 'question', 'time', 'answer1',
  48              'answer2'));
  49  
  50          $analysis = new backup_nested_element('analysis');
  51  
  52          $analys = new backup_nested_element('analys', array('id'), array(
  53              'userid', 'notes'));
  54  
  55          // Build the tree
  56          $survey->add_child($answers);
  57          $answers->add_child($answer);
  58  
  59          $survey->add_child($analysis);
  60          $analysis->add_child($analys);
  61  
  62          // Define sources
  63          $survey->set_source_table('survey', array('id' => backup::VAR_ACTIVITYID));
  64  
  65          $answer->set_source_table('survey_answers', array('survey' => backup::VAR_PARENTID));
  66  
  67          $analys->set_source_table('survey_analysis', array('survey' => backup::VAR_PARENTID));
  68  
  69          // Define id annotations
  70          $answer->annotate_ids('user', 'userid');
  71          $analys->annotate_ids('user', 'userid');
  72  
  73          // Define file annotations
  74          $survey->annotate_files('mod_survey', 'intro', null); // This file area hasn't itemid
  75  
  76          // Return the root element (survey), wrapped into standard activity structure
  77          return $this->prepare_activity_structure($survey);
  78      }
  79  }