--- loncom/homework/bridgetask.pm 2006/05/12 06:55:46 1.150 +++ loncom/homework/bridgetask.pm 2006/05/16 06:43:42 1.151 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: bridgetask.pm,v 1.150 2006/05/12 06:55:46 albertel Exp $ +# $Id: bridgetask.pm,v 1.151 2006/05/16 06:43:42 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,7 +40,7 @@ use Apache::slotrequest(); use Time::HiRes qw( gettimeofday tv_interval ); BEGIN { - &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Instance','InstanceText','Criteria','ClosingParagraph')); + &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','Instance','InstanceText','Criteria','ClosingParagraph')); } sub initialize_bridgetask { @@ -878,6 +878,7 @@ DONEBUTTON $man_count++; } } + my $opt_req=&Apache::lonxml::get_param('OptionalRequired', $parstack,$safeeval); if ($opt_req !~ /\S/) { $opt_req='0'; } @@ -1709,6 +1710,7 @@ sub get_id { } my %dimension; +sub start_Question { return &start_Dimension(@_); } sub start_Dimension { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; undef(%dimension); @@ -1764,15 +1766,19 @@ sub get_instance { { my $last_link; sub link { - my ($instance,$id) = @_; - return 'LC_GRADING_criteria_'.$instance.'_'.$id; + my ($id) = @_; + $id =~ s/\./_/g; + return 'LC_GRADING_criteria_'.$id; } + sub end_Question { return &end_Dimension(@_); } sub end_Dimension { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result=&Apache::lonxml::endredirection(); my $dim=&get_id($parstack,$safeeval); my $instance=&get_instance($dim); my $version=&get_version(); + use Data::Dumper; + &Apache::lonxml::debug(Dumper(\%dimension)); if ($target eq 'web') { @Apache::scripttag::parser_env = @_; $result.=&Apache::scripttag::xmlparse($dimension{'intro'}); @@ -1802,11 +1808,12 @@ sub get_instance { my $man_passed=0; my $opt_count=0; my $opt_passed=0; - foreach my $id (@{$dimension{$instance.'.criterias'}}) { - if ($dimension{$instance.'.criteria.'.$id.'.mandatory'} + foreach my $id ( @{$dimension{$instance.'.criterias'}}, + @{$dimension{'criterias'}} ) { + if ($dimension{'criteria.'.$id.'.mandatory'} eq 'N') { $opt_count++; - if ($Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.status"} eq 'pass') { + if ($Apache::lonhomework::history{"resource.$version.0.$dim.$id.status"} eq 'pass') { $opt_passed++; } } else { @@ -1817,17 +1824,24 @@ sub get_instance { } } if ($man_passed eq $man_count) { $man_passed='all'; } + my $opt_req=$dimension{$instance.'.optionalrequired'}; - if ($opt_req !~ /\S/) { $opt_req='0'; } + if ($opt_req !~ /\S/) { + $opt_req= + &Apache::lonxml::get_param('OptionalRequired', + $parstack,$safeeval); + if ($opt_req !~ /\S/) { $opt_req = 0; } + } $dim_info.="\n

".&mt('You passed [_1] of the [_2] mandatory components and [_3] of the [_4] optional components, of which you were required to pass [_5].',$man_passed,$man_count,$opt_passed,$opt_count,$opt_req)."

\n"; my $internal_location=&internal_location($dim); $result=~s/\Q$internal_location\E/$dim_info/; - foreach my $id (@{$dimension{$instance.'.criterias'}}) { - my $status=$Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.status"}; - my $comment=$Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.comment"}; - my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N'); + foreach my $id (@{$dimension{$instance.'.criterias'}}, + @{$dimension{'criterias'}}) { + my $status=$Apache::lonhomework::history{"resource.$version.0.$dim.$id.status"}; + my $comment=$Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}; + my $mandatory=($dimension{'criteria.'.$id.'.mandatory'} ne 'N'); if ($mandatory) { $mandatory='Mandatory'; } else { @@ -1840,15 +1854,14 @@ sub get_instance { } my $status_display=$status; $status_display=~s/^([a-z])/uc($1)/e; - @Apache::scripttag::parser_env = @_; $result.= '

' .$mandatory.' Criteria

'; @Apache::scripttag::parser_env = @_; - $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id}); + $result.=&Apache::scripttag::xmlparse($dimension{'criteria.'.$id}); $result.='

'.$status_display.'

'; - if ($Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.comment"}) { - $result.='

'.&mt('Comment: [_1]',$Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.comment"}).'

'; + if ($Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}) { + $result.='

'.&mt('Comment: [_1]',$Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}).'

