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   * Backup steps for mod_h5pactivity are defined here.
  19   *
  20   * @package     mod_h5pactivity
  21   * @category    backup
  22   * @copyright   2020 Ferran Recio <ferran@moodle.com>
  23   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * Define the complete structure for backup, with file and id annotations.
  30   */
  31  class backup_h5pactivity_activity_structure_step extends backup_activity_structure_step {
  32  
  33      /**
  34       * Defines the structure of the resulting xml file.
  35       *
  36       * @return backup_nested_element The structure wrapped by the common 'activity' element.
  37       */
  38      protected function define_structure() {
  39          $userinfo = $this->get_setting_value('userinfo');
  40  
  41          // Replace with the attributes and final elements that the element will handle.
  42          $attributes = ['id'];
  43          $finalelements = ['name', 'timecreated', 'timemodified', 'intro',
  44                  'introformat', 'grade', 'displayoptions', 'enabletracking', 'grademethod', 'reviewmode'];
  45          $root = new backup_nested_element('h5pactivity', $attributes, $finalelements);
  46  
  47          $attempts = new backup_nested_element('attempts');
  48  
  49          $attempt = new backup_nested_element('attempt', ['id'],
  50              ['h5pactivityid', 'userid', 'timecreated', 'timemodified', 'attempt', 'rawscore', 'maxscore',
  51              'duration', 'completion', 'success', 'scaled']
  52          );
  53  
  54          $results = new backup_nested_element('results');
  55  
  56          $result = new backup_nested_element('result', ['id'],
  57              [
  58                  'attemptid', 'subcontent', 'timecreated', 'interactiontype', 'description',
  59                  'correctpattern', 'response', 'additionals', 'rawscore', 'maxscore',
  60                  'duration', 'completion', 'success'
  61              ]
  62          );
  63  
  64          // Build the tree.
  65          $root->add_child($attempts);
  66          $attempts->add_child($attempt);
  67          $attempt->add_child($results);
  68          $results->add_child($result);
  69  
  70          // Define the source tables for the elements.
  71          $root->set_source_table('h5pactivity', ['id' => backup::VAR_ACTIVITYID]);
  72  
  73          // All the rest of elements only happen if we are including user info.
  74          if ($userinfo) {
  75              $attempt->set_source_table('h5pactivity_attempts', ['h5pactivityid' => backup::VAR_PARENTID], 'id ASC');
  76              $result->set_source_table('h5pactivity_attempts_results', ['attemptid' => backup::VAR_PARENTID], 'id ASC');
  77          }
  78  
  79          // Define id annotations.
  80          $attempt->annotate_ids('user', 'userid');
  81  
  82          // Define file annotations.
  83          $root->annotate_files('mod_h5pactivity', 'intro', null); // This file area hasn't itemid.
  84          $root->annotate_files('mod_h5pactivity', 'package', null); // This file area hasn't itemid.
  85  
  86          return $this->prepare_activity_structure($root);
  87      }
  88  }