--- loncom/homework/hint.pm 2002/01/11 16:32:29 1.22 +++ loncom/homework/hint.pm 2008/11/19 18:34:56 1.73 @@ -1,13 +1,13 @@ # The LearningOnline Network with CAPA # implements the tags that control the hints # -# $Id: hint.pm,v 1.22 2002/01/11 16:32:29 matthew Exp $ +# $Id: hint.pm,v 1.73 2008/11/19 18:34:56 jms Exp $ # # Copyright Michigan State University Board of Trustees # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). # -# LON-CAPA is free software; you can redistribute it and/or modify +# LON-CAPA me&aree software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. @@ -26,169 +26,681 @@ # http://www.lon-capa.org/ # +=head1 NAME + +Apache::hinttags + +=head1 SYNOPSIS + +This handler coordinates the delivery of hints to students working on LON-CAPA problems and assignments. + +This is part of the LearningOnline Network with CAPA project +described at http://www.lon-capa.org. + +=head1 SUBROUTINES + +=over + +=item start_hintgroup() + +=item end_hintgroup() + +=item start_numericalhint() + +=item end_numericalhint() + +=item start_formulahint() + +=item end_formulahint() + +=item start_mathhint() + +=item end_mathhint() + +=item start_customhint() + +=item end_customhint() + +=item start_stringhint() + +=item end_stringhint() + +=item start_hintpart() + +=item end_hintpart() + +=item start_optionhint() + +=item end_optionhint() + +=item start_radiobuttonhint() + +=item end_radiobuttonhint() + +=back + +=cut + package Apache::hinttags; use strict; -use Apache::lonnet; +use Apache::lonnet(); use capa; +use Apache::caparesponse(); +use Apache::lonmaxima(); +use Apache::response(); +use Apache::lonlocal; +use Storable qw(dclone); -sub BEGIN { - &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint')); +BEGIN { + &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint','stringhint','formulahint','optionhint','radiobuttonhint','mathhint','customhint')); } @Apache::hint::which=(); sub start_hintgroup { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; - my $skiptoend='0'; - my $result; - - if ($target eq 'web') { - my $id=$Apache::inputtags::part; - my $numtries=$Apache::lonhomework::history{"resource.$id.tries"}; - if ( $numtries eq '') { $numtries = 0; } - my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries"); - if ( $hinttries eq '') { $hinttries = 1; } - &Apache::lonxml::debug("found :$id:$numtries:$hinttries:"); - if ( $numtries < $hinttries ) { - $skiptoend='1'; - } else { - if ($target eq 'web') {$result='
';} - } - if ($skiptoend) { - &Apache::lonxml::get_all_text("/hintgroup",$$parser[$#$parser]); - } - } - @Apache::hint::which=(); - return $result; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + my $skiptoend='0'; + my $result; + + if ($target eq 'web') { + my $id=$Apache::inputtags::part; + my $numtries=$Apache::lonhomework::history{"resource.$id.tries"}; + if ( $numtries eq '') { $numtries = 0; } + my $hinttries=&Apache::response::get_response_param($id,"hinttries",1); + &Apache::lonxml::debug("found :$id:$numtries:$hinttries:"); + my $gradestatus= + $Apache::lonhomework::history{"resource.$id.solved"}; + my $showoncorrect=lc(&Apache::lonxml::get_param('showoncorrect',$parstack,$safeeval)); + &Apache::lonxml::debug("onc orrect $showoncorrect, $gradestatus"); + if ( ($showoncorrect ne 'yes' && &Apache::response::show_answer()) || + ( $numtries < $hinttries) ) { + &Apache::lonxml::debug("Grabbin all"); + &Apache::lonxml::get_all_text("/hintgroup",$parser,$style); + } + &Apache::lonxml::startredirection; + } elsif ($target eq 'tex') { + $result .= '\keephidden{'; + } elsif ($target eq 'edit') { + $result.=&Apache::edit::tag_start($target,$token); + $result.=&Apache::edit::select_arg('Show hint even if problem Correct:','showoncorrect',['no','yes'],$token); + $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); + } elsif ($target eq 'modified') { + my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'showoncorrect'); + if ($constructtag) { + $result =&Apache::edit::rebuild_tag($token); + } + } + @Apache::hint::which=(); + return $result; } sub end_hintgroup { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; - my $result; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + my $result; - if ($target eq 'web') { - my $id=$Apache::inputtags::part; - my $numtries=$Apache::lonhomework::history{"resource.$id.tries"}; - if ( $numtries eq '') { $numtries = 0; } - my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries"); - if ( $hinttries eq '') { $hinttries = 1; } - &Apache::lonxml::debug("found :$id:$numtries:$hinttries:"); - if ( $numtries >= $hinttries ) { - $result=' |
'. + $hinttext.' |