[svn r12141] improve scorm export :

- medias
- chapters, subchapters, ...
skala
Eric Marguin 19 years ago
parent 977c51f4e3
commit fdded37aa6
  1. 127
      main/newscorm/learnpath.class.php

@ -7372,6 +7372,9 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '')
$zip_files_abs = array();
$link_updates = array();
foreach($this->items as $index => $item){
if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK)))
{
//get included documents from this item
$inc_docs = $item->get_resources_from_source();
//error_log('Dealing with document '.$item->get_file_path().', found included documents: '.print_r($inc_docs,true),0);
@ -7396,8 +7399,29 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '')
//give a child element <adlcp:masteryscore> to the <item> element
$my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
$my_item->appendChild($my_masteryscore);
//attache this item to the organization element
//attach this item to the organization element or hits parent if there is one
if(!empty($item->parent) && $item->parent!=0)
{
$children = $organization->childNodes;
for($i=0;$i<$children->length;$i++){
$item_temp = $children->item($i);
if ($item_temp -> nodeName == 'item')
{
if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
{
$item_temp -> appendChild($my_item);
}
}
}
}
else
{
$organization->appendChild($my_item);
}
//get the path of the file(s) from the course directory root
$my_file_path = $item->get_file_path();
@ -7427,7 +7451,7 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '')
$res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
$my_dep->setAttribute('identifier',$res_id);
$my_dep->setAttribute('type','webcontent');
$my_dep->setAttribute('adlc:scormtype','asset');
$my_dep->setAttribute('adlcp:scormtype','asset');
$my_dep_file = $xmldoc->createElement('file');
//check type of URL
//error_log('Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
@ -7502,6 +7526,73 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '')
$zip_files[] = $my_file_path;
//error_log('File '.$my_file_path. ' added to $zip_files',0);
}
else
{ // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
$my_item = $xmldoc->createElement('item');
$my_item->setAttribute('identifier','ITEM_'.$item->get_id());
$my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
$my_item->setAttribute('isvisible','true');
//give a child element <title> to the <item> element
$my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
$my_item->appendChild($my_title);
//give a child element <adlcp:prerequisite> to the <item> element
$my_prereqs = $xmldoc->createElement('adlcp:prerequisite',$item->get_prereq_string());
$my_prereqs->setAttribute('type','aicc_script');
$my_item->appendChild($my_prereqs);
//give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
//$xmldoc->createElement('adlcp:maxtimeallowed','');
//give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
//$xmldoc->createElement('adlcp:timelimitaction','');
//give a child element <adlcp:datafromlms> to the <item> element - not yet supported
//$xmldoc->createElement('adlcp:datafromlms','');
//give a child element <adlcp:masteryscore> to the <item> element
$my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
$my_item->appendChild($my_masteryscore);
//attach this item to the organization element or hits parent if there is one
if(!empty($item->parent) && $item->parent!=0)
{
$children = $organization->childNodes;
for($i=0;$i<$children->length;$i++){
$item_temp = $children->item($i);
if ($item_temp -> nodeName == 'item')
{
if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
{
$item_temp -> appendChild($my_item);
}
}
}
}
else
{
$organization->appendChild($my_item);
}
//get the path of the file(s) from the course directory root
$my_file_path = 'non_exportable.html';
$my_xml_file_path = htmlentities($my_file_path);
$my_sub_dir = dirname($my_file_path);
$my_xml_sub_dir = htmlentities($my_sub_dir);
//give a <resource> child to the <resources> element
$my_resource = $xmldoc->createElement('resource');
$my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
$my_resource->setAttribute('type','webcontent');
$my_resource->setAttribute('href','document/'.$my_xml_file_path);
//adlcp:scormtype can be either 'sco' or 'asset'
$my_resource->setAttribute('adlcp:scormtype','asset');
//xml:base is the base directory to find the files declared in this resource
$my_resource->setAttribute('xml:base','');
//give a <file> child to the <resource> element
$my_file = $xmldoc->createElement('file');
$my_file->setAttribute('href','document/'.$my_xml_file_path);
$my_resource->appendChild($my_file);
$resources->appendChild($my_resource);
}
}
$organizations->appendChild($organization);
$root->appendChild($organizations);
$root->appendChild($resources);
@ -7510,6 +7601,7 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '')
//error_log(print_r($zip_files,true),0);
$garbage_path = api_get_path(GARBAGE_PATH);
$sys_course_path = api_get_path(SYS_COURSE_PATH);
foreach($zip_files as $file_path)
{
if(empty($file_path)){continue;}
@ -7517,6 +7609,7 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '')
$dest_file = $garbage_path.$temp_dir_short.'/'.$file_path;
$this->create_path($dest_file);
//error_log('copy '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' to '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/'.$file_path,0);
//echo $main_path.$file_path.'<br>';
copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
//check if the file needs a link update
if(in_array($file_path,array_keys($link_updates))){
@ -7553,6 +7646,36 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '')
}
$zip_folder->add($dest_file,PCLZIP_OPT_REMOVE_PATH, $garbage_path);
}
$lang_not_exportable = get_lang('ThisItemIsNotExportable');
$file_content =
<<<EOD
<html>
<head>
<style>
.error-message {
font-family: arial, verdana, helvetica, sans-serif;
border-width: 1px;
border-style: solid;
left: 50%;
margin: 10px auto;
min-height: 30px;
padding: 5px;
right: 50%;
width: 500px;
background-color: #FFD1D1;
border-color: #FF0000;
color: #000;
}
</style>
<body>
<div class="error-message">
$lang_not_exportable
</div>
</body>
</html>
EOD;
file_put_contents($garbage_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
$zip_folder->add($garbage_path.$temp_dir_short.'/document/non_exportable.html',PCLZIP_OPT_REMOVE_PATH, $garbage_path);
//Finalize the imsmanifest structure, add to the zip, then return the zip
$xmldoc->save($garbage_path.'/'.$temp_dir_short.'/imsmanifest.xml');

Loading…
Cancel
Save