[LON-CAPA-cvs] cvs: loncom /imspackages imsprocessor.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Tue, 25 Oct 2005 13:54:46 -0000
This is a MIME encoded message
--raeburn1130248486
Content-Type: text/plain
raeburn Tue Oct 25 09:54:46 2005 EDT
Modified files:
/loncom/imspackages imsprocessor.pm
Log:
Can now convert BB6 pool and assessment questions to LON-CAPA problems. Some fixes made to bb6 parser. Mapping of feedback items to hints still needed.
--raeburn1130248486
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20051025095446.txt"
Index: loncom/imspackages/imsprocessor.pm
diff -u loncom/imspackages/imsprocessor.pm:1.29 loncom/imspackages/imsprocessor.pm:1.30
--- loncom/imspackages/imsprocessor.pm:1.29 Fri Oct 14 18:28:56 2005
+++ loncom/imspackages/imsprocessor.pm Tue Oct 25 09:54:46 2005
@@ -44,7 +44,17 @@
survey => 'assessment/x-bb-survey',
users => 'course/x-bb-user',
);
- %{$$cmsmap{bb6}} = %{$$cmsmap{bb5}};
+ %{$$cmsmap{bb6}} = (
+ announce => 'resource/x-bb-announcement',
+ board => 'resource/x-bb-discussionboard',
+ doc => 'resource/x-bb-document',
+ extlink => 'resource/x-bb-externallink',
+ pool => 'assessment/x-bb-qti-pool',
+ quiz => 'assessment/x-bb-qti-test',
+ staff => 'resource/x-bb-staffinfo',
+ survey => 'assessment/x-bb-survey',
+ users => 'course/x-bb-user',
+ );
$$cmsmap{bb6}{conference} = 'resource/x-bb-conference';
%{$$cmsmap{angel}} = (
board => 'BOARD',
@@ -514,15 +524,15 @@
$board_id ++;
$board_count ++;
}
- } elsif ($$resources{$key}{type} eq "assessment/x-bb-pool") {
+ } elsif ($$resources{$key}{type} =~/assessment\/x\-bb\-(qti\-)?pool/) {
%{$$resinfo{$key}} = ();
&process_assessment($cms,$context,$key,$docroot,'pool',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs);
push @{$pools}, $key;
- } elsif ($$resources{$key}{type} eq "assessment/x-bb-quiz") {
+ } elsif ($$resources{$key}{type} =~ /assessment\/x\-bb\-(qti\-)?quiz/) {
%{$$resinfo{$key}} = ();
&process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs);
push @{$quizzes}, $key;
- } elsif ($$resources{$key}{type} eq "assessment/x-bb-survey") {
+ } elsif ($$resources{$key}{type} =~ /assessment\/x\-bb\-(qti\-)?survey/) {
%{$$resinfo{$key}} = ();
&process_assessment($cms,$context,$key,$docroot,'survey',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs);
push @{$surveys}, $key;
@@ -1827,19 +1837,31 @@
}
sub parse_bb6_assessment {
- my ($res,$docroot,$container,$settings,$allanswers,$allchoices,$allids) = @_;
+ my ($res,$docroot,$container,$settings,$allids) = @_;
my $xmlfile = $docroot.'/'.$res.".dat";
my @state = ();
my $id; # the current question ID
- my $list; # the current list ID for multiple choice questions
my $response; # the current response ID
- my $currtexttype;
- my @curr_block = ();
+ my $foil; # the current foil ID
+ my $numchoice; # the current right match choice;
+ my $labelcount; # the current count of choices for a matching item.
my $curr_shuffle;
- my $curr_class;
+ my $curr_class; # the current question type
my $curr_matchitem;
- my $curr_block_type;
- my $curr_feedback_type;
+ my $curr_block_type; # the current block type
+ my $curr_flow; # the current flow class attribute
+ my $curr_flow_mat; # the current flow_mat class attribute
+ my $curr_feedback_type; # the current feedback type
+ my $numorder; # counter for ordering type questions
+
+ my $itemfrag = "questestinterop assessment section item";
+ my $presfrag = "$itemfrag presentation flow flow";
+ my $blockflow = 'flow';
+ my $responselid;
+ my $instructionfrag = "questestinterop assessment presentation_material flow_mat material";
+ my $feedbackfrag = "$itemfrag itemfeedback";
+ my $feedback_tag = '';
+ my $responselid;
my $p = HTML::Parser->new
(
xml_mode => 1,
@@ -1851,42 +1873,51 @@
$$settings{title} = $attr->{title};
}
if ("@state" eq "questestinterop assessment rubric flow_mat material mat_extension mat_formattedtext") {
- $currtexttype = $attr->{type};
+ $$settings{description}{texttype} = $attr->{type};
}
- if ("@state" eq "questestinterop section item presentation flow") {
- $curr_block[0] = $attr->{class};
- if ($curr_block[0] eq 'RESPONSE_BLOCK') {
+ if ("@state" eq $presfrag) {
+ if ($attr->{class} eq 'QUESTION_BLOCK') {
+ $curr_block_type = 'question';
+ } elsif ($attr->{class} eq 'RESPONSE_BLOCK') {
$curr_block_type = 'response';
- } elsif ($curr_block[0] eq 'RIGHT_MATCH_BLOCK') {
+ if ($curr_class eq 'Matching') {
+ $responselid = 'flow response_lid';
+ } else {
+ $responselid = 'response_lid';
+ }
+ } elsif (($attr->{class} eq 'RIGHT_MATCH_BLOCK')) {
+ $numchoice = 0;
$curr_block_type = 'rightmatch';
- }
+ }
}
- if ("@state" eq "questestinterop section item presentation flow flow") {
- $curr_block[1] = $attr->{class};
- if ($curr_block[1] eq 'QUESTION_BLOCK') {
- $curr_block_type = 'question';
+ if ("@state" eq "$presfrag flow") {
+ if (($curr_block_type =~ /^rightmatch/) && ($attr->{class} eq 'Block')) {
+ $curr_block_type = 'rightmatch'.$numchoice;
+ $numchoice ++;
}
}
- if ("@state" eq "questestinterop section item presentation flow flow flow") {
- $curr_block[2] = $attr->{class};
+ if ($state[-1] eq 'flow') {
+ $curr_flow = $attr->{class};
}
- if ("@state" eq "questestinterop section item presentation flow flow flow material mat_extension mat_formatted_text") {
+ if ($state[-1] eq 'flow_mat') {
+ $curr_flow_mat = $attr->{class};
+ }
+ if ("@state" eq "$presfrag $blockflow material mat_extension mat_formattedtext") {
$$settings{$id}{$curr_block_type}{texttype} = $attr->{texttype};
- $currtexttype = $attr->{texttype};
}
- if ("@state" eq "questestinterop section item presentation flow flow flow material matapplication") {
+ if ("@state" eq "$presfrag $blockflow material matapplication") {
$$settings{$id}{$curr_block_type}{image} = $attr->{uri};
$$settings{$id}{$curr_block_type}{style} = $attr->{embedded};
$$settings{$id}{$curr_block_type}{label} = $attr->{label};
}
- if ("@state" eq "questestinterop section item presentation flow flow flow material mattext") {
+ if ("@state" eq "$presfrag $blockflow material mattext") {
$$settings{$id}{$curr_block_type}{link} = $attr->{uri};
}
- if ("@state" eq "questestinterop section item presentation flow response_lid render_choice") {
- $curr_shuffle = $attr->{shuffle};
- }
- if ("@state" eq "questestinterop section item presentation flow response_lid") { $response = $attr->{ident};
+ if ("@state" eq "$presfrag $responselid") {
+ $response = $attr->{ident};
+ $labelcount = 0;
if ($curr_class eq 'Matching') {
+ push(@{$$settings{$id}{answers}},$response);
%{$$settings{$id}{$response}} = ();
foreach my $key (keys(%{$$settings{$id}{$curr_block_type}})) {
$$settings{$id}{$response}{$key} = $$settings{$id}{$curr_block_type}{$key};
@@ -1894,40 +1925,56 @@
%{$$settings{$id}{$curr_block_type}} = ();
}
}
- if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow response_label") {
- if (($curr_class eq 'Multiple Choice') || ($curr_class eq 'Multiple Answer') || ($curr_class eq 'Order')) {
- $list = $attr->{ident};
- push(@{$$settings{$id}{lists}},$list);
- $$settings{$id}{$list}{randomize} = $curr_shuffle;
- %{$$settings{$id}{$list}} = ();
- @{$$allanswers{$id}{$list}} = ();
- @{$$settings{$id}{$list}{correctanswer}} = ();
- } elsif ($curr_class eq 'Matching') {
- push(@{$$settings{$id}{$response}{items}},$list);
- }
- }
- if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow response_label flow_mat material matapplication") {
- $$settings{$id}{$list}{filetype} = $attr->{embedded};
- $$settings{$id}{$list}{label} = $attr->{label};
- $$settings{$id}{$list}{uri} = $attr->{uri};
+ if ("@state" eq "$presfrag $responselid render_choice") {
+ $curr_shuffle = $attr->{shuffle};
+ }
+ if ("@state" eq "$presfrag $responselid render_choice flow_label response_label") {
+ $foil = $attr->{ident};
+ %{$$settings{$id}{$foil}} = ();
+ $$settings{$id}{$foil}{randomize} = $curr_shuffle;
+ unless ($curr_class eq 'Essay'){
+ if ($curr_class eq 'Matching') {
+ push(@{$$settings{$id}{$response}{items}},$foil);
+ $$settings{$id}{$foil}{order} = $labelcount;
+ $labelcount ++;
+ } else {
+ push(@{$$settings{$id}{answers}},$foil);
+ @{$$settings{$id}{correctanswer}} = ();
+ }
+ }
+ }
+ if ("@state" eq "$presfrag $responselid render_choice flow_label response_label flow_mat material matapplication") {
+ $$settings{$id}{$foil}{filetype} = $attr->{embedded};
+ $$settings{$id}{$foil}{label} = $attr->{label};
+ $$settings{$id}{$foil}{uri} = $attr->{uri};
}
- if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow response_label flow_mat material mattext") {
- $$settings{$id}{$list}{link} = $attr->{uri};
+ if ("@state" eq "$presfrag $responselid render_choice flow_label response_label flow_mat material mattext") {
+ $$settings{$id}{$foil}{link} = $attr->{uri};
}
- if ("@state" eq "questestinterop section item resprocessing respcondition conditionvar varequal") {
+ if ("@state" eq "questestinterop assessment section item resprocessing") {
+ if ($curr_class eq 'Matching') {
+ $$settings{$id}{allchoices} = $numchoice;
+ }
+ }
+ if ("@state" eq "questestinterop assessment section item resprocessing respcondition conditionvar varequal") {
if ($curr_class eq 'Matching') {
$curr_matchitem = $attr->{respident};
}
}
- if ("@state" eq "questestinterop section item itemfeedback") {
+ if ("@state" eq $feedbackfrag) {
$curr_feedback_type = $attr->{ident};
+ $feedback_tag = "";
+ }
+ if ("@state" eq "$feedbackfrag solution") {
+ $curr_feedback_type = 'solution';
+ $feedback_tag = "solution solutionmaterial";
}
- if ("@state" eq "questestinterop section item itemfeedback flow_mat flow_mat material matapplication") {
+ if ("@state" eq "$feedbackfrag $feedback_tag flow_mat flow_mat material matapplication") {
$$settings{$id}{$curr_feedback_type.'feedback'}{filetype} = $attr->{'embedded'};
$$settings{$id}{$curr_feedback_type.'feedback'}{label} = $attr->{label};
- $$settings{$id}{$curr_feedback_type.'feedback'}{uri} = $attr->{uri};
+ $$settings{$id}{$curr_feedback_type.'feedback'}{uri} = $attr->{uri};
}
- if ("@state" eq "questestinterop section item itemfeedback flow_mat flow_mat material mattext") {
+ if ("@state" eq "$feedbackfrag $feedback_tag flow_mat flow_mat material mattext") {
$$settings{$id}{$curr_feedback_type.'feedback'}{link} = $attr->{uri};
}
}, "tagname, attr"],
@@ -1937,56 +1984,77 @@
$text =~ s/^\s+//g;
$text =~ s/\s+$//g;
if ("@state" eq "questestinterop assessment rubric flow_mat material mat_extension mat_formattedtext") {
- $$settings{description} = $text;
- } elsif ("@state" eq "questestinterop assessment presentation_material flow_mat material mat_extension mat_formattedtext") {
+ $$settings{description}{text} = $text;
+ }
+ if ("@state" eq "questestinterop assessment rubric flow_mat material mattext") {
+ $$settings{description}{text} = $text;
+ }
+ if ("@state" eq "$instructionfrag mat_extension mat_formattedtext") {
+ $$settings{instructions}{text} = $text;
+ }
+ if ("@state" eq "$instructionfrag mattext") {
$$settings{instructions}{text} = $text;
}
if ("@state" eq "questestinterop assessment section item itemmetadata bbmd_asi_object_id") {
$id = $text;
push @{$allids}, $id;
%{$$settings{$id}} = ();
- @{$$settings{$id}{lists}} = ();
+ @{$$settings{$id}{answers}} = ();
%{$$settings{$id}{question}} = ();
%{$$settings{$id}{correctfeedback}} = ();
%{$$settings{$id}{incorrectfeedback}} = ();
%{$$settings{$id}{solutionfeedback}} = ();
- %{$$settings{$id}{question}} = ();
- %{$$settings{$id}{response}} = ();
}
if ("@state" eq "questestinterop assessment section item itemmetadata bbmd_questiontype") {
$$settings{$id}{class} = $text;
$curr_class = $text;
+ if ($curr_class eq 'Matching') {
+ $blockflow = 'flow flow';
+ } else {
+ $blockflow = 'flow';
+ }
}
- if ("@state" eq "questestinterop assessment section item presentation flow flow flow material mat_extension mat_formatted_text") {
+ if ("@state" eq "$presfrag $blockflow material mat_extension mat_formattedtext") {
$$settings{$id}{$curr_block_type}{text} = $text;
}
- if ("@state" eq "questestinterop section item presentation flow flow flow material mattext") {
- $$settings{$id}{$curr_block_type}{linktext} = $text;
- }
- if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow response_label flow_mat material mat_extension mat_formatted_text") {
- $$settings{$id}{$list}{text} = $text;
+ if ("@state" eq "$presfrag $blockflow material mattext") {
+ if ($curr_flow eq 'LINK_BLOCK') {
+ $$settings{$id}{$curr_block_type}{linkname} = $text;
+ } elsif ($curr_flow eq 'FORMATTED_TEXT_BLOCK') {
+ $$settings{$id}{$curr_block_type}{text} = $text;
+ }
}
- if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow response_label flow_mat material mattext") {
- $$settings{$id}{$list}{linktext} = $text;
+ if ("@state" eq "$presfrag $responselid render_choice flow_label response_label flow_mat material mat_extension mat_formattedtext") {
+ $$settings{$id}{$foil}{text} = $text;
+ }
+ if ("@state" eq "$presfrag $responselid render_choice flow_label response_label flow_mat material mattext") {
+ if ($curr_flow_mat eq 'LINK_BLOCK') {
+ $$settings{$id}{$foil}{linkname} = $text;
+ } else {
+ $$settings{$id}{$foil}{text} = $text;
+ }
}
- if ("@state" eq "questestinterop section item resprocessing respcondition conditionvar varequal") {
- if ($curr_class eq 'Multiple Choice') {
- $$settings{$id}{$list}{correctanswer}[0] = $text;
- } elsif ($curr_class eq 'True/False') {
- $$settings{$id}{correctanswer} = $text;
- } elsif ($curr_class eq 'Matching') {
+ if ("@state" eq "questestinterop assessment section item resprocessing respcondition conditionvar varequal") {
+ if ($curr_class eq 'Matching') {
$$settings{$id}{$curr_matchitem}{correctanswer} = $text;
- } elsif ($curr_class eq 'Fill in the Blank') {
- push(@{$$settings{$id}{$list}{correctanswer}},$text);
+ } else {
+ push(@{$$settings{$id}{correctanswer}},$text);
}
}
- if ("@state" eq "questestinterop section item resprocessing respcondition conditionvar and varequal") {
- push(@{$$settings{$id}{$list}{correctanswer}},$text);
+ if ("@state" eq "questestinterop assessment section item resprocessing respcondition conditionvar") {
+ $numorder = 0;
}
- if ("@state" eq "questestinterop section item itemfeedback flow_mat flow_mat material mat_extension mat_formattedtext") {
+ if ("@state" eq "questestinterop assessment section item resprocessing respcondition conditionvar and varequal") {
+ push(@{$$settings{$id}{correctanswer}},$text);
+ if ($curr_class eq 'Ordering') {
+ $numorder ++;
+ $$settings{$id}{$text}{order} = $numorder;
+ }
+ }
+ if ("@state" eq "$feedbackfrag $feedback_tag flow_mat flow_mat material mat_extension mat_formattedtext") {
$$settings{$id}{$curr_feedback_type.'feedback'}{text} = $text;
}
- if ("@state" eq "questestinterop section item itemfeedback flow_mat flow_mat material mattext") {
+ if ("@state" eq "$feedbackfrag $feedback_tag flow_mat flow_mat material mattext") {
$$settings{$id}{$curr_feedback_type.'feedback'}{linkname} = $text;
}
}, "dtext"],
@@ -2471,7 +2539,7 @@
if ($cms eq 'bb5') {
&parse_bb5_assessment($res,$docroot,$container,$settings,\%allanswers,\%allchoices,\@allids);
} elsif ($cms eq 'bb6') {
- &parse_bb6_assessment($res,$docroot,$container,$settings,\%allanswers,\%allchoices,\@allids);
+ &parse_bb6_assessment($res,$docroot,$container,$settings,\@allids);
} elsif ($cms eq 'webct4') {
unless($$dbparse) {
&parse_webct4_questionDB($docroot,$$resources{$res}{file},$catinfo,$qzdbsettings,\%alldbanswers,\%alldbchoices,\@alldbquestids);
@@ -2556,7 +2624,7 @@
if ($cms eq 'bb5') {
&write_bb5_questions(\@allids,$containerdir,$context,$settings,$dirname,$destdir,$res,\%allanswers,\%allchoices,$total,$newdir,$cid,$cdom,$cnum,$docroot);
} elsif ($cms eq 'bb6') {
- &write_bb6_questions(\@allids,$containerdir,$context,$settings,$dirname,$destdir,$res,\%allanswers,\%allchoices,$total,$newdir,$cid,$cdom,$cnum);
+ &write_bb6_questions(\@allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$total,$newdir,$cid,$cdom,$cnum,$docroot);
}
}
@@ -3549,7 +3617,373 @@
}
sub write_bb6_questions {
- my ($allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$allanswers,$allchoices) = @_;
+ my ($allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$total,$newdir,$cid,$cdom,$cnum,$docroot) = @_;
+ my $qnum = 0;
+ foreach my $id (@{$allids}) {
+ my $questiontext = $$settings{$id}{question}{text};
+ my $question_texttype = $$settings{$id}{question}{texttype};
+ &process_html(\$questiontext,'bb6',$question_texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir);
+ $qnum ++;
+ my $output;
+ my $permcontainer = $containerdir;
+ $permcontainer =~ s#/home/httpd/html/userfiles#uploaded#;
+ my $symb = $cid.'.'.$permcontainer.'___'.$qnum.'___lib/templates/simpleproblem.problem.0.';
+ my %resourcedata = ();
+ for (my $i=0; $i<10; $i++) {
+ my $iter = $i+1;
+ $resourcedata{$symb.'text'.$iter} = "";
+ $resourcedata{$symb.'value'.$iter} = "unused";
+ $resourcedata{$symb.'position'.$iter} = "random";
+ }
+ $resourcedata{$symb.'randomize'} = 'yes';
+ $resourcedata{$symb.'maxfoils'} = 10;
+ if ($context eq 'CSTR') {
+ $output = qq|<problem>
+|;
+ }
+ $$total{prob} ++;
+ $questiontext .= &add_images_links('question',$settings,$id,$dirname,$res);
+ if ($$settings{$id}{class} eq "Essay") {
+ if ($context eq 'CSTR') {
+ $output .= qq|<startouttext />$questiontext<endouttext />
+ <essayresponse>
+ <textfield></textfield>
+ </essayresponse>
+|;
+ } else {
+ $resourcedata{$symb.'questiontext'} = $questiontext;
+ $resourcedata{$symb.'hiddenparts'} = '!essay';
+ $resourcedata{$symb.'questiontype'} = 'essay';
+ }
+ } else {
+ if ($context eq 'CSTR') {
+ $output .= qq|<startouttext />$questiontext\n<endouttext />|;
+ } else {
+ $resourcedata{$symb.'questiontext'} = $questiontext;
+ }
+ my $numfoils = @{$$settings{$id}{answers}};
+ if (($$settings{$id}{class} eq 'Multiple Choice') ||
+ ($$settings{$id}{class} eq 'True/False')) {
+ if ($context eq 'CSTR') {
+ $output .= qq|
+ <radiobuttonresponse max="$numfoils" randomize="yes">
+ <foilgroup>
+|;
+ } else {
+ $resourcedata{$symb.'hiddenparts'} = '!radio';
+ $resourcedata{$symb.'questiontype'} = 'radio';
+ $resourcedata{$symb.'maxfoils'} = $numfoils;
+ }
+ for (my $k=0; $k<$numfoils; $k++) {
+ my $iter = $k+1;
+ my $answer_id = $$settings{$id}{answers}[$k];
+ my $answer_text = $$settings{$id}{$answer_id}{text};
+ my $texttype = $$settings{$id}{$answer_id}{texttype};
+ &process_html(\$answer_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir);
+ $answer_text .= &add_images_links('response',$settings,$id,$dirname,$res);
+ $output .= " <foil name=\"foil".$k."\" value=\"";
+ if (grep/^$answer_id$/,@{$$settings{$id}{correctanswer}}) {
+ $output .= "true\" location=\"";
+ $resourcedata{$symb.'value'.$iter} = "true";
+ } else {
+ $output .= "false\" location=\"";
+ $resourcedata{$symb.'value'.$iter} = "false";
+ }
+ if (lc ($$settings{$id}{$answer_id}{text}) =~ m/^\s?([Aa]ll)|([Nn]one)\s(of\s)?the\sabove\.?/) {
+ $output .= "bottom\"";
+ $resourcedata{$symb.'position'.$iter} = "bottom";
+ } else {
+ $output .= "random\"";
+ }
+ $output .= '\><startouttext />'.$answer_text.
+ '<endouttext /></foil>'."\n";
+ $resourcedata{$symb.'text'.$iter} = $answer_text;
+ }
+ if ($context eq 'CSTR') {
+ chomp($output);
+ $output .= qq|
+ </foilgroup>
+ <hintgroup showoncorrect="no">
+ <radiobuttonhint>
+ </radiobuttonhint>
+ <hintpart on="default">
+ <startouttext/><endouttext />
+ </hintpart>
+ </hintgroup>
+ </radiobuttonresponse>
+|;
+ }
+ } elsif ($$settings{$id}{class} eq 'Multiple Answer') {
+ if ($context eq 'CSTR') {
+ $output .= qq|
+ <optionresponse max="$numfoils" randomize="yes">
+ <foilgroup options="('True','False')">
+|;
+ } else {
+ $resourcedata{$symb.'newopt'} = '';
+ $resourcedata{$symb.'delopt'} = '';
+ $resourcedata{$symb.'options'} = "('True','False')";
+ $resourcedata{$symb.'hiddenparts'} = '!option';
+ $resourcedata{$symb.'questiontype'} = 'option';
+ $resourcedata{$symb.'maxfoils'} = $numfoils;
+ }
+ for (my $k=0; $k<$numfoils; $k++) {
+ my $iter = $k+1;
+ my $answer_id = $$settings{$id}{answers}[$k];
+ my $answer_text = $$settings{$id}{$answer_id}{text};
+ my $texttype = $$settings{$id}{$answer_id}{texttype};
+ &process_html(\$answer_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir);
+ $answer_text .= &add_images_links('response',$settings,$id,$dirname,$res);
+
+ $output .= " <foil name=\"foil".$k."\" value=\"";
+ if (grep/^$answer_id$/,@{$$settings{$id}{correctanswer}}) {
+ $output .= "True\"";
+ $resourcedata{$symb.'value'.$iter} = "True";
+ } else {
+ $output .= "False\"";
+ $resourcedata{$symb.'value'.$iter} = "False";
+ }
+ $output .= "\><startouttext />".$answer_text."<endouttext /></foil>\n";
+ $resourcedata{$symb.'text'.$iter} = $answer_text;
+ }
+ if ($context eq 'CSTR') {
+ chomp($output);
+ $output .= qq|
+ </foilgroup>
+ <hintgroup showoncorrect="no">
+ <optionhint>
+ </optionhint>
+ <hintpart on="default">
+ <startouttext/><endouttext />
+ </hintpart>
+ </hintgroup>
+ </optionresponse>
+|;
+ }
+ } elsif ($$settings{$id}{class} eq 'Ordering') {
+ my @allorder = ();
+ if ($context eq 'CSTR') {
+ $output .= qq|
+ <rankresponse max="$numfoils" randomize="yes">
+ <foilgroup>
+|;
+ } else {
+ $resourcedata{$symb.'newopt'} = '';
+ $resourcedata{$symb.'delopt'} = '';
+ $resourcedata{$symb.'hiddenparts'} = '!option';
+ $resourcedata{$symb.'questiontype'} = 'option';
+ $resourcedata{$symb.'maxfoils'} = $numfoils;
+ }
+ for (my $k=0; $k<$numfoils; $k++) {
+ my $answer_id = $$settings{$id}{answers}[$k];
+ my $answer_text = $$settings{$id}{$answer_id}{text};
+ my $texttype = $$settings{$id}{$answer_id}{texttype};
+ &process_html(\$answer_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir);
+ $answer_text .= &add_images_links('response',$settings,$id,$dirname,$res);
+ my $iter = $k+1;
+ if ($context eq 'CSTR') {
+ $output .= " <foil location=\"random\" name=\"foil".$k."\" value=\"".$$settings{$id}{$answer_id}{order}."\"><startouttext />".$answer_text."<endouttext /></foil>\n";
+ } else {
+ $resourcedata{$symb.'text'.$iter} = $answer_text;
+ $resourcedata{$symb.'value'.$iter} = $$settings{$id}{$answer_id}{order};
+ if (!grep/^$$settings{$id}{$answer_id}{order}$/,@allorder) {
+ push(@allorder,$$settings{$id}{$answer_id}{order});
+ }
+ }
+ }
+ if ($context eq 'CSTR') {
+ chomp($output);
+ $output .= qq|
+ </foilgroup>
+ </rankresponse>
+|;
+ } else {
+ @allorder = sort {$a <=> $b} @allorder;
+ $resourcedata{$symb.'options'} = "('".join("','",@allorder)."')";
+ }
+ } elsif ($$settings{$id}{class} eq 'Fill in the Blank') {
+ my $numerical = 1;
+ if ($context eq 'DOCS') {
+ $numerical = 0;
+ } else {
+ for (my $k=0; $k<@{$$settings{$id}{correctanswer}}; $k++) {
+ if ($$settings{$id}{correctanswer}[$k] =~ m/([^\d\.]|\.\.)/) {
+ $numerical = 0;
+ }
+ }
+ }
+ if ($numerical) {
+ my $numans;
+ my $tol;
+ if (@{$$settings{$id}{correctanswer}} == 1) {
+ $tol = 5;
+ $numans = $$settings{$id}{correctanswer}[0];
+ } else {
+ my $min = $$settings{$id}{correctanswer}[0];;
+ my $max = $min;
+ for (my $k=1; $k<@{$$settings{$id}{correctanswer}}; $k++) {
+ if ($$settings{$id}{correctanswer}[$k] <= $min) {
+ $min = $$settings{$id}{correctanswer}[$k];
+ }
+ if ($$settings{$id}{correctanswer}[$k] >= $max) {
+ $max = $$settings{$id}{correctanswer}[$k];
+ }
+ }
+ $numans = ($max + $min)/2;
+ $tol = 100*($max - $min)/($numans*2);
+ $tol = 5;
+ }
+ if ($context eq 'CSTR') {
+ $output .= qq|
+<numericalresponse answer="$numans">
+ <responseparam type="tolerance" default="$tol%" name="tol" description="Numerical Tolerance" />
+ <responseparam name="sig" type="int_range,0-16" default="0,15" description="Significant Figures"
+/>
+ <textline />
+</numericalresponse>
+<hintgroup showoncorrect="no">
+ <numericalhint>
+ </numericalhint>
+ <hintpart on="default">
+ <startouttext/><endouttext />
+ </hintpart>
+</hintgroup>
+|;
+ }
+ } else {
+ if ($context eq 'DOCS') {
+ $resourcedata{$symb.'hiddenparts'} = '!string';
+ $resourcedata{$symb.'questiontype'} = 'string';
+ $resourcedata{$symb.'maxfoils'} = 1;
+ $resourcedata{$symb.'hiddenparts'} = '!string';
+ $resourcedata{$symb.'stringtype'} = 'ci';
+ $resourcedata{$symb.'stringanswer'} = $$settings{$id}{correctanswer}[0];
+ } else {
+ if (@{$$settings{$id}{correctanswer}} == 1) {
+ $output .= qq|
+<stringresponse answer="$$settings{$id}{correctanswer}[0];" type="ci">
+<textline>
+</textline>
+</stringresponse>
+<hintgroup showoncorrect="no">
+<stringhint type="cs">
+</stringhint>
+<hintpart on="default">
+ <startouttext/><endouttext />
+</hintpart>
+</hintgroup>
+|;
+ } else {
+ my @answertext = ();
+ for (my $k=0; $k<@{$$settings{$id}{correctanswer}}; $k++) {
+ my $answer_text = $$settings{$id}{correctanswer}[$k];
+ $answer_text =~ s/\|/\|/g;
+ push @answertext, $answer_text;
+ }
+ my $regexpans = join('|',@answertext);
+ $regexpans = '/^('.$regexpans.')\b/';
+ $output .= qq|
+<stringresponse answer="$regexpans" type="re">
+<textline>
+</textline>
+</stringresponse>
+<hintgroup showoncorrect="no">
+ <stringhint type="cs">
+ </stringhint>
+ <hintpart on="default">
+ <startouttext/><endouttext />
+ </hintpart>
+</hintgroup>
+|;
+ }
+ }
+ }
+ } elsif ($$settings{$id}{class} eq "Matching") {
+ my @allmatchers = ();
+ my %matchtext = ();
+ if ($context eq 'CSTR') {
+ $output .= qq|
+<matchresponse max="10" randomize="yes">
+ <foilgroup>
+ <itemgroup>
+|;
+ } else {
+ $resourcedata{$symb.'newopt'} = '';
+ $resourcedata{$symb.'delopt'} = '';
+ $resourcedata{$symb.'hiddenparts'} = '!option';
+ $resourcedata{$symb.'questiontype'} = 'option';
+ $resourcedata{$symb.'maxfoils'} = $numfoils;
+ }
+ for (my $k=0; $k<$$settings{$id}{allchoices}; $k++) {
+ my $choice_id = 'rightmatch'.$k;
+ my $choice_text = $$settings{$id}{$choice_id}{text};
+ my $texttype = $$settings{$id}{$choice_id}{texttype};
+ my $choice_plaintext = &remove_html($choice_text);
+ &process_html(\$choice_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir);
+ $choice_text .= &add_images_links($choice_id,$settings,$id,$dirname,$res);
+ push(@allmatchers,$choice_plaintext);
+ if ($context eq 'CSTR') {
+ $output .= qq|
+<item name="$choice_id">
+<startouttext />$choice_text<endouttext />
+</item>
+ |;
+ }
+ }
+ if ($context eq 'CSTR') {
+ $output .= qq|
+ </itemgroup>
+|;
+ }
+ for (my $k=0; $k<$numfoils; $k++) {
+ my $answer_id = $$settings{$id}{answers}[$k];
+ my $answer_text = $$settings{$id}{$answer_id}{text};
+ my $texttype = $$settings{$id}{$answer_id}{texttype};
+ &process_html(\$answer_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir);
+ $answer_text .= &add_images_links($answer_id,$settings,$id,$dirname,$res);
+ if ($context eq 'CSTR') {
+ $output .= '
+ <foil location="random" value="rightmatch'.$$settings{$id}{$$settings{$id}{$answer_id}{correctanswer}}{order}.'" name="'.$answer_id.'">
+ <startouttext />'.$answer_text.'<endouttext />
+ </foil>
+';
+ } else {
+ my $iter = $k+1;
+ $resourcedata{$symb.'value'.$iter} = "$allmatchers[$$settings{$id}{$$settings{$id}{$answer_id}{correctanswer}}{order}]";
+ $resourcedata{$symb.'text'.$iter} = $answer_text;
+ }
+ }
+ if ($context eq 'CSTR') {
+ $output .= qq|
+ </foilgroup>
+</matchresponse>
+|;
+ } else {
+ $resourcedata{$symb.'options'} = "('".join("','",@allmatchers)."')";
+ }
+ }
+ }
+ if ($context eq 'CSTR') {
+
+ $output .= qq|
+ <postanswerdate>
+ $$settings{$id}{solutionfeedback}{text}
+ </postanswerdate>
+</problem>
+|;
+ my $title = $$settings{title};
+ $title =~ s/\s/_/g;
+ $title =~ s/\W//g;
+ $title .= '_'.$id;
+ open(PROB,">:utf8", "$newdir/$title.problem");
+ print PROB $output;
+ close PROB;
+ } else {
+# put %resourcedata;
+ my $reply=&Apache::lonnet::cput
+ ('resourcedata',\%resourcedata,$cdom,$cnum);
+ }
+ }
}
sub retrieve_image {
@@ -4136,5 +4570,49 @@
}
}
+sub process_html {
+ my ($text,$caller,$html_cond,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir) = @_;
+
+ if ($caller eq 'bb5') {
+ if ($html_cond eq 'true') {
+ $$text = &HTML::Entities::decode($$text);
+ }
+ } elsif ($caller eq 'bb6') {
+ if ($html_cond eq 'HTML') {
+ $$text = &HTML::Entities::decode($$text);
+ }
+ }
+ if ($$text =~ m#<img src=['"]?(https?://[^\s]+/)([^/\s\'"]+)['"]?[^>]*>#) {
+ if (&retrieve_image($context,$res,$dirname,$cdom,$cnum,$docroot,$destdir,$1,$2) eq 'ok') {
+ $$text =~ s#(<img src=['"]?)(https?://[^\s]+/)([^/\s'"]+)(['"]?[^>]*>)#$1../../resfiles/$res/webimages/$3$4#g;
+ }
+ }
+ $$text =~ s#(<img src=[^>]+)/*>#$1 />#gi;
+ $$text =~ s#<br>#<br />#g;
+ return;
+}
+
+sub add_images_links {
+ my ($type,$settings,$id,$dirname,$res) = @_;
+ my ($image,$imglink,$url);
+ if ((defined($$settings{$id}{$type}{image})) && ($$settings{$id}{$type}{image} ne '')) {
+ if ( $$settings{$id}{$type}{style} eq 'Inline' ) {
+ $image = qq|<br /><img src="../../resfiles/$res/$$settings{$id}{$type}{image}" alt="$$settings{$id}{$type}{label}"/><br />|;
+ } else {
+ $imglink = qq|<br /><a href="../../resfiles/$res/$$settings{$id}{$type}{image}">$$settings{$id}{$type}{label}</a><br />|;
+ }
+ }
+ if ((defined($$settings{$id}{$type}{link})) && ($$settings{$id}{$type}{link} ne '' )) {
+ $url = qq|<br /><a href="$$settings{$id}{$type}{link}">$$settings{$id}{$type}{linkname}</a><br />|;
+ }
+ return $image.$imglink.$url;
+}
+
+sub remove_html {
+ my ($choice_text) = @_;
+ return $choice_text;
+}
+
+
1;
__END__
--raeburn1130248486--