[LON-CAPA-cvs] cvs: loncom(version_2_10_X) /homework structuretags.pm

raeburn raeburn@source.lon-capa.org
Mon, 16 Aug 2010 18:09:28 -0000


raeburn		Mon Aug 16 18:09:28 2010 EDT

  Modified files:              (Branch: version_2_10_X)
    /loncom/homework	structuretags.pm 
  Log:
  - Backport 1.470, 1.471, 1.472.
  
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.465.2.2 loncom/homework/structuretags.pm:1.465.2.3
--- loncom/homework/structuretags.pm:1.465.2.2	Mon Aug 16 17:51:02 2010
+++ loncom/homework/structuretags.pm	Mon Aug 16 18:09:28 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.465.2.2 2010/08/16 17:51:02 raeburn Exp $
+# $Id: structuretags.pm,v 1.465.2.3 2010/08/16 18:09:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -633,9 +633,7 @@
 	    $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results,
 					    $symb,$courseid,$domain,$name);
 	    &Apache::lonxml::debug('Store return message:'.$result);
-            if ($env{'request.role'} =~/^st/) {
-                &store_aggregates($symb,$courseid);
-            }
+            &store_aggregates($symb,$courseid);
 	}
     } else {
 	&Apache::lonxml::debug('Nothing to store');
@@ -655,7 +653,7 @@
 
 sub store_aggregates {
     my ($symb,$courseid) = @_;
-    my %aggregate;
+    my (%aggregate,%anoncounter);
     my @parts;
     my $cdomain = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
@@ -665,28 +663,51 @@
         }
     }
     foreach my $part (@parts) {
-        if ($Apache::lonhomework::results{'resource.'.$part.'.award'}
-	    eq 'APPROX_ANS' ||
-	    $Apache::lonhomework::results{'resource.'.$part.'.award'}
-	    eq 'EXACT_ANS') {
-            $aggregate{$symb."\0".$part."\0correct"} = 1;
+        if ($env{'request.role'} =~/^st/) {
+            if ($Apache::lonhomework::results{'resource.'.$part.'.award'}
+                eq 'APPROX_ANS' ||
+                $Apache::lonhomework::results{'resource.'.$part.'.award'}
+                eq 'EXACT_ANS') {
+                $aggregate{$symb."\0".$part."\0correct"} = 1;
+            }
+            if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) {
+                $aggregate{$symb."\0".$part."\0users"} = 1;
+            } else {
+                my (undef,$last_reset) = &Apache::grades::get_last_resets($symb,$env{'request.course.id'},[$part]);
+                if ($last_reset) {
+                    if (&Apache::grades::get_num_tries(\%Apache::lonhomework::history,$last_reset,$part) == 0) {
+                        $aggregate{$symb."\0".$part."\0users"} = 1;
+                    }
+                }
+            }
+            $aggregate{$symb."\0".$part."\0attempts"} = 1;
         }
-        if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) {
-            $aggregate{$symb."\0".$part."\0users"} = 1;
-        } else {
-            my (undef,$last_reset) = &Apache::grades::get_last_resets($symb,$env{'request.course.id'},[$part]); 
-            if ($last_reset) {
-                if (&Apache::grades::get_num_tries(\%Apache::lonhomework::history,$last_reset,$part) == 0) {
-                    $aggregate{$symb."\0".$part."\0users"} = 1;
+        if (($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'anonsurvey') ||
+            ($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'anonsurveycred')) {
+            $anoncounter{$symb."\0".$part} = 1;
+            my $needsrelease = $Apache::lonnet::needsrelease{'parameter:type:'.$Apache::lonhomework::results{'resource.'.$part.'.type'}};
+            if ($needsrelease) {
+                my $curr_required = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
+                if ($curr_required eq '') {
+                    &Apache::lonnet::update_released_required($needsrelease);
+                } else {
+                    my ($currmajor,$currminor) = split(/\./,$curr_required);
+                    my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
+                    if (($currmajor < $needsmajor) || ($currmajor == $needsmajor && $currminor < $needsminor)) {
+                        &Apache::lonnet::update_released_required($needsrelease);
+                    }
                 }
             }
         }
-        $aggregate{$symb."\0".$part."\0attempts"} = 1;
     }
     if (keys (%aggregate) > 0) {
 	&Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
                             $cdomain,$cname);
     }
+    if (keys(%anoncounter) > 0) {
+        &Apache::lonnet::cinc('nohist_anonsurveys',\%anoncounter,
+                            $cdomain,$cname);
+    }
 }
 
 sub checkout_msg {