File:  [LON-CAPA] / loncom / homework / hint.pm
Revision 1.9: download - view: text, annotated - select for diffs
Sat Mar 31 00:35:17 2001 UTC (23 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- <hintpart> works properly when default hint is to be shown

    1: package Apache::hinttags; 
    2: 
    3: use strict;
    4: use Apache::lonnet;
    5: use capa;
    6: 
    7: sub BEGIN {
    8:   &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint'));
    9: }
   10: 
   11: 
   12: @Apache::hint::which=();
   13: sub start_hintgroup {
   14:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   15:   my $skiptoend='0';
   16:   my $result;
   17:   
   18:   if ($target eq 'web' || $target eq 'grade') {
   19:     my $id=$Apache::inputtags::part;
   20:     my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
   21:     if ( $numtries eq '') { $numtries = 0; }
   22:     my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
   23:     if ( $hinttries eq '') { $hinttries = 1; }
   24:     &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
   25:     if ( $numtries <= $hinttries ) {
   26:       $skiptoend='1'; 
   27:     } else {
   28:       if ($target eq 'web') {$result='<table bgcolor="#dddddd"><tr><td>';}
   29:     }
   30:   }
   31:   if ($skiptoend) {
   32:     &Apache::lonxml::get_all_text("/hintgroup",$$parser[$#$parser]);
   33:   }
   34:   @Apache::hint::which=();
   35:   return $result;
   36: }
   37: 
   38: sub end_hintgroup {
   39:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   40:   my $result;
   41: 
   42:   if ($target ne 'meta' || $target ne 'grade') {
   43:     my $id=$Apache::inputtags::part;
   44:     my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
   45:     if ( $numtries eq '') { $numtries = 0; }
   46:     my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
   47:     if ( $hinttries eq '') { $hinttries = 1; }
   48:     &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
   49:     if ( $numtries >= $hinttries ) {
   50:       if ($target eq 'web') {$result='</td></tr></table>';}
   51:     }	
   52:   }
   53:   @Apache::hint::which='';
   54:   return $result;
   55: }
   56: 
   57: sub start_numericalhint {
   58:   #do everything in end, so intervening <responseparams> work
   59: }
   60: 
   61: sub end_numericalhint {
   62:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   63:   my $result;
   64:   if ($target ne 'meta' && $target ne 'grade') {
   65:     my $args ='';
   66:     $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
   67:     if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
   68:     my $name = &Apache::run::run("{$args;".'return $name}',$safeeval);
   69:     my $response = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.$Apache::inputtags::response['-1'].submission"};
   70:     &Apache::lonxml::debug("hintgroup is using $response<br />\n");
   71:     my $expression="&caparesponse_check_list('".$response."','".
   72:       $$parstack[$#$parstack].
   73: 	';my $tol="'.$Apache::inputtags::params{'tol'}.'"'.
   74: 	';my $sig="'.$Apache::inputtags::params{'sig'}.'"'.
   75: 	  "');";
   76:     $result = &Apache::run::run($expression,$safeeval);
   77:     &Apache::lonxml::debug("$expression:result:$result:$Apache::lonxml::curdepth");
   78:     my ($awards) = split /:/ , $result;
   79:     my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
   80:     if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') { push (@Apache::hint::which,$name); }
   81:     $result='';
   82:   }
   83:   return $result;
   84: }
   85: 
   86: # a part shows if it is on, if no specific parts are on, then default shows
   87: sub start_hintpart {
   88:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   89: 
   90:   my $show ='0';
   91: 
   92:   if ($target eq 'web') {
   93:     my $args ='';
   94:     if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
   95:     my $on = &Apache::run::run("{$args;".'return $on}',$safeeval);
   96:     &Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
   97:     if ( $on eq 'default' && $#Apache::hint::which == '-1') {
   98:       $show=1;
   99:     } else {
  100:       my $which;
  101:       foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
  102:     }
  103:     if (!$show) {
  104:       &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
  105:     }
  106:   } elsif ($target eq 'grade') {
  107:     &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
  108:   }
  109:   return '';
  110: }
  111: 
  112: sub end_hintpart {
  113: }
  114: 
  115: 1;
  116: __END__

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