/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/LABEL
* data available
*/
public function process_label($data)
{
// get the course module id and context id
$instanceid = $data['id'];
$cminfo = $this->get_cminfo($instanceid);
$moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
// get a fresh new file manager for this instance
$fileman = $this->converter->get_file_manager($contextid, 'mod_label');
// convert course files embedded into the intro
$fileman->filearea = 'intro';
$fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $fileman);
// write inforef.xml
$this->open_xml_writer("activities/label_{$moduleid}/inforef.xml");
$this->xmlwriter->begin_tag('inforef');
$this->xmlwriter->begin_tag('fileref');
foreach ($fileman->get_fileids() as $fileid) {
$this->write_xml('file', array('id' => $fileid));
}
$this->xmlwriter->end_tag('fileref');
$this->xmlwriter->end_tag('inforef');
$this->close_xml_writer();
// write label.xml
$this->open_xml_writer("activities/label_{$moduleid}/label.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, 'modulename' => 'label', 'contextid' => $contextid));
$this->write_xml('label', $data, array('/label/id'));
$this->xmlwriter->end_tag('activity');
$this->close_xml_writer();
return $data;
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/ASSIGNMENT
* data available
*/
public function process_assignment($data)
{
global $CFG;
// get the course module id and context id
$instanceid = $data['id'];
$cminfo = $this->get_cminfo($instanceid);
$this->moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
//store assignment type for possible subplugin conversions.
$this->currentsubpluginname = $data['assignmenttype'];
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_assignment');
// convert course files embedded into the intro
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
// convert the introformat if necessary
if ($CFG->texteditors !== 'textarea') {
$data['intro'] = text_to_html($data['intro'], false, false, true);
$data['introformat'] = FORMAT_HTML;
}
// start writing assignment.xml
$this->open_xml_writer("activities/assignment_{$this->moduleid}/assignment.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'assignment', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('assignment', array('id' => $instanceid));
foreach ($data as $field => $value) {
if ($field != 'id') {
$this->xmlwriter->full_tag($field, $value);
}
}
//after writing the assignment type element, let the subplugin add on whatever it wants.
$this->handle_assignment_subplugin($data);
$this->xmlwriter->begin_tag('submissions');
return $data;
}
开发者ID:evltuma,项目名称:moodle,代码行数:39,代码来源:lib.php
示例6: process_feedback
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK
* data available
*/
public function process_feedback($data)
{
// get the course module id and context id
$instanceid = $data['id'];
$cminfo = $this->get_cminfo($instanceid);
$this->moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_feedback');
// convert course files embedded into the intro
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
// start writing feedback.xml
$this->open_xml_writer("activities/feedback_{$this->moduleid}/feedback.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'feedback', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('feedback', array('id' => $instanceid));
foreach ($data as $field => $value) {
if ($field != 'id') {
$this->xmlwriter->full_tag($field, $value);
}
}
$this->xmlwriter->begin_tag('items');
return $data;
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM
* data available
*/
public function process_scorm($data)
{
global $CFG;
// get the course module id and context id
$instanceid = $data['id'];
$currentcminfo = $this->get_cminfo($instanceid);
$this->moduleid = $currentcminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
// conditionally migrate to html format in intro
if ($CFG->texteditors !== 'textarea') {
$data['intro'] = text_to_html($data['intro'], false, false, true);
$data['introformat'] = FORMAT_HTML;
}
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_scorm');
// convert course files embedded into the intro
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
// check 1.9 version where backup was created
$backupinfo = $this->converter->get_stash('backup_info');
if ($backupinfo['moodle_version'] < 2007110503) {
// as we have no module version data, assume $currmodule->version <= $module->version
// - fix data as the source 1.9 build hadn't yet at time of backing up.
$data['grademethod'] = $data['grademethod'] % 10;
}
// update scormtype (logic is consistent as done in scorm/db/upgrade.php)
$ismanifest = preg_match('/imsmanifest\\.xml$/', $data['reference']);
$iszippif = preg_match('/.(zip|pif)$/', $data['reference']);
$isurl = preg_match('/^((http|https):\\/\\/|www\\.)/', $data['reference']);
if ($isurl) {
if ($ismanifest) {
$data['scormtype'] = 'external';
} else {
if ($iszippif) {
$data['scormtype'] = 'localtype';
}
}
}
// migrate scorm package file
$this->fileman->filearea = 'package';
$this->fileman->itemid = 0;
$this->fileman->migrate_file('course_files/' . $data['reference']);
// start writing scorm.xml
$this->open_xml_writer("activities/scorm_{$this->moduleid}/scorm.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'scorm', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('scorm', array('id' => $instanceid));
foreach ($data as $field => $value) {
if ($field != 'id') {
$this->xmlwriter->full_tag($field, $value);
}
}
$this->xmlwriter->begin_tag('scoes');
return $data;
}
protected function convert_configdata(array $olddata)
{
$instanceid = $olddata['id'];
$contextid = $this->converter->get_contextid(CONTEXT_BLOCK, $olddata['id']);
$configdata = unserialize(base64_decode($olddata['configdata']));
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'block_html');
// convert course files embedded in the block content
$this->fileman->filearea = 'content';
$this->fileman->itemid = 0;
$configdata->text = moodle1_converter::migrate_referenced_files($configdata->text, $this->fileman);
$configdata->format = FORMAT_HTML;
return base64_encode(serialize($configdata));
}
开发者ID:evltuma,项目名称:moodle,代码行数:14,代码来源:lib.php
示例10: process_legacy_resource
/**
* Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data
* Called by moodle1_mod_resource_handler::process_resource()
*/
public function process_legacy_resource(array $data, array $raw = null) {
// get the course module id and context id
$instanceid = $data['id'];
$currentcminfo = $this->get_cminfo($instanceid);
$moduleid = $currentcminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
// convert legacy data into the new folder record
$folder = array();
$folder['id'] = $data['id'];
$folder['name'] = $data['name'];
$folder['intro'] = $data['intro'];
$folder['introformat'] = $data['introformat'];
$folder['revision'] = 1;
$folder['timemodified'] = $data['timemodified'];
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_folder');
// migrate the files embedded into the intro field
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$folder['intro'] = moodle1_converter::migrate_referenced_files($folder['intro'], $this->fileman);
// migrate the folder files
$this->fileman->filearea = 'content';
$this->fileman->itemid = 0;
$this->fileman->migrate_directory('course_files/'.$data['reference']);
// write folder.xml
$this->open_xml_writer("activities/folder_{$moduleid}/folder.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
'modulename' => 'folder', 'contextid' => $contextid));
$this->write_xml('folder', $folder, array('/folder/id'));
$this->xmlwriter->end_tag('activity');
$this->close_xml_writer();
// write inforef.xml
$this->open_xml_writer("activities/folder_{$moduleid}/inforef.xml");
$this->xmlwriter->begin_tag('inforef');
$this->xmlwriter->begin_tag('fileref');
foreach ($this->fileman->get_fileids() as $fileid) {
$this->write_xml('file', array('id' => $fileid));
}
$this->xmlwriter->end_tag('fileref');
$this->xmlwriter->end_tag('inforef');
$this->close_xml_writer();
}
开发者ID:JP-Git,项目名称:moodle,代码行数:52,代码来源:lib.php
示例11: process_data
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/DATA
* data available
*/
public function process_data($data)
{
global $CFG;
// get the course module id and context id
$instanceid = $data['id'];
$cminfo = $this->get_cminfo($instanceid);
$this->moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
// replay the upgrade step 2007101512
if (!array_key_exists('asearchtemplate', $data)) {
$data['asearchtemplate'] = null;
}
// replay the upgrade step 2007101513
if (is_null($data['notification'])) {
$data['notification'] = 0;
}
// conditionally migrate to html format in intro
if ($CFG->texteditors !== 'textarea') {
$data['intro'] = text_to_html($data['intro'], false, false, true);
$data['introformat'] = FORMAT_HTML;
}
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_data');
// convert course files embedded into the intro
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
// @todo: user data - upgrade content to new file storage
// add 'export' tag to list and single template.
$pattern = '/\\#\\#delete\\#\\#(\\s+)\\#\\#approve\\#\\#/';
$replacement = '##delete##$1##approve##$1##export##';
$data['listtemplate'] = preg_replace($pattern, $replacement, $data['listtemplate']);
$data['singletemplate'] = preg_replace($pattern, $replacement, $data['singletemplate']);
//@todo: user data - move data comments to comments table
//@todo: user data - move data ratings to ratings table
// start writing data.xml
$this->open_xml_writer("activities/data_{$this->moduleid}/data.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'data', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('data', array('id' => $instanceid));
foreach ($data as $field => $value) {
if ($field != 'id') {
$this->xmlwriter->full_tag($field, $value);
}
}
$this->xmlwriter->begin_tag('fields');
return $data;
}
开发者ID:pzhu2004,项目名称:moodle,代码行数:51,代码来源:lib.php
示例12: process_customlabel
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/CUSTOMLABEL
* data available
*/
public function process_customlabel($data)
{
// get the course module id and context id
$instanceid = $data['id'];
$cminfo = $this->get_cminfo($instanceid);
$moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
// shifts content from name (moodle 1.9 label hacking location) to processed content and
// computes a new explicit name
$storedcontent = base64_decode($data['content']);
$customlabel = json_decode($storedcontent);
$data['processedcontent'] = $data['name'];
$data['name'] = $customlabel->labelclass . $data['id'];
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_customlabel');
// convert course files embedded into the content
$this->fileman->filearea = 'content';
$this->fileman->itemid = 0;
// try get files and reencode from stored content stub.
$storedcontent = moodle1_converter::migrate_referenced_files($storedcontent, $this->fileman);
$data['content'] = base64_encode($storedcontent);
$data['processedcontent'] = moodle1_converter::migrate_referenced_files($data['processedcontent'], $this->fileman);
// write inforef.xml
$this->open_xml_writer("activities/customlabel_{$moduleid}/inforef.xml");
$this->xmlwriter->begin_tag('inforef');
$this->xmlwriter->begin_tag('fileref');
foreach ($this->fileman->get_fileids() as $fileid) {
$this->write_xml('file', array('id' => $fileid));
}
$this->xmlwriter->end_tag('fileref');
$this->xmlwriter->end_tag('inforef');
$this->close_xml_writer();
// write customlabel.xml
$this->open_xml_writer("activities/customlabel_{$moduleid}/customlabel.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, 'modulename' => 'customlabel', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('customlabel', array('id' => $instanceid));
foreach ($data as $field => $value) {
if ($field != 'id') {
$this->xmlwriter->full_tag($field, $value);
}
}
// finish writing customlabel.xml
$this->xmlwriter->end_tag('customlabel');
$this->xmlwriter->end_tag('activity');
$this->close_xml_writer();
return $data;
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/RCONTENT
* data available
*/
public function process_rcontent($data)
{
global $CFG;
// get the course module id and context id
$instanceid = $data['id'];
$currentcminfo = $this->get_cminfo($instanceid);
$this->moduleid = $currentcminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
// conditionally migrate to html format in summary
if ($CFG->texteditors !== 'textarea') {
$data['intro'] = text_to_html($data['intro'], false, false, true);
}
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_rcontent');
// convert course files embedded into the summary
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
// check 1.9 version where backup was created
$backupinfo = $this->converter->get_stash('backup_info');
if ($backupinfo['moodle_version'] < 2007110503) {
// as we have no module version data, assume $currmodule->version <= $module->version
// - fix data as the source 1.9 build hadn't yet at time of backing up.
if (isset($data['grademethod'])) {
$data['grademethod'] = $data['grademethod'] % 10;
}
}
// start writing rcontent.xml
$this->open_xml_writer("activities/rcontent_{$this->moduleid}/rcontent.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'rcontent', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('rcontent', array('id' => $instanceid));
foreach ($data as $field => $value) {
if ($field != 'id') {
$this->xmlwriter->full_tag($field, $value);
}
}
$this->xmlwriter->begin_tag('grades');
return $data;
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/LTI
* data available
*/
public function process_basiclti($data)
{
global $DB;
// Get the course module id and context id.
$instanceid = $data['id'];
$cminfo = $this->get_cminfo($instanceid);
$this->moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
// Get a fresh new file manager for this instance.
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_lti');
// Convert course files embedded into the intro.
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
// Start writing assignment.xml.
$this->open_xml_writer("activities/lti_{$this->moduleid}/lti.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'lti', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('lti', array('id' => $instanceid));
$ignorefields = array('id', 'modtype');
if (!$DB->record_exists('lti_types', array('id' => $data['typeid']))) {
$ntypeid = $DB->get_field('lti_types_config', 'typeid', array('name' => 'toolurl', 'value' => $data['toolurl']), IGNORE_MULTIPLE);
if ($ntypeid === false) {
$ntypeid = $DB->get_field('lti_types_config', 'typeid', array(), IGNORE_MULTIPLE);
}
if ($ntypeid === false) {
$ntypeid = 0;
}
$data['typeid'] = $ntypeid;
}
if (empty($data['servicesalt'])) {
$data['servicesalt'] = uniqid('', true);
}
foreach ($data as $field => $value) {
if (!in_array($field, $ignorefields)) {
$this->xmlwriter->full_tag($field, $value);
}
}
return $data;
}
开发者ID:evltuma,项目名称:moodle,代码行数:43,代码来源:lib.php
示例17: process_quiz
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUIZ
* data available
*/
public function process_quiz($data)
{
global $CFG;
// replay the upgrade step 2008081501
if (is_null($data['sumgrades'])) {
$data['sumgrades'] = 0;
//@todo for user data: quiz_attempts SET sumgrades=0 WHERE sumgrades IS NULL
//@todo for user data: quiz_grades.grade should be not be null , convert to default 0
}
// replay the upgrade step 2009042000
if ($CFG->texteditors !== 'textarea') {
$data['intro'] = text_to_html($data['intro'], false, false, true);
$data['introformat'] = FORMAT_HTML;
}
// replay the upgrade step 2009031001
$data['timelimit'] *= 60;
// get the course module id and context id
$instanceid = $data['id'];
$cminfo = $this->get_cminfo($instanceid);
$this->moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_quiz');
// convert course files embedded into the intro
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
// start writing quiz.xml
$this->open_xml_writer("activities/quiz_{$this->moduleid}/quiz.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'quiz', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('quiz', array('id' => $instanceid));
foreach ($data as $field => $value) {
if ($field != 'id') {
$this->xmlwriter->full_tag($field, $value);
}
}
return $data;
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK/ITEMS/ITEM
* data available
*/
public function process_flashcard_deckdata($data)
{
$this->write_xml('deck', $data, array('/deck/id'));
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_flashcard');
// convert course files embedded into the intro
$this->fileman->filearea = 'answertext';
$this->fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['answertext'], $this->fileman);
// convert course files embedded into the intro
$this->fileman->filearea = 'responsetext';
$this->fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['responsetext'], $this->fileman);
}
public function test_referenced_course_files()
{
$text = 'This is a text containing links to file.php
as it is parsed from the backup file. <br /><br /><img border="0" width="110" vspace="0" hspace="0" height="92" title="News" alt="News" src="$@FILEPHP@$$@SLASH@$pics$@SLASH@$news.gif" /><a href="$@FILEPHP@$$@SLASH@$pics$@SLASH@$news.gif$@FORCEDOWNLOAD@$">download image</a><br />
<br /><a href=\'$@FILEPHP@$$@SLASH@$MANUAL.DOC$@FORCEDOWNLOAD@$\'>download manual</a><br />';
$files = moodle1_converter::find_referenced_files($text);
$this->assertEquals(gettype($files), 'array');
$this->assertEquals(2, count($files));
$this->assertTrue(in_array('/pics/news.gif', $files));
$this->assertTrue(in_array('/MANUAL.DOC', $files));
$text = moodle1_converter::rewrite_filephp_usage($text, array('/pics/news.gif', '/another/file/notused.txt'), $files);
$this->assertEquals($text, 'This is a text containing links to file.php
as it is parsed from the backup file. <br /><br /><img border="0" width="110" vspace="0" hspace="0" height="92" title="News" alt="News" src="@@PLUGINFILE@@/pics/news.gif" /><a href="@@PLUGINFILE@@/pics/news.gif?forcedownload=1">download image</a><br />
<br /><a href=\'$@FILEPHP@$$@SLASH@$MANUAL.DOC$@FORCEDOWNLOAD@$\'>download manual</a><br />');
}
请发表评论