[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/scorm/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_scorm
  21   * @copyright  2011 Aparup Banerjee <nebgor@gmail.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Scorm conversion handler
  29   */
  30  class moodle1_mod_scorm_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/SCORM 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('scorm', '/MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM',
  54                  array(
  55                      'newfields' => array(
  56                          'whatgrade' => 0,
  57                          'scormtype' => 'local',
  58                          'sha1hash' => null,
  59                          'revision' => '0',
  60                          'forcecompleted' => 0,
  61                          'forcenewattempt' => 0,
  62                          'lastattemptlock' => 0,
  63                          'masteryoverride' => 1,
  64                          'displayattemptstatus' => 1,
  65                          'displaycoursestructure' => 0,
  66                          'timeopen' => '0',
  67                          'timeclose' => '0',
  68                          'introformat' => '0',
  69                      ),
  70                      'renamefields' => array(
  71                          'summary' => 'intro'
  72                      )
  73                  )
  74              ),
  75              new convert_path('scorm_sco', '/MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM/SCOES/SCO')
  76          );
  77      }
  78  
  79      /**
  80       * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM
  81       * data available
  82       */
  83      public function process_scorm($data) {
  84          global $CFG;
  85  
  86          // get the course module id and context id
  87          $instanceid     = $data['id'];
  88          $currentcminfo  = $this->get_cminfo($instanceid);
  89          $this->moduleid = $currentcminfo['id'];
  90          $contextid      = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
  91  
  92          // conditionally migrate to html format in intro
  93          if ($CFG->texteditors !== 'textarea') {
  94              $data['intro']       = text_to_html($data['intro'], false, false, true);
  95              $data['introformat'] = FORMAT_HTML;
  96          }
  97  
  98          // get a fresh new file manager for this instance
  99          $this->fileman = $this->converter->get_file_manager($contextid, 'mod_scorm');
 100  
 101          // convert course files embedded into the intro
 102          $this->fileman->filearea = 'intro';
 103          $this->fileman->itemid   = 0;
 104          $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
 105  
 106          // check 1.9 version where backup was created
 107          $backupinfo = $this->converter->get_stash('backup_info');
 108          if ($backupinfo['moodle_version'] < 2007110503) {
 109              // as we have no module version data, assume $currmodule->version <= $module->version
 110              // - fix data as the source 1.9 build hadn't yet at time of backing up.
 111              $data['grademethod'] = $data['grademethod']%10;
 112          }
 113  
 114          // update scormtype (logic is consistent as done in scorm/db/upgrade.php)
 115          $ismanifest = preg_match('/imsmanifest\.xml$/', $data['reference']);
 116          $iszippif = preg_match('/.(zip|pif)$/', $data['reference']);
 117          $isurl = preg_match('/^((http|https):\/\/|www\.)/', $data['reference']);
 118          if ($isurl) {
 119              if ($ismanifest) {
 120                  $data['scormtype'] = 'external';
 121              } else if ($iszippif) {
 122                  $data['scormtype'] = 'localtype';
 123              }
 124          }
 125  
 126          // migrate scorm package file
 127          $this->fileman->filearea = 'package';
 128          $this->fileman->itemid   = 0;
 129          $this->fileman->migrate_file('course_files/'.$data['reference']);
 130  
 131          // start writing scorm.xml
 132          $this->open_xml_writer("activities/scorm_{$this->moduleid}/scorm.xml");
 133          $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
 134              'modulename' => 'scorm', 'contextid' => $contextid));
 135          $this->xmlwriter->begin_tag('scorm', array('id' => $instanceid));
 136  
 137          foreach ($data as $field => $value) {
 138              if ($field <> 'id') {
 139                  $this->xmlwriter->full_tag($field, $value);
 140              }
 141          }
 142  
 143          $this->xmlwriter->begin_tag('scoes');
 144  
 145          return $data;
 146      }
 147  
 148      /**
 149       * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM/SCOES/SCO
 150       * data available
 151       */
 152      public function process_scorm_sco($data) {
 153          $this->write_xml('sco', $data, array('/sco/id'));
 154      }
 155  
 156      /**
 157       * This is executed when we reach the closing </MOD> tag of our 'scorm' path
 158       */
 159      public function on_scorm_end() {
 160          // close scorm.xml
 161          $this->xmlwriter->end_tag('scoes');
 162          $this->xmlwriter->end_tag('scorm');
 163          $this->xmlwriter->end_tag('activity');
 164          $this->close_xml_writer();
 165  
 166          // write inforef.xml
 167          $this->open_xml_writer("activities/scorm_{$this->moduleid}/inforef.xml");
 168          $this->xmlwriter->begin_tag('inforef');
 169          $this->xmlwriter->begin_tag('fileref');
 170          foreach ($this->fileman->get_fileids() as $fileid) {
 171              $this->write_xml('file', array('id' => $fileid));
 172          }
 173          $this->xmlwriter->end_tag('fileref');
 174          $this->xmlwriter->end_tag('inforef');
 175          $this->close_xml_writer();
 176      }
 177  }


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