Diff for /loncom/homework/matchresponse.pm between versions 1.83 and 1.88

version 1.83, 2011/10/07 22:39:59 version 1.88, 2013/04/25 17:58:32
Line 34  use Apache::optionresponse(); Line 34  use Apache::optionresponse();
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::lonxml;  use Apache::lonxml;
   use POSIX qw(ceil);
   
 BEGIN {  BEGIN {
     &Apache::lonxml::register('Apache::matchresponse',('matchresponse'));      &Apache::lonxml::register('Apache::matchresponse',('matchresponse'));
Line 103  sub start_itemgroup { Line 104  sub start_itemgroup {
     if ($target eq 'edit') {      if ($target eq 'edit') {
  $result=&Apache::edit::tag_start($target,$token);   $result=&Apache::edit::tag_start($target,$token);
  $result.=&Apache::edit::select_arg('Randomize Order:','randomize',   $result.=&Apache::edit::select_arg('Randomize Order:','randomize',
    ['yes','no'],$token).' 'x 3;     ['yes','no'],$token);
  $result.=&Apache::edit::select_arg('Items Display Location:',   $result.=&Apache::edit::select_arg('Items Display Location:',
    'location',     'location',
    ['top','bottom','left','right'],     ['top','bottom','left','right'],
    $token).' 'x 3;     $token);
  $result.=&Apache::edit::select_arg('Items Display Direction:',   $result.=&Apache::edit::select_arg('Items Display Direction:',
    'direction',     'direction',
    ['vertical','horizontal'],     ['vertical','horizontal'],
    $token);     $token);
           $result.=&Apache::edit::select_arg('Items Columns:',
                                              'columns',
                                              [['','default'],'1','2','3','4'],
                                               $token);
  $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();   $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
     } elsif ($target eq 'modified') {      } elsif ($target eq 'modified') {
  my $constructtag=&Apache::edit::get_new_args($token,$parstack,   my $constructtag=&Apache::edit::get_new_args($token,$parstack,
      $safeeval,'randomize',       $safeeval,'randomize',
      'location','direction');       'location','direction',
                                                        'columns');
  if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }   if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
     } elsif ($target eq 'web' or $target eq 'tex') {      } elsif ($target eq 'web' or $target eq 'tex') {
  $Apache::matchresponse::itemtable{'location'}=   $Apache::matchresponse::itemtable{'location'}=
Line 131  sub end_itemgroup { Line 137  sub end_itemgroup {
     my $result;      my $result;
   
     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }      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 @names=@{ $Apache::response::itemgroup{'names'} };
     my $randomize =&Apache::lonxml::get_param('randomize',$parstack,$safeeval);      my $randomize =&Apache::lonxml::get_param('randomize',$parstack,$safeeval);
     if ($randomize ne 'no' ) {      if ($randomize ne 'no' ) {
Line 154  sub end_itemgroup { Line 164  sub end_itemgroup {
     $Apache::response::itemgroup{'letter_name_map'}=\%letter_name_map;      $Apache::response::itemgroup{'letter_name_map'}=\%letter_name_map;
     $Apache::response::itemgroup{'name_letter_map'}=\%name_letter_map;      $Apache::response::itemgroup{'name_letter_map'}=\%name_letter_map;
     my $direction=&Apache::lonxml::get_param('direction',$parstack,$safeeval);      my $direction=&Apache::lonxml::get_param('direction',$parstack,$safeeval);
       my $columns=&Apache::lonxml::get_param('columns',$parstack,$safeeval);
       
       unless ($columns =~ /^\d+$/) {
           undef($columns);
       }
     if ($target eq 'web') {      if ($target eq 'web') {
   
  my $table='<br /><table>'; # extra space to match what latex does.   my $table='<br /><table>'; # extra space to match what latex does.
  my $i=0;          if ((!$columns) || ($columns < 0)) {
  if ($direction eq 'horizontal') { $table .='<tr>';}              if ($direction eq 'horizontal') {
  foreach my $name (@names) {                  if (@names > 0) { 
     if ($direction ne 'horizontal') { $table.='<tr>'; }                      $columns = scalar(@names);
     $table.='<td>'.$alphabet[$i].'</td><td>'.                  } else {
  $Apache::response::itemgroup{$name.'.text'}.'</td>';                      $columns = 1;
     if ($direction ne 'horizontal') { $table.='</tr>'; }                  }
     $i++;              } else {
  }                  $columns = 1;
  if ($direction eq 'horizontal') { $table .='</tr>';}              }
           }
           my $rows=ceil(scalar(@names)/$columns);
           my $endloop = $columns*$rows;
           for (my $i=0; $i<$endloop; $i++) {
               my $label = '&nbsp;';
               my $item = '&nbsp;';
               my $index;
               if ($direction eq 'horizontal') {
                   $index = $i;
               } else {
                   $index = ($i % $columns)*$rows+int($i/$columns);
               }
               if ($index < scalar(@names)) {
                   $label = $alphabet[$index];
                   $item = $Apache::response::itemgroup{$names[$index].'.text'};
               }
               if ($i % $columns == 0) {
                   $table.='<tr>';
               }
               $table.= '<td>'.$label.'</td><td>'.$item.'</td>';
               if ($columns > 1) {
                   $table .= '<td>&nbsp;</td>';
               }
               if ( ! (($i+1) % $columns) ) {
                   $table.='</tr>';
               }
           }
  $table.='</table>';   $table.='</table>';
  $Apache::matchresponse::itemtable{'display'}=$table;   $Apache::matchresponse::itemtable{'display'}=$table;
  $Apache::lonxml::post_evaluate=0;   $Apache::lonxml::post_evaluate=0;
Line 220  sub start_item { Line 262  sub start_item {
  $result=&Apache::edit::tag_start($target,$token,"Item");   $result=&Apache::edit::tag_start($target,$token,"Item");
  $result.=&Apache::edit::text_arg('Name:','name',$token);   $result.=&Apache::edit::text_arg('Name:','name',$token);
  if ($randomize ne 'no') {   if ($randomize ne 'no') {
     $result.='&nbsp;'x 3 .      $result.=
                      &Apache::edit::select_arg('Location:','location',                       &Apache::edit::select_arg('Location:','location',
        ['random','top','bottom'],         ['random','top','bottom'],
        $token);         $token);
Line 345  sub whichfoils { Line 387  sub whichfoils {
   
 sub displayanswers {  sub displayanswers {
     my ($max,$randomize,@opt)=@_;      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 @names = @{ $Apache::response::foilgroup{'names'} };
     my @whichfoils = &Apache::response::whichorder(&getfoilcounts($max),      my @whichfoils = &Apache::response::whichorder(&getfoilcounts($max),
    $randomize,     $randomize,
   &Apache::response::showallfoils(),    &Apache::response::showallfoils(),
  \%Apache::response::foilgroup);   \%Apache::response::foilgroup);
     my %name_letter_map;      my %name_letter_map;
     if (defined(%{ $Apache::response::itemgroup{'name_letter_map'} })) {      if (ref($Apache::response::itemgroup{'name_letter_map'}) eq 'HASH') {
  %name_letter_map=          if (%{$Apache::response::itemgroup{'name_letter_map'}}) {
     %{ $Apache::response::itemgroup{'name_letter_map'} };      %name_letter_map=
           %{ $Apache::response::itemgroup{'name_letter_map'} };
           }
     }      }
     my $result;      my $result;
     if ($Apache::lonhomework::type eq 'exam') {      if ($Apache::lonhomework::type eq 'exam') {
Line 391  sub grade_response { Line 439  sub grade_response {
     my %answerhash;      my %answerhash;
     my ($temp,$right,$wrong,$ignored)=(1,0,0,0);      my ($temp,$right,$wrong,$ignored)=(1,0,0,0);
     my %letter_name_map;      my %letter_name_map;
     if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) {      if (ref($Apache::response::itemgroup{'letter_name_map'}) eq 'HASH') {
  %letter_name_map=          if (%{$Apache::response::itemgroup{'letter_name_map'}}) {
     %{ $Apache::response::itemgroup{'letter_name_map'} };      %letter_name_map=
           %{ $Apache::response::itemgroup{'letter_name_map'} };
           }
     }      }
     my @items;      my @items;
     my $numitems = scalar(@{ $Apache::response::itemgroup{'names'} });      my $numitems = scalar(@{ $Apache::response::itemgroup{'names'} });
Line 450  sub grade_response { Line 500  sub grade_response {
  }   }
     }      }
     my $part=$Apache::inputtags::part;      my $part=$Apache::inputtags::part;
     my $nonlenient=&Apache::optionresponse::is_nonlenient($part);      my $nonlenient=&Apache::optionresponse::grading_is_nonlenient($part);
     my $id = $Apache::inputtags::response['-1'];      my $id = $Apache::inputtags::response['-1'];
     my $responsestr=&Apache::lonnet::hash2str(%responsehash);      my $responsestr=&Apache::lonnet::hash2str(%responsehash);
     my $itemstr    =&Apache::lonnet::array2str(@items);      my $itemstr    =&Apache::lonnet::array2str(@items);
Line 564  sub displayfoils { Line 614  sub displayfoils {
     my $part=$Apache::inputtags::part;      my $part=$Apache::inputtags::part;
     my $solved=$Apache::lonhomework::history{"resource.$part.solved"};      my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
     my %letter_name_map;      my %letter_name_map;
     if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) {      if (ref($Apache::response::itemgroup{'letter_name_map'}) eq 'HASH') {
  %letter_name_map=          if (%{$Apache::response::itemgroup{'letter_name_map'}}) {
     %{ $Apache::response::itemgroup{'letter_name_map'} };      %letter_name_map=
           %{ $Apache::response::itemgroup{'letter_name_map'} };
           }
     }      }
     my %name_letter_map;      my %name_letter_map;
     if (defined(%{ $Apache::response::itemgroup{'name_letter_map'} })) {      if (ref($Apache::response::itemgroup{'name_letter_map'}) eq 'HASH') {
  %name_letter_map=          if (%{$Apache::response::itemgroup{'name_letter_map'}}) {
     %{ $Apache::response::itemgroup{'name_letter_map'} };      %name_letter_map=
           %{ $Apache::response::itemgroup{'name_letter_map'} };
           }
     }      }
     if ( &Apache::response::show_answer() && ($target ne 'tex')) {      if ( &Apache::response::show_answer() && ($target ne 'tex')) {
  foreach my $name (@whichfoils) {   foreach my $name (@whichfoils) {
Line 835  sub start_foil { Line 889  sub start_foil {
  if ($$tagstack[-2] eq 'conceptgroup') { $level = '-3'; }   if ($$tagstack[-2] eq 'conceptgroup') { $level = '-3'; }
  $result.=&Apache::edit::text_arg('Name:','name',$token);   $result.=&Apache::edit::text_arg('Name:','name',$token);
  my @names;   my @names;
  if (defined(@{ $Apache::response::itemgroup{'names'} })) {   if (ref($Apache::response::itemgroup{'names'}) eq 'ARRAY') {
     @names=@{ $Apache::response::itemgroup{'names'} };              if (@{ $Apache::response::itemgroup{'names'} }) {
           @names=@{ $Apache::response::itemgroup{'names'} };
               }
  }   }
  $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',['unused',@names],$token,'15');   $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',['unused',@names],$token,'15');
  my $randomize=&Apache::lonxml::get_param('randomize',$parstack,   my $randomize=&Apache::lonxml::get_param('randomize',$parstack,

Removed from v.1.83  
changed lines
  Added in v.1.88


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>