[LON-CAPA-cvs] cvs: loncom /imspackages imsprocessor.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Mon, 25 Aug 2008 13:43:39 -0000
This is a MIME encoded message
--raeburn1219671819
Content-Type: text/plain
raeburn Mon Aug 25 09:43:39 2008 EDT
Modified files:
/loncom/imspackages imsprocessor.pm
Log:
Changes to support import of standalone question library from WebCT (d2lquestionlibrary type, with filename of questiondb.xml; items tagged as "objectbank" in XML file).
- rcardinality set to "Single" if only one answer is correct (even if questiondb.xml has attribute set to "Multiple").
- correctness of response based on numerical test of text defined by setvar tag.
- itemfeedback accumulated and displayed in <postanswerdate> block for all response types.
--raeburn1219671819
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080825094339.txt"
Index: loncom/imspackages/imsprocessor.pm
diff -u loncom/imspackages/imsprocessor.pm:1.43 loncom/imspackages/imsprocessor.pm:1.44
--- loncom/imspackages/imsprocessor.pm:1.43 Sat Aug 23 17:08:29 2008
+++ loncom/imspackages/imsprocessor.pm Mon Aug 25 09:43:39 2008
@@ -635,7 +635,11 @@
if (grep/^$key$/,@{$targets}) {
if ($$resources{$key}{type} eq "webcontent") {
%{$$resinfo{$key}} = ();
- &webct4_content($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$$resources{$key}{type},$$items{$$resources{$key}{revitm}}{title},$resrcfiles);
+ if ($$resources{$key}{file} eq 'questiondb.xml') {
+ &process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs,\%allquestions);
+ } else {
+ &webct4_content($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$$resources{$key}{type},$$items{$$resources{$key}{revitm}}{title},$resrcfiles);
+ }
} elsif ($$resources{$key}{type} eq "webctquiz") {
&process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs,\%allquestions);
}
@@ -2775,8 +2779,13 @@
sub parse_webct4_questionDB {
my ($docroot,$href,$catinfo,$settings,$allanswers,$allchoices,$allids) = @_;
- $href =~ s#[^/]+$##;
- my $xmlfile = $docroot.'/'.$href.'questionDB.xml'; #quizDB file
+ my $xmlfile;
+ if ($href eq 'questiondb.xml') {
+ $xmlfile = $docroot.'/'.$href;
+ } else {
+ $href =~ s#[^/]+$##;
+ $xmlfile = $docroot.'/'.$href.'questionDB.xml'; #quizDB file
+ }
my @state = ();
my $category; # the current category ID
my $id; # the current question ID
@@ -2797,14 +2806,19 @@
action => '',
);
my $currtexttype;
- my $currimagtype;
+ my $currimagtype;
+ my $is_objectbank;
my $p = HTML::Parser->new
(
xml_mode => 1,
start_h =>
[sub {
my ($tagname, $attr) = @_;
- push @state, $tagname;
+ if (("@state" eq "questestinterop") && ($tagname eq 'objectbank')) {
+ $is_objectbank = 1;
+ } else {
+ push @state, $tagname;
+ }
if ("@state" eq "questestinterop section") {
$category = $attr->{ident};
%{$$catinfo{$category}} = ();
@@ -2893,6 +2907,10 @@
$$settings{$id}{$list}{$answer_id}{texttype} = $attr->{texttype};
$currtexttype = $attr->{texttype};
}
+ if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow_label response_label flow_mat material mattext") {
+ $$settings{$id}{$list}{$answer_id}{texttype} = $attr->{texttype};
+ $currtexttype = $attr->{texttype};
+ }
# Numerical
if ("@state" eq "questestinterop section item presentation material mat_extension webct:x_webct_v01_dynamicmattext") {
@@ -2979,7 +2997,9 @@
}
}
if ("@state" eq "questestinterop section item resprocessing respcondition setvar") {
- $setvar{varname} = $attr->{varname};
+ foreach my $key (keys(%{$attr})) {
+ $setvar{$key} = $attr->{$key};
+ }
if ($setvar{varname} eq 'WebCT_Correct') {
push(@{$$settings{$id}{$grp}{correctanswer}},$answer_id);
}
@@ -3010,6 +3030,7 @@
}
if ("@state" eq "questestinterop section item itemfeedback") {
$fdbk = $attr->{ident};
+ push(@{$$settings{$id}{feedback}},$fdbk);
$$settings{$id}{$fdbk}{view} = $attr->{view};
}
if ("@state" eq "questestinterop section item itemfeedback material mattext") {
@@ -3053,6 +3074,9 @@
if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow_label response_label material mattext") {
$$settings{$id}{$list}{$answer_id}{text} = $text;
}
+ if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow_label response_label flow_mat material mattext") {
+ $$settings{$id}{$list}{$answer_id}{text} = $text;
+ }
# Numerical
if ("@state" eq "questestinterop section item presentation material mat_extension webct:x_webct_v01_dynamicmattext") {
@@ -3103,6 +3127,14 @@
push(@{$$settings{$id}{$list}{correctanswer}},$answer_id);
}
}
+ } elsif ($is_objectbank) { #Multiple Choice WebCT 4.1 D2L objectbank
+ if ($setvar{action} eq "Set") {
+ if ($text =~ /^\d+\.?\d*$/) {
+ if ($text > 0.000000001) {
+ push(@{$$settings{$id}{$list}{correctanswer}},$answer_id);
+ }
+ }
+ }
}
}
if ("@state" eq "questestinterop section item resprocessing itemproc_extension webct:x_webct_v01_autocalculate webct:x_webct_v01_anstolerance") {
@@ -3119,7 +3151,11 @@
end_h =>
[sub {
my ($tagname) = @_;
- pop @state;
+ if (("@state" eq "questestinterop") && ($tagname eq 'objectbank')) {
+ $is_objectbank = '';
+ } else {
+ pop @state;
+ }
}, "tagname"],
);
$p->unbroken_text(1);
@@ -3137,6 +3173,22 @@
}
}
}
+ } elsif ($$settings{$id}{class} eq 'multiplechoice') {
+ if (ref($$settings{$id}) eq 'HASH') {
+ foreach my $list (keys(%{$$settings{$id}})) {
+ if (ref($$settings{$id}{$list}) eq 'HASH') {
+ if (defined($$settings{$id}{$list}{rcardinality})) {
+ if ($$settings{$id}{$list}{rcardinality} eq 'Multiple') {
+ if (ref($$settings{$id}{$list}{correctanswer}) eq 'ARRAY') {
+ if (@{$$settings{$id}{$list}{correctanswer}} == 1) {
+ $$settings{$id}{$list}{rcardinality} = 'Single';
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
}
}
@@ -3215,7 +3267,9 @@
}
if ($cms eq 'webctce4') {
- &build_problem_container($cms,$dirtitle,$destdir,$container,$res,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,\@allids,$udom,$uname,$dirname,\$containerdir,$cid,$cdom,$cnum,$catinfo,$qzdbsettings);
+ if (@allids > 0 && $allids[0] ne '') {
+ &build_problem_container($cms,$dirtitle,$destdir,$container,$res,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,\@allids,$udom,$uname,$dirname,\$containerdir,$cid,$cdom,$cnum,$catinfo,$qzdbsettings);
+ }
} else {
&build_problem_container($cms,$dirtitle,$destdir,$container,$res,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,\@allids,$udom,$uname,$dirname,\$containerdir,$cid,$cdom,$cnum,$catinfo,$qzdbsettings,\%qzparams);
}
@@ -3328,6 +3382,7 @@
}
$probtitle{$id} =~ s/\s+/_/g;
$probtitle{$id} =~ s/:/_/g;
+ $probtitle{$id} =~ s/\//_/g;
$probtitle{$id} .= '_'.$id;
}
if (($cms eq 'webctce4' && $container ne 'database') ||
@@ -3787,10 +3842,12 @@
my $questionimage;
foreach my $fdbk (@{$$settings{$id}{feedback}}) {
my $feedback = $$settings{$id}{$fdbk}{text};
- if ($$settings{$id}{$fdbk}{texttype} eq 'text/html') {
- $feedback = &HTML::Entities::decode($feedback);
+ if ($feedback ne '') {
+ if ($$settings{$id}{$fdbk}{texttype} eq 'text/html') {
+ $feedback = &HTML::Entities::decode($feedback);
+ }
+ $allfeedback .= $feedback;
}
- $allfeedback .= $feedback;
}
if ($$settings{$id}{texttype} eq 'text/html') {
if ($$settings{$id}{text}) {
@@ -3850,9 +3907,6 @@
<essayresponse>
<textfield>$pre_fill_answer</textfield>
</essayresponse>
- <postanswerdate>
- $allfeedback
- </postanswerdate>
|;
} else {
$resourcedata{$symb.'questiontext'} = '<p>'.$$settings{$id}{text}.'</p>'.$questionimage;
@@ -4363,11 +4417,19 @@
if (!-e "$destdir/problems/$probdir") {
mkdir("$destdir/problems/$probdir",0755);
}
+ if ($allfeedback ne '') {
+ $output .= qq|
+ <postanswerdate>
+ $allfeedback
+ </postanswerdate>
+|;
+ }
$output .= qq|</problem>
|;
my $title = $$settings{$id}{title};
$title =~ s/\s/_/g;
$title =~ s/:/_/g;
+ $title =~ s/\//_/g;
$title .= '_'.$id;
open(PROB,">$destdir/problems/$probdir/$title.problem");
print PROB $output;
--raeburn1219671819--