--- loncom/homework/caparesponse/caparesponse.pm 2007/05/22 00:45:43 1.214 +++ loncom/homework/caparesponse/caparesponse.pm 2008/02/01 23:00:56 1.221 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # caparesponse definition # -# $Id: caparesponse.pm,v 1.214 2007/05/22 00:45:43 albertel Exp $ +# $Id: caparesponse.pm,v 1.221 2008/02/01 23:00:56 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -392,9 +392,6 @@ sub setup_capa_args { sub setup_capa_response { my ($args_ref,$response) = @_; - use Data::Dumper; - &Apache::lonxml::debug("response dump is ".&Dumper($response)); - if (ref($response)) { $$args_ref{'response'}=dclone($response); } else { @@ -434,6 +431,10 @@ sub check_submission { &add_in_tag_answer($parstack,$safeeval); + if (!%answer) { + &Apache::lonxml::error("No answers are defined"); + } + my (@final_awards,@final_msgs,@names); foreach my $name (keys(%answer)) { &Apache::lonxml::debug(" doing $name with ".join(':',@{ $answer{$name}{'answers'} })); @@ -786,7 +787,16 @@ sub end_numericalresponse { } if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') { - &Apache::lonxml::increment_counter($increment); + if (($tag eq 'formularesponse') && ($target eq 'analyze')) { + my $type = &Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.type'); + if ($type eq 'exam') { + $increment = &Apache::response::repetition(); + } + } + &Apache::lonxml::increment_counter($increment,"$partid.$id"); + if ($target eq 'analyze') { + &Apache::lonhomework::set_bubble_lines(); + } } &Apache::response::end_response(); return $result; @@ -824,8 +834,6 @@ sub check_for_answer_errors { } (sort(keys(%counts)))); &Apache::lonxml::error(&mt("All answers must have the same number of components. Varying numbers of answers were seen. ").$counts); } - use Data::Dumper; - &Apache::lonxml::debug("count dump is ".&Dumper(\%counts)); my $expected_number_of_inputs = (keys(%counts))[0]; if ( $expected_number_of_inputs > 0 && $expected_number_of_inputs != scalar(@Apache::inputtags::inputlist)) { @@ -864,7 +872,13 @@ sub get_table_sizes { my $bubbles_per_line=int($textwidth/$cell_width); if ($bubbles_per_line > $number_of_bubbles) { $bubbles_per_line=$number_of_bubbles; - }elsif (($bubbles_per_line > $number_of_bubbles/2) && ($number_of_bubbles % 2==0)) {$bubbles_per_line=$number_of_bubbles/2;} + } elsif (($bubbles_per_line > $number_of_bubbles/2) + && ($number_of_bubbles % 2==0)) { + $bubbles_per_line=$number_of_bubbles/2; + } + if ($bubbles_per_line < 1) { + $bubbles_per_line=1; + } my $number_of_tables = int($number_of_bubbles/$bubbles_per_line); my @table_range = (); for (my $i=0;$i<$number_of_tables;$i++) {push @table_range,$bubbles_per_line;} @@ -899,6 +913,11 @@ sub format_number { sub make_numerical_bubbles { my ($part,$id,$target,$parstack,$safeeval) =@_; + + if (!%answer) { + &Apache::lonxml::error(&mt("No answers defined for response [_1] in part [_2] to make bubbles for.",$id,$part)); + return ([],[],undef); + } my $number_of_bubbles = &Apache::response::get_response_param($part.'_'.$id,'numbubbles',8); @@ -999,7 +1018,8 @@ sub get_sigrange { my ($sig)=@_; #&Apache::lonxml::debug("Got a sig of :$sig:"); my $courseid=$env{'request.course.id'}; - if (lc($env{"course.$courseid.disablesigfigs"}) eq 'yes') { + if ($env{'request.state'} ne 'construct' + && lc($env{"course.$courseid.disablesigfigs"}) eq 'yes') { return (15,0); } my $sig_lbound; @@ -1216,7 +1236,11 @@ sub end_stringresponse { } if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') { - &Apache::lonxml::increment_counter(&Apache::response::repetition()); + &Apache::lonxml::increment_counter(&Apache::response::repetition(), + "$part.$id"); + if ($target eq 'analyze') { + &Apache::lonhomework::set_bubble_lines(); + } } &Apache::response::end_response; return $result;