'; } $result.='
'; } @@ -1860,15 +1873,16 @@ sub get_instance { &Apache::scripttag::xmlparse($dimension{'intro'}); @Apache::scripttag::parser_env = @_; &Apache::scripttag::xmlparse($dimension{$instance.'.text'}); - foreach my $id (@{$dimension{$instance.'.criterias'}}) { - my $link=&link($instance,$id); - my $status=$Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.status"}; + foreach my $id (@{$dimension{$instance.'.criterias'}}, + @{$dimension{'criterias'}} ) { + my $link=&link($id); + my $status=$Apache::lonhomework::history{"resource.$version.0.$dim.$id.status"}; $result.='
'."\n". '
'."\n"; @Apache::scripttag::parser_env = @_; - $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id}); + $result.=&Apache::scripttag::xmlparse($dimension{'criteria.'.$id}); $result.='
'."\n". - #$dimension{$instance.'.criteria.'.$id}. + #$dimension{'criteria.'.$id}. '
'."\n". ''."\n". ''."\n". @@ -1876,14 +1890,14 @@ sub get_instance { ''."\n". '
'."\n". ''."\n". ''."\n". '
'."\n"; - $result.=&grading_history($version,$dim,$instance,$id); + $result.=&grading_history($version,$dim,$id); $last_link=$link; } } elsif ($target eq 'grade' && $env{'form.webgrade'}) { @@ -1891,11 +1905,12 @@ sub get_instance { my $mandatory_failed=0; my $ungraded=0; my $review=0; - foreach my $id (@{$dimension{$instance.'.criterias'}}) { - my $link=&link($instance,$id); - my $status=$Apache::lonhomework::results{"resource.$version.0.$dim.$instance.$id.status"}=$env{'form.HWVAL_'.$link}; - $Apache::lonhomework::results{"resource.$version.0.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_'.$link}; - my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N'); + foreach my $id (@{$dimension{$instance.'.criterias'}}, + @{$dimension{'criterias'}}) { + my $link=&link($id); + my $status=$Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link}; + $Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link}; + my $mandatory=($dimension{'criteria.'.$id.'.mandatory'} ne 'N'); if ($status eq 'pass') { if (!$mandatory) { $optional_passed++; } } elsif ($status eq 'fail') { @@ -1908,7 +1923,15 @@ sub get_instance { $ungraded++; } } - if ($optional_passed < $dimension{$instance.'.optionalrequired'}) { + # FIXME optional required can apply to only right now... + my $opt_req=$dimension{$instance.'.optionalrequired'}; + if ($opt_req !~ /\S/) { + $opt_req= + &Apache::lonxml::get_param('OptionalRequired', + $parstack,$safeeval); + if ($opt_req !~ /\S/) { $opt_req = 0; } + } + if ($optional_passed < $opt_req) { $mandatory_failed++; } &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review"); @@ -1934,12 +1957,12 @@ sub get_instance { } sub grading_history { - my ($version,$dim,$instance,$criteria) = @_; + my ($version,$dim,$id) = @_; if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) { return ''; } my ($result,$grader); - my $scope="resource.$version.0.$dim.$instance.$criteria"; + my $scope="resource.$version.0.$dim.$id"; foreach my $t (1..$Apache::lonhomework::history{'version'}) { if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) { my ($gname,$gdom) = @@ -1969,10 +1992,11 @@ sub start_IntroParagraph { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result; if ($target eq 'web' || $target eq 'webgrade') { - if ($tagstack->[-2] eq 'Dimension') { - $dimension{'intro'}=&Apache::lonxml::get_all_text('/introparagraph',$parser,$style); - - } elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') { + if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) { + $dimension{'intro'}= + &Apache::lonxml::get_all_text('/introparagraph', + $parser,$style); + } elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') { &Apache::lonxml::startredirection(); } @@ -2021,14 +2045,21 @@ sub end_InstanceText { sub start_Criteria { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; - my $instance_id=$Apache::bridgetask::instance[-1]; my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style); if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') { my $id=&get_id($parstack,$safeeval); - $dimension{$instance_id.'.criteria.'.$id}=$criteria; - $dimension{$instance_id.'.criteria.'.$id.'.mandatory'}= - &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval); - push(@{$dimension{$instance_id.'.criterias'}},$id); + if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) { + my $instance_id=$Apache::bridgetask::instance[-1]; + $dimension{"criteria.$instance_id.$id"}=$criteria; + $dimension{"criteria.$instance_id.$id.mandatory"}= + &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval); + push(@{$dimension{$instance_id.'.criterias'}},"$instance_id.$id"); + } else { + $dimension{'criteria.'.$id}=$criteria; + $dimension{'criteria.'.$id.'.mandatory'}= + &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval); + push(@{$dimension{'criterias'}},$id); + } } return ''; }