--- loncom/homework/radiobuttonresponse.pm 2005/06/22 12:03:23 1.102
+++ loncom/homework/radiobuttonresponse.pm 2008/12/11 03:25:45 1.141
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# mutliple choice style responses
#
-# $Id: radiobuttonresponse.pm,v 1.102 2005/06/22 12:03:23 albertel Exp $
+# $Id: radiobuttonresponse.pm,v 1.141 2008/12/11 03:25:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -18,54 +18,77 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with LON-CAPA; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# along with LON-CAPA; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
+
+
package Apache::radiobuttonresponse;
use strict;
use HTML::Entities();
use Apache::lonlocal;
use Apache::lonnet;
+use Apache::response;
+
+my $default_bubbles_per_line = 10;
+
BEGIN {
&Apache::lonxml::register('Apache::radiobuttonresponse',('radiobuttonresponse'));
}
+sub bubble_line_count {
+ my ($numfoils, $bubbles_per_line) = @_;
+ my $bubble_lines;
+ $bubble_lines = int($numfoils / $bubbles_per_line);
+ if (($numfoils % $bubbles_per_line) != 0) {
+ $bubble_lines++;
+ }
+ return $bubble_lines;
+
+}
+
+
sub start_radiobuttonresponse {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
+
#when in a radiobutton response use these
&Apache::lonxml::register('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
push (@Apache::lonxml::namespace,'radiobuttonresponse');
my $id = &Apache::response::start_response($parstack,$safeeval);
+
%Apache::hint::radiobutton=();
undef(%Apache::response::foilnames);
if ($target eq 'meta') {
$result=&Apache::response::meta_package_write('radiobuttonresponse');
} elsif ($target eq 'edit' ) {
- $result.=&Apache::edit::start_table($token).
- '
"; }
+ if ($target ne 'tex') {
+ if (($direction eq 'horizontal') && ($target ne 'tex')) { $result.=""; }
+ } else {
+ $result.='\vskip 0 mm ';
+ }
}
}
}
- if ($direction eq 'horizontal') { $result.='
'; }
+
+ if (($direction eq 'horizontal') && ($target ne 'tex')) { $result.=''; }
return $result;
}
+
sub whichfoils {
my ($max,$randomize)=@_;
@@ -289,7 +415,7 @@ sub whichfoils {
my ($truecnt,$falsecnt) = &getfoilcounts();
my $count=0;
# we will add in 1 of the true statements
- if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; }
+ if ( $max>0 && ($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; $max=$count; }
my $answer=int(&Math::Random::random_uniform() * ($count));
&Apache::lonxml::debug("Count is $count, $answer is $answer");
my @names;
@@ -314,7 +440,7 @@ sub whichfoils {
}
}
if (!$havetrue && $Apache::lonhomework::type ne 'survey') {
- &Apache::lonxml::error("There are no true statements available. ");
+ &Apache::lonxml::error(&mt('There are no true statements available.').' ');
}
} else {
my $current=0;
@@ -375,7 +501,7 @@ sub whichfoils {
my $dosplice=1;
if ($notrue && $Apache::lonhomework::type ne 'survey') {
$dosplice=0;
- &Apache::lonxml::error("There are no true statements available. ");
+ &Apache::lonxml::error(&mt('There are no true statements available.').' ');
}
#insert the true statement, keeping track of where it wants to be
if ($Apache::response::foilgroup{$truename.'.location'} eq 'top' && $dosplice) {
@@ -417,10 +543,9 @@ sub whichfoils {
}
sub displayfoils {
- my ($target,$max,$randomize,$direction)=@_;
+ my ($target,$answer,$whichfoils,$direction, $bubbles_per_line)=@_;
my $result;
- my ($answer,@whichfoils)=&whichfoils($max,$randomize);
my $part=$Apache::inputtags::part;
my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
if ( ($target ne 'tex') &&
@@ -430,7 +555,7 @@ sub displayfoils {
$result.='
';
}
}
- foreach my $name (@whichfoils) {
+ foreach my $name (@{ $whichfoils }) {
if ($direction eq 'horizontal') {
if ($target ne 'tex') { $result.='
'; }
}
@@ -440,9 +565,13 @@ sub displayfoils {
$result.='\item \vskip -2 mm ';
}
if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
- if ($target ne 'tex') { $result.='Correct:'; } else { $result.='Correct: \textbf{';}
+ if ($target ne 'tex') {
+ $result.=&mt('Correct:').'';
+ } else {
+ $result.=&mt('Correct:').' \textbf{';
+ }
} else {
- $result.='Incorrect:';
+ $result.=&mt('Incorrect:');
}
if ($target eq 'web') { $result.=""; }
$result.=$Apache::response::foilgroup{$name.'.text'};
@@ -462,6 +591,8 @@ sub displayfoils {
} else {
my @alphabet = ('A'..'Z');
my $i = 0;
+ my $bubble_number = 0;
+ my $line = 0;
my $temp=0;
my $id=$Apache::inputtags::response['-1'];
my $part=$Apache::inputtags::part;
@@ -470,7 +601,7 @@ sub displayfoils {
if ($target ne 'tex' && $direction eq 'horizontal') {
$result.="
";
}
- foreach my $name (@whichfoils) {
+ foreach my $name (@{ $whichfoils }) {
if ($target ne 'tex') {
if ($direction eq 'horizontal') {
$result.="
";
@@ -505,8 +658,10 @@ sub displayfoils {
}
sub displayallanswers {
- my @names = @{ $Apache::response::foilgroup{'names'} };
-
+ my @names;
+ if ( $Apache::response::foilgroup{'names'} ) {
+ @names= @{ $Apache::response::foilgroup{'names'} };
+ }
my $result=&Apache::response::answer_header('radiobuttonresponse');
foreach my $name (@names) {
$result.=&Apache::response::answer_part('radiobuttonresponse',
@@ -517,13 +672,23 @@ sub displayallanswers {
}
sub displayanswers {
- my ($max,$randomize)=@_;
- my ($answer,@whichopt) = &whichfoils($max,$randomize);
- my $result=&Apache::response::answer_header('radiobuttonresponse');
- foreach my $name (@whichopt) {
+ my ($answer, $whichopt, $bubbles_per_line)=@_;
+ my $result;
+
+ if ($Apache::lonhomework::type eq 'exam') {
+ my $line = int($answer/$bubbles_per_line);
+ my $correct = ('A'..'Z')[$answer%$bubbles_per_line];
+ $result .= &Apache::response::answer_header('radiobuttonresponse',
+ $line);
+ $result .= &Apache::response::answer_part('radiobuttonresponse',
+ $correct);
+ } else {
+ $result .= &Apache::response::answer_header('radiobuttonresponse');
+ }
+ foreach my $name (@{ $whichopt }) {
$result.=&Apache::response::answer_part('radiobuttonresponse',
- $Apache::response::foilgroup{$name.'.value'})
- }
+ $Apache::response::foilgroup{$name.'.value'});
+ }
$result.=&Apache::response::answer_footer('radiobuttonresponse');
return $result;
}
@@ -608,11 +773,11 @@ sub end_foil {
if ($value ne 'unused') {
my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
if ($name eq "") {
- &Apache::lonxml::warning("Foils without names exist. This can cause problems to malfunction.");
+ &Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
$name=$Apache::lonxml::curdepth;
}
if (defined($Apache::response::foilnames{$name})) {
- &Apache::lonxml::error(&mt("Foil name [_1] appears more than once. Foil names need to be unique.",$name));
+ &Apache::lonxml::error(&mt('Foil name [_1] appears more than once. Foil names need to be unique.',''.$name.''));
}
$Apache::response::foilnames{$name}++;
my $location =&Apache::lonxml::get_param('location',$parstack,
@@ -643,4 +808,87 @@ sub insert_foil {
}
1;
__END__
+
+
+
+=head1 NAME
+
+Apache::radiobuttonresponse
+
+=head1 SYNOPSIS
+
+Handles multiple-choice style responses.
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 SUBROUTINES
+
+=over
+
+=item start_radiobuttonresponse()
+
+=item bubble_line_count()
+
+=item end_radiobuttonresponse()
+
+=item start_foilgroup()
+
+=item storesurvey()
+
+=item grade_response()
+
+=item end_foilgroup()
+
+=item getfoilcounts()
+
+=item format_prior_answer()
+
+=item displayallfoils()
+
+=item &whichfoils($max,$randomize)
+
+Randomizes the list of foils.
+Respects
+ - each foils desire to be randomized
+ - the existance of Concept groups of foils (select 1 foil from each)
+ - and selects a single correct statement from all possilble true statments
+ - and limits it to a toal of $max foils
+
+WARNING: this routine uses the random number generator, it should only
+be called once per target, otherwise it can cause randomness changes in
+homework problems.
+
+Arguments
+ $max - maximum number of foils to select (including the true one)
+ (so a max of 5 is: 1 true, 4 false)
+
+ $randomize - whether to randomize the listing of foils, by default
+ will randomize, only if randomize is 'no' will it not
+
+Returns
+ $answer - location in the array of the correct answer
+ @foils - array of foil names in to display order
+
+=item displayfoils()
+
+=item displayallanswers()
+
+=item displayanswers()
+
+=item start_conceptgroup()
+
+=item end_conceptgroup()
+
+=item insert_conceptgroup()
+
+=item start_foil()
+
+=item end_foil()
+
+=item insert_foil()
+
+=back
+
+=cut