[LON-CAPA-cvs] cvs: loncom /homework bridgetask.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 16 May 2006 06:43:42 -0000


This is a MIME encoded message

--albertel1147761822
Content-Type: text/plain

albertel		Tue May 16 02:43:42 2006 EDT

  Modified files:              
    /loncom/homework	bridgetask.pm 
  Log:
  - <Question> is a synonym for <Dimension>
  - OptionalRequired is allowed on <Question>s (but if it exists on <Instance> it overrides the <Dimension> definition)
  - <Criteria> is allowed inside of <Question> and is then used on all <Instance>s
  
  
  
--albertel1147761822
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20060516024342.txt"

Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.150 loncom/homework/bridgetask.pm:1.151
--- loncom/homework/bridgetask.pm:1.150	Fri May 12 02:55:46 2006
+++ loncom/homework/bridgetask.pm	Tue May 16 02:43:42 2006
@@ -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 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 @@
 			    $man_count++;
 			}
 		    }
+		    
 		    my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
 							 $parstack,$safeeval);
 		    if ($opt_req !~ /\S/) { $opt_req='0'; }
@@ -1709,6 +1710,7 @@
 }
 
 my %dimension;
+sub start_Question { return &start_Dimension(@_); }
 sub start_Dimension {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     undef(%dimension);
@@ -1764,15 +1766,19 @@
 {
     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 @@
 		    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 @@
 			}
 		    }
 		    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<p>".&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)."</p>\n</div>";
 
 		    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 @@
 			}
 			my $status_display=$status;
 			$status_display=~s/^([a-z])/uc($1)/e;
-			@Apache::scripttag::parser_env = @_;
 			$result.=
 			    '<div class="LC_'.$status.' LC_criteria"><h4>'
 			    .$mandatory.' Criteria</h4><p>';
 			@Apache::scripttag::parser_env = @_;
-			$result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
+			$result.=&Apache::scripttag::xmlparse($dimension{'criteria.'.$id});
 			$result.='</p><p class="LC_grade">'.$status_display.'</p>';
-			if ($Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.comment"}) {
-			    $result.='<p class="LC_comment">'.&mt('Comment: [_1]',$Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.comment"}).'</p>';
+			if ($Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}) {
+			    $result.='<p class="LC_comment">'.&mt('Comment: [_1]',$Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}).'</p>';
 			}
 			$result.='</div>';
 		    }
@@ -1860,15 +1873,16 @@
 	    &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.='<div class="LC_GRADING_criteria" id="'.$link.'">'."\n".
 		    '<div class="LC_GRADING_criteriatext" id="next_'.$last_link.'">'."\n";
 		@Apache::scripttag::parser_env = @_;
-		$result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
+		$result.=&Apache::scripttag::xmlparse($dimension{'criteria.'.$id});
 		$result.='</div>'."\n".
-		    #$dimension{$instance.'.criteria.'.$id}.
+		    #$dimension{'criteria.'.$id}.
 		    '<div class="LC_GRADING_grade">'."\n".
 		    '<label class="LC_GRADING_ungraded"><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label>'."\n".
 		    '<label class="LC_GRADING_fail"><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label>'."\n".
@@ -1876,14 +1890,14 @@
 		    '<label class="LC_GRADING_review"><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label>'."\n".
 		    '</div>'."\n".
 		    '<label class="LC_GRADING_comment">'.&mt('Additional Comment for Student')."\n".
-		    '<textarea class="LC_GRADING_comment_area" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode($Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.comment"}).'</textarea>'."\n".
+		    '<textarea class="LC_GRADING_comment_area" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode($Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}).'</textarea>'."\n".
 		    '</label>'."\n".
 		    '<ul class="LC_GRADING_navbuttons">'."\n".
 		    '<li><a href="#'.$last_link.'">Prev</a></li>'."\n".
 		    '<li><a href="#next_'.$link.'">Next</a></li>'."\n".
 		    '</ul>'."\n".
                     '</div>'."\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 @@
 	    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 @@
 		    $ungraded++;
 		}
 	    }
-	    if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
+	    # FIXME optional required can apply to only <instance> 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 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 @@
     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 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 '';
 }

--albertel1147761822--