--- loncom/homework/matchresponse.pm 2003/10/27 19:27:09 1.28
+++ loncom/homework/matchresponse.pm 2004/01/06 20:16:17 1.32
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Full matching style response
#
-# $Id: matchresponse.pm,v 1.28 2003/10/27 19:27:09 albertel Exp $
+# $Id: matchresponse.pm,v 1.32 2004/01/06 20:16:17 sakharuk Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -123,6 +123,10 @@ sub end_itemgroup {
@names=&Apache::response::whichorder($#names+1,$randomize,0,
\%Apache::response::itemgroup);
}
+ if ($target eq 'analyze') {
+ my $partid="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
+ push (@{ $Apache::lonhomework::analyze{"$partid.items"} }, @names);
+ }
my %letter_name_map;
my %name_letter_map;
my @alphabet=('A'..'Z');
@@ -163,7 +167,7 @@ sub end_itemgroup {
sub start_item {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result='';
- if ($target eq 'web' || $target eq 'tex') {
+ if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
&Apache::lonxml::startredirection;
} elsif ($target eq 'edit') {
my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
@@ -189,11 +193,11 @@ sub end_item {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $text ='';
my $result = '';
- if ($target eq 'web' || $target eq 'tex') {
+ if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
$text=&Apache::lonxml::endredirection;
}
if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
- $target eq 'edit' || $target eq 'tex') {
+ $target eq 'edit' || $target eq 'tex' || $target eq 'analyze') {
my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
my $location=&Apache::lonxml::get_param('location',$parstack,
$safeeval);
@@ -251,7 +255,7 @@ sub end_foilgroup {
} elsif ( $target eq 'analyze') {
my @shown=&whichfoils($max,$randomize);
&Apache::response::analyze_store_foilgroup(\@shown,
- ['text','value']);
+ ['text','value','location']);
#FIXME need to store options in some way
}
&Apache::lonxml::increment_counter(&getfoilcounts($max));
@@ -261,6 +265,14 @@ sub end_foilgroup {
return $result;
}
+sub whichfoils {
+ my ($max,$randomize)=@_;
+ return &Apache::response::whichorder(&getfoilcounts($max),
+ $randomize,
+ &Apache::response::showallfoils(),
+ \%Apache::response::foilgroup);
+}
+
sub displayanswers {
my ($max,$randomize,@opt)=@_;
if (!defined(@{ $Apache::response::foilgroup{'names'} })) { return; }
@@ -300,12 +312,14 @@ sub grade_response {
%letter_name_map=
%{ $Apache::response::itemgroup{'letter_name_map'} };
}
+ my @items;
foreach my $name (@whichfoils) {
my $response = &Apache::response::getresponse($temp);
+ push(@items,$response);
my $responsename = $letter_name_map{$response};
- $responsehash{$name}=$responsename;
my $value=$Apache::response::foilgroup{$name.'.value'};
if ( $response =~ /[^\s]/) {
+ $responsehash{$name}=$responsename;
&Apache::lonxml::debug("submitted a $response for $value
\n");
if ($value eq $responsename) {
$grade{$name}='1'; $right++;
@@ -320,9 +334,9 @@ sub grade_response {
my $part=$Apache::inputtags::part;
my $id = $Apache::inputtags::response['-1'];
my $responsestr=&Apache::lonnet::hash2str(%responsehash);
+ my $itemstr =&Apache::lonnet::array2str(@items);
my $gradestr =&Apache::lonnet::hash2str(%grade);
- my %previous =&Apache::response::check_for_previous($responsestr,
- $part,$id);
+ my %previous=&Apache::response::check_for_previous($responsestr,$part,$id);
&Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored ");
my $ad;
if ($wrong==0 && $ignored==0) {
@@ -338,6 +352,8 @@ sub grade_response {
}
$Apache::lonhomework::results{"resource.$part.$id.submission"}=
$responsestr;
+ $Apache::lonhomework::results{"resource.$part.$id.submissionitems"}=
+ $itemstr;
$Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=
$gradestr;
$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
@@ -449,11 +465,19 @@ sub displayfoils {
} elsif ($result=&itemdisplay('bottom')) {
$result=$question.$result;
} elsif ($result=&itemdisplay('right')) {
- $result='
'.$question.' | '.$result.
- ' |
';
+ if ($target ne 'tex') {
+ $result=''.$question.' | '.$result.
+ ' |
';
+ } else {
+ $result='\begin{tabular}{p{\textwidth/2}p{\textwidth/2}}\begin{minipage}{\textwidth/2}'.$question.'\end{minipage}&\begin{minipage}{\textwidth/2}'.$result.'\end{minipage}\end{tabular}';
+ }
} elsif ($result=&itemdisplay('left')) {
- $result=''.$result.' | '.$question.
- ' |
';
+ if ($target ne 'tex') {
+ $result=''.$result.' | '.$question.
+ ' |
';
+ } else {
+ $result='\begin{tabular}{p{\textwidth/2}p{\textwidth/2}}\begin{minipage}{\textwidth/2}'.$result.'\end{minipage}&\begin{minipage}{\textwidth/2}'.$question.'\end{minipage}\end{tabular}';
+ }
}
if ($target ne 'tex') {$result.="
";} else {$result.=' \\\\ ';}
return $result;