[LON-CAPA-cvs] cvs: loncom /imspackages imsimport.pm imsimportdocs.pm imsprocessor.pm
raeburn
raeburn at source.lon-capa.org
Sat Jul 27 18:04:49 EDT 2013
raeburn Sat Jul 27 22:04:49 2013 EDT
Modified files:
/loncom/imspackages imsimport.pm imsimportdocs.pm imsprocessor.pm
Log:
- Support import of Blackboard Vista question banks (IMS format) containing
questions with images.
-------------- next part --------------
Index: loncom/imspackages/imsimport.pm
diff -u loncom/imspackages/imsimport.pm:1.42 loncom/imspackages/imsimport.pm:1.43
--- loncom/imspackages/imsimport.pm:1.42 Mon Jul 15 16:13:16 2013
+++ loncom/imspackages/imsimport.pm Sat Jul 27 22:04:49 2013
@@ -1,6 +1,6 @@
# The LearningOnline Network with CAPA
#
-# $Id: imsimport.pm,v 1.42 2013/07/15 16:13:16 bisitz Exp $
+# $Id: imsimport.pm,v 1.43 2013/07/27 22:04:49 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -543,7 +543,9 @@
my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,
\%resources,\%items,\%hrefs,\%resinfo,'prepare',
\%includedres);
+
if ($manifest_result eq 'ok') {
+ my %possibledep;
foreach my $res (sort keys %resources) {
if ($importareas{$resources{$res}{type}}) {
$includedres{$res} = 1;
@@ -552,6 +554,13 @@
$resources{$res}{type} eq 'webct.question') {
push(@assessmentfiles,$res);
}
+ } elsif ($resources{$res}{usedby}) {
+ $possibledep{$res} = 1;
+ }
+ }
+ foreach my $res (sort(keys(%possibledep))) {
+ if ($includedres{$resources{$res}{usedby}}) {
+ $includedres{$res} = 1;
}
}
foreach my $itm (sort keys %items) {
@@ -566,6 +575,7 @@
$manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,
\%resources,\%items,\%hrefs,\%resinfo,'build',
\%includedres,\%includeditems);
+
if ($manifest_result eq 'ok') {
&Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets);
@@ -584,7 +594,7 @@
&Apache::imsprocessor::process_resinfo($cms,'CSTR',$tempdir,$destdir,\%items,\%resources,\@targets,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$seqstem,$seqstem,\@resrcfiles,\@packages,\%hrefs,\@pages,\@sequences,\%randompicks);
- my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\@assessmentfiles,\%total);
+ my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$cms,\%hrefs,\%resources,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\@assessmentfiles,\%total);
&Apache::imsprocessor::build_structure($cms,'CSTR',$destdir,\%items,\%resinfo,\%resources,\@targets,\%hrefs,$udom,$uname,$dirpath,$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages,\%includeditems,\%randompicks);
Index: loncom/imspackages/imsimportdocs.pm
diff -u loncom/imspackages/imsimportdocs.pm:1.30 loncom/imspackages/imsimportdocs.pm:1.31
--- loncom/imspackages/imsimportdocs.pm:1.30 Wed Oct 31 12:54:17 2012
+++ loncom/imspackages/imsimportdocs.pm Sat Jul 27 22:04:49 2013
@@ -1,6 +1,6 @@
# The LearningOnline Network with CAPA
#
-# $Id: imsimportdocs.pm,v 1.30 2012/10/31 12:54:17 raeburn Exp $
+# $Id: imsimportdocs.pm,v 1.31 2013/07/27 22:04:49 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -502,7 +502,7 @@
&Apache::imsprocessor::process_resinfo($cms,'DOCS',$tempdir,$destdir,\%items,\%resources,\@targets,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$seqstem,$seqstem,\@resrcfiles,\@packages,\%hrefs,\@pages,\@sequences);
- my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas);
+ my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,\%resources,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas);
&Apache::imsprocessor::build_structure($cms,'DOCS',$destdir,\%items,\%resinfo,\%resources,\@targets,\%hrefs,$udom,$uname,'',$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages,\%includeditems);
Index: loncom/imspackages/imsprocessor.pm
diff -u loncom/imspackages/imsprocessor.pm:1.51 loncom/imspackages/imsprocessor.pm:1.52
--- loncom/imspackages/imsprocessor.pm:1.51 Tue Dec 18 18:54:11 2012
+++ loncom/imspackages/imsprocessor.pm Sat Jul 27 22:04:49 2013
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Processor for IMS Packages
#
-# $Id: imsprocessor.pm,v 1.51 2012/12/18 18:54:11 raeburn Exp $
+# $Id: imsprocessor.pm,v 1.52 2013/07/27 22:04:49 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -203,13 +203,14 @@
sub parse_manifest {
my ($cms,$phase,$tempdir,$xmlfile,$toc,$includedres,$includeditems,$items,
- $resources,$resinfo,$hrefs,$seq) = @_;
+ $resources,$resinfo,$hrefs,$seq,$requirer) = @_;
my @state = ();
my $itm = '';
my %contents = ();
my $identifier = '';
my @allidentifiers = ();
my $lastitem;
+ my $neededby;
my $p = HTML::Parser->new
(
xml_mode => 1,
@@ -308,12 +309,8 @@
}
} elsif ("@state" eq "manifest resources resource file") {
if ($$includedres{$identifier} || $phase ne 'build') {
- if ($cms eq 'webctvista4') {
- $$resources{$identifier}{file} = $attr->{href};
- }
if ($cms eq 'bb5' || $cms eq 'bb6' ||
$cms eq 'webctce4' || $cms eq 'webctvista4') {
- push @{$$hrefs{$identifier}},$attr->{href};
if ($$resources{$identifier}{type} eq
'webct.manifest') {
my $manifestfile = $tempdir.'/'.$attr->{href};
@@ -325,7 +322,19 @@
&parse_manifest($cms,$phase,$tempdir,$manifestfile,
$toc,$includedres,$includeditems,
$items,$resources,$resinfo,
- $hrefs,$currseqref);
+ $hrefs,$currseqref,$neededby);
+ } else {
+ if ($cms eq 'webctvista4') {
+ if ($$resources{$identifier}{type} eq 'ims_qtiasiv1p2') {
+ $neededby = $identifier;
+ } elsif ($$resources{$identifier}{type} eq 'webcontent') {
+ $$resources{$identifier}{usedby} = $requirer;
+ push(@{$$hrefs{$identifier}},$attr->{href});
+ }
+ $$resources{$identifier}{file} = $attr->{href};
+ } else {
+ push(@{$$hrefs{$identifier}},$attr->{href});
+ }
}
} elsif ($cms eq 'angel5') {
if ($attr->{href} =~ m/^_assoc\\$identifier\\(.+)$/) {
@@ -333,7 +342,7 @@
} elsif ($attr->{href} =~ m/^Icons\\icon(\w+)\.gif/) {
$$resources{$identifier}{type} = $1;
}
- }
+ }
}
} elsif ("@state" eq "manifest webct:ContentObject") {
foreach my $ident (@allidentifiers) {
@@ -360,6 +369,11 @@
}
}
}
+ if ("@state" eq "manifest webct:ContentObject webct:Name") {
+ if ($cms eq 'webctvista4') {
+ $$resources{$identifier}{title} = (split(/,/,$text))[-1];
+ }
+ }
}, "dtext"],
end_h =>
[sub {
@@ -405,16 +419,20 @@
sub target_resources {
my ($resources,$oktypes,$targets) = @_;
- foreach my $key (keys %{$resources}) {
+ foreach my $key (sort(keys(%{$resources}))) {
if ( defined($$oktypes{$$resources{$key}{type}}) ) {
- push @{$targets}, $key;
+ push(@{$targets},$key);
+ } elsif (defined($$resources{$key}{usedby})) {
+ if (defined($$oktypes{$$resources{$$resources{$key}{usedby}}{type}})) {
+ push(@{$targets},$key);
+ }
}
}
return;
}
sub copy_resources {
- my ($context,$cms,$hrefs,$tempdir,$targets,$url,$crs,$cdom,$destdir,$timenow,$assessmentfiles,$total) = @_;
+ my ($context,$cms,$hrefs,$resources,$tempdir,$targets,$url,$crs,$cdom,$destdir,$timenow,$assessmentfiles,$total) = @_;
if ($context eq 'DOCS') {
foreach my $key (sort keys %{$hrefs}) {
if (grep/^$key$/,@{$targets}) {
@@ -438,6 +456,16 @@
$copyfile = $1;
}
}
+ if ($cms eq 'webctvista4') {
+ if ($file =~ m{/\QX-WEBCT-VISTA-V0\E/.+([^.]+)$}) {
+ $copyfile = $1;
+ }
+ if ($$resources{$key}{usedby}) {
+ if ($$resources{$$resources{$key}{usedby}}{image} =~ /^\Q$copyfile\E/) {
+ $copyfile = $$resources{$$resources{$key}{usedby}}{image};
+ }
+ }
+ }
unless ((($cms eq 'webctce4') && ($copyfile =~ m/questionDB\.xml$/ || $copyfile =~ m/quiz_QIZ_\d+\.xml$/ || $copyfile =~ m/properties_QIZ_\d+\.xml$/)) || (($cms eq 'webctvista4') && (grep/^$key$/,@{$assessmentfiles}) && $file =~ /\.xml$/)) {
$copyfile = $fpath.$copyfile;
my $fileresult;
@@ -452,7 +480,7 @@
if (!-e "$destdir/resfiles") {
mkdir("$destdir/resfiles",0770);
}
- foreach my $key (sort keys %{$hrefs}) {
+ foreach my $key (sort(keys(%{$hrefs}))) {
if (grep/^$key$/,@{$targets}) {
foreach my $file (@{$$hrefs{$key}}) {
$file =~ s-\\-/-g;
@@ -511,6 +539,52 @@
} elsif ($file !~ m-/data/(.+)$-) {
&Apache::lonnet::logthis("IMS import error: WebCT4 - file $file is in unexpected location");
}
+ } elsif ($cms eq 'webctvista4') {
+ if ($file =~ m{^\QX-WEBCT-VISTA-V0\E/(.+)$}) {
+ my $copyfile = $1;
+ if ($copyfile =~ m{^[^/]+/[^/]+}) {
+ my @dirs = split/\//,$copyfile;
+ my $path = "$destdir/resfiles";
+ while (@dirs > 1) {
+ $path .= '/'.$dirs[0];
+ if (!-e "$path") {
+ mkdir("$path",0755);
+ }
+ shift @dirs;
+ }
+ } else {
+ $copyfile =~ s/^[^.]+\.(\d+)_R/$1/;
+ my ($filestem,$extension) = ($copyfile =~ /^(.+)\.(\w+)$/);
+ if ($$resources{$key}{usedby}) {
+ if (ref($$resources{$$resources{$key}{usedby}}{image}) eq 'ARRAY') {
+ for (my $i=0; $i<@{$$resources{$$resources{$key}{usedby}}{image}}; $i++) {
+ my ($img,$imgtitle);
+ $img = $$resources{$$resources{$key}{usedby}}{image}[$i];
+ if (ref($$resources{$$resources{$key}{usedby}}{imagetitle}) eq 'ARRAY') {
+ $imgtitle = $$resources{$$resources{$key}{usedby}}{imagetitle}[$i];
+ }
+ if (($img =~ /^\Q$filestem\E/i) && ($imgtitle =~ /\Q$extension\E/i)) {
+ $copyfile = $img.'_'.$imgtitle;
+ last;
+ } elsif ($img =~ /^\Q$filestem\E/i) {
+ $copyfile = $img.'.'.$extension;
+ last;
+ }
+ }
+ }
+ }
+ }
+ if (-e "$tempdir/$file") {
+ my $renameres = rename("$tempdir/$file","$destdir/resfiles/$copyfile");
+ if ($renameres) {
+ if (ref($total) eq 'HASH') {
+ $$total{'file'} ++;
+ }
+ } else {
+ &Apache::lonnet::logthis("IMS import error: WebCTVista - renaming failed for file $file");
+ }
+ }
+ }
}
}
}
@@ -2358,7 +2432,12 @@
$$settings{$id}{text} .= '['.$attr->{'webct:name'}.']';
}
if ("@state" eq "questestinterop item presentation flow material matimage") {
- $$settings{$id}{image} = $attr->{uri};
+ if ($attr->{uri} =~ /\QRelativeResourceManager?contentID=\E(\d+)$/) {
+ $$settings{$id}{image} = $1;
+ push(@{$$resources{$res}{image}},$$settings{$id}{image});
+ } else {
+ $$settings{$id}{image} = $attr->{uri};
+ }
}
if ("@state" eq "questestinterop item presentation flow material mattext") {
@@ -2566,6 +2645,11 @@
if ($currtexttype eq '/text/html') {
$text =~ s#(<img\ssrc=")([^"]+)">#$1../resfiles/$2#g;
}
+ if ("@state" eq "questestinterop item presentation flow material matimage") {
+ my $imagetitle = (split(/,/,$text))[-1];
+ $$settings{$id}{imagetitle} = $imagetitle;
+ push(@{$$resources{$res}{imagetitle}},$imagetitle);
+ }
if ("@state" eq "questestinterop item itemmetadata qtimetadata qtimetadatafield fieldlabel") {
$fieldlabel = $text;
}
@@ -3909,6 +3993,13 @@
}
}
}
+ if (($cms eq 'webctvista4') && (defined($$settings{$id}{image}))) {
+ my $imgsrc = '../../resfiles/'.$$settings{$id}{image};
+ if (defined($$settings{$id}{imagetitle})) {
+ $imgsrc .= '_'.$$settings{$id}{imagetitle};
+ }
+ $questionimage = qq|<p><img src="$imgsrc" /></p>|;
+ }
if ($$settings{$id}{class} eq "paragraph") {
my $pre_fill_answer = $$settings{$id}{PARA}{PARA}{PRE_FILL_ANSWER};
if ($context eq 'CSTR') {
More information about the LON-CAPA-cvs
mailing list