MDL-41580 SCORM: allow imsmanifest.xml to be used in file system repos

This commit is contained in:
Dan Marsden 2013-09-04 18:46:35 +12:00
parent 7f3836d15a
commit 361a47d409
11 changed files with 153 additions and 14 deletions

View file

@ -33,6 +33,7 @@ $string['activityoverview'] = 'You have SCORM packages that need attention';
$string['activitypleasewait'] = 'Activity loading, please wait ...';
$string['adminsettings'] = 'Admin settings';
$string['advanced'] = 'Parameters';
$string['aliasonly'] = 'When selecting an imsmanifest.xml file from a repository you must use an alias/shortcut for this file.';
$string['allowapidebug'] = 'Activate API debug and tracing (set the capture mask with apidebugmask)';
$string['allowtypeexternal'] = 'Enable external package type';
$string['allowtypeexternalaicc'] = 'Enable direct AICC URL';
@ -167,6 +168,7 @@ $string['identifier'] = 'Question identifier';
$string['incomplete'] = 'Incomplete';
$string['info'] = 'Info';
$string['interactions'] = 'Interactions';
$string['repositorynotsupported'] = 'Only file system repositories are supported when linking directly to an imsmanifest.xml file.';
$string['trackid'] = 'Id';
$string['trackid_help'] = 'This is the identifier set by your SCORM package for this question, the SCORM specification doesn\'t allow the full question text to be provided.';
$string['trackcorrectcount'] = 'Correct count';
@ -194,6 +196,7 @@ $string['tracktype_help'] = 'Type of the question, for example "choice" or "shor
$string['trackweight'] = 'Weight';
$string['trackweight_help'] = 'Weight assigned to the question when calculating score.';
$string['invalidactivity'] = 'SCORM activity is incorrect';
$string['invalidmanifestname'] = 'Only imsmanifest.xml or .zip files may be selected';
$string['invalidurl'] = 'Invalid URL specified';
$string['invalidurlhttpcheck'] = 'Invalid URL specified. Debug message:<pre>{$a->cmsg}</pre>';
$string['invalidhacpsession'] = 'Invalid HACP session';

View file

@ -953,6 +953,22 @@ function scorm_pluginfile($course, $cm, $context, $filearea, $args, $forcedownlo
$fullpath = "/$context->id/mod_scorm/package/0/$relativepath";
$lifetime = 0; // no caching here
} else if ($filearea === 'imsmanifest') { // This isn't a real filearea, it's a url parameter for this type of package.
$revision = (int)array_shift($args); // Prevents caching problems - ignored here.
$relativepath = implode('/', $args);
// Get imsmanifest file.
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_scorm', 'package', 0, '', false);
$file = reset($files);
// Check that the package file is an imsmanifest.xml file - if not then this method is not allowed.
$packagefilename = $file->get_filename();
if (strtolower($packagefilename) !== 'imsmanifest.xml') {
return false;
}
$file->send_relative_file($relativepath);
} else {
return false;
}

View file

@ -148,11 +148,14 @@ if (scorm_external_link($sco->launch)) {
//TODO: does this happen?
$result = $launcher;
} else if ($scorm->scormtype === SCORM_TYPE_EXTERNAL) {
// Remote learning activity
// Remote learning activity.
$result = dirname($scorm->reference).'/'.$launcher;
} else if ($scorm->scormtype === SCORM_TYPE_LOCAL && strtolower($scorm->reference) == 'imsmanifest.xml') {
// This SCORM content sits in a repository that allows relative links.
$result = "$CFG->wwwroot/pluginfile.php/$context->id/mod_scorm/imsmanifest/$scorm->revision/$launcher";
} else if ($scorm->scormtype === SCORM_TYPE_LOCAL or $scorm->scormtype === SCORM_TYPE_LOCALSYNC) {
//note: do not convert this to use get_file_url() or moodle_url()
//SCORM does not work without slasharguments and moodle_url() encodes querystring vars
// Note: do not convert this to use get_file_url() or moodle_url()
// SCORM does not work without slasharguments and moodle_url() encodes querystring vars.
$result = "$CFG->wwwroot/pluginfile.php/$context->id/mod_scorm/content/$scorm->revision/$launcher";
}

