Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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   * Provides support for the conversion of moodle1 backup to the moodle2 format
  20   *
  21   * @package    mod_survey
  22   * @copyright  2011 Rossiani Wijaya <rwijaya@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   * Survey conversion handler
  30   */
  31  class moodle1_mod_survey_handler extends moodle1_mod_handler {
  32  
  33      /** @var moodle1_file_manager */
  34      protected $fileman = null;
  35  
  36      /** @var int cmid */
  37      protected $moduleid = null;
  38  
  39      /**
  40       * Declare the paths in moodle.xml we are able to convert
  41       *
  42       * The method returns list of {@link convert_path} instances.
  43       * For each path returned, the corresponding conversion method must be
  44       * defined.
  45       *
  46       * Note that the path /MOODLE_BACKUP/COURSE/MODULES/MOD/SURVEY does not
  47       * actually exist in the file. The last element with the module name was
  48       * appended by the moodle1_converter class.
  49       *
  50       * @return array of {@link convert_path} instances
  51       */
  52      public function get_paths() {
  53          return array(
  54              new convert_path(
  55                  'survey', '/MOODLE_BACKUP/COURSE/MODULES/MOD/SURVEY',
  56                  array(
  57                      'newfields' => array(
  58                          'introformat' => 0,
  59                      ),
  60                  )
  61              ),
  62          );
  63      }
  64  
  65      /**
  66       * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/SURVEY
  67       * data available
  68       */
  69      public function process_survey($data) {
  70          global $CFG;
  71  
  72          // get the course module id and context id
  73          $instanceid     = $data['id'];
  74          $cminfo         = $this->get_cminfo($instanceid);
  75          $this->moduleid = $cminfo['id'];
  76          $contextid      = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
  77  
  78          // replay upgrade step 2009042002
  79          if ($CFG->texteditors !== 'textarea') {
  80              $data['intro']       = text_to_html($data['intro'], false, false, true);
  81              $data['introformat'] = FORMAT_HTML;
  82          }
  83  
  84          // get a fresh new file manager for this instance
  85          $this->fileman = $this->converter->get_file_manager($contextid, 'mod_survey');
  86  
  87          // convert course files embedded into the intro
  88          $this->fileman->filearea = 'intro';
  89          $this->fileman->itemid   = 0;
  90          $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
  91  
  92          // write survey.xml
  93          $this->open_xml_writer("activities/survey_{$this->moduleid}/survey.xml");
  94          $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
  95              'modulename' => 'survey', 'contextid' => $contextid));
  96          $this->xmlwriter->begin_tag('survey', array('id' => $instanceid));
  97  
  98          foreach ($data as $field => $value) {
  99              if ($field <> 'id') {
 100                  $this->xmlwriter->full_tag($field, $value);
 101              }
 102          }
 103  
 104          return $data;
 105      }
 106  
 107      /**
 108       * This is executed when we reach the closing </MOD> tag of our 'survey' path
 109       */
 110      public function on_survey_end() {
 111          // finish survey.xml
 112          $this->xmlwriter->end_tag('survey');
 113          $this->xmlwriter->end_tag('activity');
 114          $this->close_xml_writer();
 115  
 116          // write inforef.xml
 117          $this->open_xml_writer("activities/survey_{$this->moduleid}/inforef.xml");
 118          $this->xmlwriter->begin_tag('inforef');
 119          $this->xmlwriter->begin_tag('fileref');
 120          foreach ($this->fileman->get_fileids() as $fileid) {
 121              $this->write_xml('file', array('id' => $fileid));
 122          }
 123          $this->xmlwriter->end_tag('fileref');
 124          $this->xmlwriter->end_tag('inforef');
 125          $this->close_xml_writer();
 126      }
 127  }