--- loncom/homework/matchresponse.pm 2009/12/09 11:30:45 1.78
+++ loncom/homework/matchresponse.pm 2011/11/08 01:48:51 1.81.2.1
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Full matching style response
#
-# $Id: matchresponse.pm,v 1.78 2009/12/09 11:30:45 foxr Exp $
+# $Id: matchresponse.pm,v 1.81.2.1 2011/11/08 01:48:51 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -131,7 +131,11 @@ sub end_itemgroup {
my $result;
if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
- if (!defined(@{ $Apache::response::itemgroup{'names'} })) { return; }
+ if (ref($Apache::response::itemgroup{'names'}) eq 'ARRAY') {
+ if(!@{ $Apache::response::itemgroup{'names'} }) { return; }
+ } else {
+ return;
+ }
my @names=@{ $Apache::response::itemgroup{'names'} };
my $randomize =&Apache::lonxml::get_param('randomize',$parstack,$safeeval);
if ($randomize ne 'no' ) {
@@ -252,7 +256,7 @@ sub start_foilgroup {
my $result;
%Apache::response::foilgroup=();
$Apache::matchresponse::conceptgroup=0;
- &Apache::response::pushrandomnumber();
+ &Apache::response::pushrandomnumber(undef,$target);
if ($target eq 'edit') {
$result.=&Apache::edit::start_table($token)
.'
'.&mt('Collection Of Foils').' | '
@@ -311,16 +315,22 @@ sub whichfoils {
sub displayanswers {
my ($max,$randomize,@opt)=@_;
- if (!defined(@{ $Apache::response::foilgroup{'names'} })) { return; }
+ if (ref($Apache::response::foilgroup{'names'}) eq 'ARRAY') {
+ if (!@{ $Apache::response::foilgroup{'names'} }) { return; }
+ } else {
+ return;
+ }
my @names = @{ $Apache::response::foilgroup{'names'} };
my @whichfoils = &Apache::response::whichorder(&getfoilcounts($max),
$randomize,
&Apache::response::showallfoils(),
\%Apache::response::foilgroup);
my %name_letter_map;
- if (defined(%{ $Apache::response::itemgroup{'name_letter_map'} })) {
- %name_letter_map=
- %{ $Apache::response::itemgroup{'name_letter_map'} };
+ if (ref($Apache::response::itemgroup{'name_letter_map'}) eq 'HASH') {
+ if (%{$Apache::response::itemgroup{'name_letter_map'}}) {
+ %name_letter_map=
+ %{ $Apache::response::itemgroup{'name_letter_map'} };
+ }
}
my $result;
if ($Apache::lonhomework::type eq 'exam') {
@@ -354,11 +364,14 @@ sub grade_response {
if (!&Apache::response::submitted()) { return; }
my %responsehash;
my %grade;
+ my %answerhash;
my ($temp,$right,$wrong,$ignored)=(1,0,0,0);
my %letter_name_map;
- if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) {
- %letter_name_map=
- %{ $Apache::response::itemgroup{'letter_name_map'} };
+ if (ref($Apache::response::itemgroup{'letter_name_map'}) eq 'HASH') {
+ if (%{$Apache::response::itemgroup{'letter_name_map'}}) {
+ %letter_name_map=
+ %{ $Apache::response::itemgroup{'letter_name_map'} };
+ }
}
my @items;
foreach my $name (@whichfoils) {
@@ -366,6 +379,9 @@ sub grade_response {
push(@items,$response);
my $responsename = $letter_name_map{$response};
my $value=$Apache::response::foilgroup{$name.'.value'};
+ if ($Apache::lonhomework::type eq 'randomizetry') {
+ $answerhash{$name} = $value;
+ }
if ( $response =~ /[^\s]/) {
$responsehash{$name}=$responsename;
&Apache::lonxml::debug("submitted a $response($responsename) for $value
\n");
@@ -392,9 +408,24 @@ sub grade_response {
$itemstr;
$Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=
$gradestr;
- if ($Apache::lonhomework::type eq 'survey') {
+ if ($Apache::lonhomework::type eq 'randomizetry') {
+ $Apache::lonhomework::results{"resource.$part.$id.foilorder"} = &Apache::lonnet::array2str(@whichfoils);
+ }
+ if (($Apache::lonhomework::type eq 'survey') ||
+ ($Apache::lonhomework::type eq 'surveycred') ||
+ ($Apache::lonhomework::type eq 'anonsurvey') ||
+ ($Apache::lonhomework::type eq 'anonsurveycred')) {
if ($ignored == 0) {
- my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED';
+ my $ad;
+ if ($Apache::lonhomework::type eq 'anonsurvey') {
+ $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS';
+ } elsif ($Apache::lonhomework::type eq 'anonsurveycred') {
+ $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS_CREDIT';
+ } elsif ($Apache::lonhomework::type eq 'surveycred') {
+ $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED_CREDIT';
+ } else {
+ $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED';
+ }
&Apache::response::handle_previous(\%previous,$ad);
} elsif ($wrong==0 && $right==0) {
} else {
@@ -475,14 +506,18 @@ sub displayfoils {
my $part=$Apache::inputtags::part;
my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
my %letter_name_map;
- if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) {
- %letter_name_map=
- %{ $Apache::response::itemgroup{'letter_name_map'} };
+ if (ref($Apache::response::itemgroup{'letter_name_map'}) eq 'HASH') {
+ if (%{$Apache::response::itemgroup{'letter_name_map'}}) {
+ %letter_name_map=
+ %{ $Apache::response::itemgroup{'letter_name_map'} };
+ }
}
my %name_letter_map;
- if (defined(%{ $Apache::response::itemgroup{'name_letter_map'} })) {
- %name_letter_map=
- %{ $Apache::response::itemgroup{'name_letter_map'} };
+ if (ref($Apache::response::itemgroup{'name_letter_map'}) eq 'HASH') {
+ if (%{$Apache::response::itemgroup{'name_letter_map'}}) {
+ %name_letter_map=
+ %{ $Apache::response::itemgroup{'name_letter_map'} };
+ }
}
if ( &Apache::response::show_answer() && ($target ne 'tex')) {
foreach my $name (@whichfoils) {
@@ -500,7 +535,18 @@ sub displayfoils {
my $temp=1;
my $id=$Apache::inputtags::response[-1];
my $part=$Apache::inputtags::part;
- my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
+ my ($lastresponse,$newvariation);
+ if ((($Apache::lonhomework::history{"resource.$part.type"} eq 'randomizetry') ||
+ ($Apache::lonhomework::type eq 'randomizetry')) &&
+ ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
+ if ($env{'form.'.$part.'.rndseed'} ne
+ $Apache::lonhomework::history{"resource.$part.rndseed"}) {
+ $newvariation = 1;
+ }
+ }
+ unless ((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred') && (defined($env{'form.grade_symb'}))) || $newvariation) {
+ $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
+ }
my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
my @alphabet=('A'..'Z');
my @used_letters=sort(keys(%letter_name_map));
@@ -527,16 +573,18 @@ sub displayfoils {
foreach $option (@used_letters) {
if ($option eq $last_letter) {
if ($target ne 'tex') {
- $optionlist.="\n";
+ $optionlist.="\n";
} elsif ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
- && $Apache::inputtags::status['-1'] eq 'CAN_ANSWER') {
+ && $Apache::inputtags::status['-1'] eq 'CAN_ANSWER'
+ && $Apache::lonhomework::type ne 'exam') {
$optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
}
} else {
if ($target ne 'tex') {
$optionlist.="\n";
} elsif ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
- && $Apache::inputtags::status['-1'] eq 'CAN_ANSWER') {
+ && $Apache::inputtags::status['-1'] eq 'CAN_ANSWER'
+ && $Apache::lonhomework::type ne 'exam') {
$optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
}
}
@@ -581,7 +629,7 @@ sub displayfoils {
# Note that if left or right positioned, we must
# confine the bubbles to righttabsize:
#
- if ($Apache::lonhomework::type eq 'exam' && $env{'form.pdfFormFields'} ne 'yes') {
+ if ($Apache::lonhomework::type eq 'exam') {
$question.=' '.$optionlist.$text."\n";
my @emptyItems = ();
for (my $i=0;$i<=$#used_letters;$i++) {push @emptyItems, ' ';}
@@ -635,10 +683,15 @@ sub displayfoils {
}
}
if ($target eq 'web') {
+ my $questiontype;
+ if ($Apache::lonhomework::type eq 'randomizetry') {
+ $questiontype = $Apache::lonhomework::type;
+ }
&Apache::response::setup_prior_tries_hash(\&format_prior_answer,
[\@whichfoils,
'submissiongrading',
- 'submissionitems']);
+ 'submissionitems'],
+ $questiontype);
}
if ($target ne 'tex') {$result.="
";} else {$result.=' \\\\ ';}
return $result;
@@ -709,9 +762,11 @@ sub start_foil {
if ($$tagstack[-2] eq 'conceptgroup') { $level = '-3'; }
$result.=&Apache::edit::text_arg('Name:','name',$token);
my @names;
- if (defined(@{ $Apache::response::itemgroup{'names'} })) {
- @names=@{ $Apache::response::itemgroup{'names'} };
- }
+ if (ref($Apache::response::itemgroup{'names'}) eq 'ARRAY') {
+ if (@{ $Apache::response::itemgroup{'names'} }) {
+ @names=@{ $Apache::response::itemgroup{'names'} };
+ }
+ }
$result.= &Apache::edit::select_or_text_arg('Correct Option:','value',['unused',@names],$token,'15');
my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
$safeeval,'-3');