View file

@ -199,6 +199,7 @@ function scorm_parse($scorm, $full) {
$fs = get_file_storage();
$packagefile = false;
$packagefileimsmanifest = false;
if ($scorm->scormtype === SCORM_TYPE_LOCAL) {
if ($packagefile = $fs->get_file($context->id, 'mod_scorm', 'package', 0, '/', $scorm->reference)) {
@ -206,6 +207,9 @@ function scorm_parse($scorm, $full) {
$packagefile->import_external_file_contents();
}
$newhash = $packagefile->get_contenthash();
if (strtolower($packagefile->get_filename()) == 'imsmanifest.xml') {
$packagefileimsmanifest = true;
}
} else {
$newhash = null;
}
@ -228,8 +232,8 @@ function scorm_parse($scorm, $full) {
if ($packagefile) {
if (!$full and $packagefile and $scorm->sha1hash === $newhash) {
if (strpos($scorm->version, 'SCORM') !== false) {
if ($fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml')) {
// no need to update
if ($packagefileimsmanifest || $fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml')) {
// No need to update.
return;
}
} else if (strpos($scorm->version, 'AICC') !== false) {
@ -237,18 +241,25 @@ function scorm_parse($scorm, $full) {
return;
}
}
if (!$packagefileimsmanifest) {
// Now extract files.
$fs->delete_area_files($context->id, 'mod_scorm', 'content');
// now extract files
$fs->delete_area_files($context->id, 'mod_scorm', 'content');
$packer = get_file_packer('application/zip');
$packagefile->extract_to_storage($packer, $context->id, 'mod_scorm', 'content', 0, '/');
$packer = get_file_packer('application/zip');
$packagefile->extract_to_storage($packer, $context->id, 'mod_scorm', 'content', 0, '/');
}
} else if (!$full) {
return;
}
if ($packagefileimsmanifest) {
require_once("$CFG->dirroot/mod/scorm/datamodels/scormlib.php");
// Direct link to imsmanifest.xml file.
if (!scorm_parse_scorm($scorm, $packagefile)) {
$scorm->version = 'ERROR';
}
if ($manifest = $fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml')) {
} else if ($manifest = $fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml')) {
require_once("$CFG->dirroot/mod/scorm/datamodels/scormlib.php");
// SCORM
if (!scorm_parse_scorm($scorm, $manifest)) {

View file

@ -89,7 +89,7 @@ class mod_scorm_mod_form extends moodleform_mod {
// New local package upload.
$filemanageroptions = array();
$filemanageroptions['accepted_types'] = array('.zip');
$filemanageroptions['accepted_types'] = array('.zip', '.xml');
$filemanageroptions['maxbytes'] = 0;
$filemanageroptions['maxfiles'] = 1;
$filemanageroptions['subdirs'] = 0;
@ -353,7 +353,21 @@ class mod_scorm_mod_form extends moodleform_mod {
// Make sure updatefreq is not set if using normal local file.
$errors['updatefreq'] = get_string('updatefreq_error', 'mod_scorm');
}
$errors = array_merge($errors, scorm_validate_package($file));
if (strtolower($file->get_filename()) == 'imsmanifest.xml') {
if (!$file->is_external_file()) {
$errors['packagefile'] = get_string('aliasonly', 'mod_scorm');
} else {
$repository = repository::get_repository_by_id($file->get_repository_id(), CONTEXT_SYSTEM);
if (!$repository->supports_relative_file()) {
$errors['packagefile'] = get_string('repositorynotsupported', 'mod_scorm');
}
}
} else if (strtolower(substr($file->get_filename(), -3)) == 'xml') {
$errors['packagefile'] = get_string('invalidmanifestname', 'mod_scorm');
} else {
// Validate this SCORM package.
$errors = array_merge($errors, scorm_validate_package($file));
}
}
} else if ($type === SCORM_TYPE_EXTERNAL) {