[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/feedback/backup/moodle1/ -> lib.php (source)

   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   * Provides support for the conversion of moodle1 backup to the moodle2 format
  19   *
  20   * @package    mod_feedback
  21   * @copyright  2011 Rossiani Wijaya <[email protected]>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Feedback module conversion handler
  29   */
  30  class moodle1_mod_feedback_handler extends moodle1_mod_handler {
  31  
  32      /** @var moodle1_file_manager */
  33      protected $fileman = null;
  34  
  35      /** @var int cmid */
  36      protected $moduleid = null;
  37  
  38      /**
  39       * Declare the paths in moodle.xml we are able to convert
  40       *
  41       * The method returns list of {@link convert_path} instances.
  42       * For each path returned, the corresponding conversion method must be
  43       * defined.
  44       *
  45       * Note that the path /MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK does not
  46       * actually exist in the file. The last element with the module name was
  47       * appended by the moodle1_converter class.
  48       *
  49       * @return array of {@link convert_path} instances
  50       */
  51      public function get_paths() {
  52          return array(
  53              new convert_path(
  54                  'feedback', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK',
  55                  array(
  56                      'renamefields' => array(
  57                          'summary' => 'intro',
  58                          'pageaftersub' => 'page_after_submit',
  59                      ),
  60                      'newfields' => array(
  61                          'autonumbering' => 1,
  62                          'site_after_submit' => '',
  63                          'introformat' => 0,
  64                          'page_after_submitformat' => 0,
  65                          'completionsubmit' => 0,
  66                      ),
  67                  )
  68              ),
  69              new convert_path(
  70                  'feedback_item', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK/ITEMS/ITEM',
  71                  array (
  72                      'newfields' => array(
  73                          'label' => '',
  74                          'options' => '',
  75                          'dependitem' => 0,
  76                          'dependvalue' => '',
  77                      ),
  78                  )
  79              ),
  80          );
  81      }
  82  
  83      /**
  84       * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK
  85       * data available
  86       */
  87      public function process_feedback($data) {
  88          // get the course module id and context id
  89          $instanceid     = $data['id'];
  90          $cminfo         = $this->get_cminfo($instanceid);
  91          $this->moduleid = $cminfo['id'];
  92          $contextid      = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
  93  
  94          // get a fresh new file manager for this instance
  95          $this->fileman = $this->converter->get_file_manager($contextid, 'mod_feedback');
  96  
  97          // convert course files embedded into the intro
  98          $this->fileman->filearea = 'intro';
  99          $this->fileman->itemid   = 0;
 100          $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
 101  
 102          // start writing feedback.xml
 103          $this->open_xml_writer("activities/feedback_{$this->moduleid}/feedback.xml");
 104          $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
 105              'modulename' => 'feedback', 'contextid' => $contextid));
 106          $this->xmlwriter->begin_tag('feedback', array('id' => $instanceid));
 107  
 108          foreach ($data as $field => $value) {
 109              if ($field <> 'id') {
 110                  $this->xmlwriter->full_tag($field, $value);
 111              }
 112          }
 113  
 114          $this->xmlwriter->begin_tag('items');
 115  
 116          return $data;
 117      }
 118  
 119      /**
 120       * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK/ITEMS/ITEM
 121       * data available
 122       */
 123      public function process_feedback_item($data) {
 124          $this->write_xml('item', $data, array('/item/id'));
 125      }
 126  
 127      /**
 128       * This is executed when we reach the closing </MOD> tag of our 'feedback' path
 129       */
 130      public function on_feedback_end() {
 131          // finish writing feedback.xml
 132          $this->xmlwriter->end_tag('items');
 133          $this->xmlwriter->end_tag('feedback');
 134          $this->xmlwriter->end_tag('activity');
 135          $this->close_xml_writer();
 136  
 137          // write inforef.xml
 138          $this->open_xml_writer("activities/feedback_{$this->moduleid}/inforef.xml");
 139          $this->xmlwriter->begin_tag('inforef');
 140          $this->xmlwriter->begin_tag('fileref');
 141          foreach ($this->fileman->get_fileids() as $fileid) {
 142              $this->write_xml('file', array('id' => $fileid));
 143          }
 144          $this->xmlwriter->end_tag('fileref');
 145          $this->xmlwriter->end_tag('inforef');
 146          $this->close_xml_writer();
 147      }
 148  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1