我正在开发一个Moodle web服务插件。我需要得到SCORM课程已经解压缩的文件夹,其中module_id
作为输入参数。
类似:
function get_root_folder_for_scorm_module($module_id){
global $USER;
$context = get_context_instance(CONTEXT_USER, $USER->id);
self::validate_context($context);
$fs = get_file_storage();
$manifest = $fs->get_file($context->id, 'mod_scorm', 'content', $module_id, '/', 'imsmanifest.xml');
return $manifest->get_filepath(); // Exception here. $manifest is null
}
这不起作用,因为$manifest
是null
其中$module_id
由标准moodle webservice方法core_course_get_contents
返回
scorm模块有许多不同的工作方式。据我所知,内容并不总是在本地提供,也不总是来自zip文件。
如果你知道你的包将在本地可用,那么你就在正确的轨道上,尽管传递给get_file
的参数似乎是错误的。
不看源代码,我就能看出使用的上下文不正确。存储文件的上下文最有可能是模块上下文。此外,简要地看一下mod/scorm/lib.php
中的scorm_pluginfile
和scorm_get_file_info
函数,似乎itemid
(您使用$module_id
的地方)总是0。
我建议你也看看mod/scorm/locallib.php
中的scorm_parse
,在那里我们可以找到这个:
$packagefile->extract_to_storage($packer, $context->id, 'mod_scorm', 'content', 0, '/');