[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/data/backup/moodle2/ -> backup_data_stepslib.php (source)

   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_data
  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_data_activity_task
  27   */
  28  
  29  /**
  30   * Define the complete data structure for backup, with file and id annotations
  31   */
  32  class backup_data_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          $data = new backup_nested_element('data', array('id'), array(
  41              'name', 'intro', 'introformat', 'comments',
  42              'timeavailablefrom', 'timeavailableto', 'timeviewfrom', 'timeviewto',
  43              'requiredentries', 'requiredentriestoview', 'maxentries', 'rssarticles',
  44              'singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter',
  45              'addtemplate', 'rsstemplate', 'rsstitletemplate', 'csstemplate',
  46              'jstemplate', 'asearchtemplate', 'approval', 'manageapproved', 'scale',
  47              'assessed', 'assesstimestart', 'assesstimefinish', 'defaultsort',
  48              'defaultsortdir', 'editany', 'notification', 'timemodified'));
  49  
  50          $fields = new backup_nested_element('fields');
  51  
  52          $field = new backup_nested_element('field', array('id'), array(
  53              'type', 'name', 'description', 'required', 'param1', 'param2',
  54              'param3', 'param4', 'param5', 'param6',
  55              'param7', 'param8', 'param9', 'param10'));
  56  
  57          $records = new backup_nested_element('records');
  58  
  59          $record = new backup_nested_element('record', array('id'), array(
  60              'userid', 'groupid', 'timecreated', 'timemodified',
  61              'approved'));
  62  
  63          $contents = new backup_nested_element('contents');
  64  
  65          $content = new backup_nested_element('content', array('id'), array(
  66              'fieldid', 'content', 'content1', 'content2',
  67              'content3', 'content4'));
  68  
  69          $ratings = new backup_nested_element('ratings');
  70  
  71          $rating = new backup_nested_element('rating', array('id'), array(
  72              'component', 'ratingarea', 'scaleid', 'value', 'userid', 'timecreated', 'timemodified'));
  73  
  74          // Build the tree
  75          $data->add_child($fields);
  76          $fields->add_child($field);
  77  
  78          $data->add_child($records);
  79          $records->add_child($record);
  80  
  81          $record->add_child($contents);
  82          $contents->add_child($content);
  83  
  84          $record->add_child($ratings);
  85          $ratings->add_child($rating);
  86  
  87          // Define sources
  88          $data->set_source_table('data', array('id' => backup::VAR_ACTIVITYID));
  89  
  90          $field->set_source_sql('
  91              SELECT *
  92                FROM {data_fields}
  93               WHERE dataid = ?',
  94              array(backup::VAR_PARENTID));
  95  
  96          // All the rest of elements only happen if we are including user info
  97          if ($userinfo) {
  98              $record->set_source_table('data_records', array('dataid' => backup::VAR_PARENTID));
  99  
 100              $content->set_source_table('data_content', array('recordid' => backup::VAR_PARENTID));
 101  
 102              $rating->set_source_table('rating', array('contextid'  => backup::VAR_CONTEXTID,
 103                                                        'itemid'     => backup::VAR_PARENTID,
 104                                                        'component'  => backup_helper::is_sqlparam('mod_data'),
 105                                                        'ratingarea' => backup_helper::is_sqlparam('entry')));
 106              $rating->set_source_alias('rating', 'value');
 107          }
 108  
 109          // Define id annotations
 110          $data->annotate_ids('scale', 'scale');
 111  
 112          $record->annotate_ids('user', 'userid');
 113          $record->annotate_ids('group', 'groupid');
 114  
 115          $rating->annotate_ids('scale', 'scaleid');
 116          $rating->annotate_ids('user', 'userid');
 117  
 118          // Define file annotations
 119          $data->annotate_files('mod_data', 'intro', null); // This file area hasn't itemid
 120          $content->annotate_files('mod_data', 'content', 'id'); // By content->id
 121  
 122          // Return the root element (data), wrapped into standard activity structure
 123          return $this->prepare_activity_structure($data);
 124      }
 125  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1