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

raeburn raeburn@source.lon-capa.org
Thu, 29 Jul 2010 18:00:06 -0000


raeburn		Thu Jul 29 18:00:06 2010 EDT

  Modified files:              
    /loncom/homework	structuretags.pm 
  Log:
  - Additional items in course's resourcetracker.db (key is $symb."\0".$part."\0anonymous"}.
    - Tracks how many anonymous survey submissions have been made for a problem part in a course (not resettable).
    - Will affect LON-CAPA release required for role in a course, if releaserequired is currently unset or 2.9 or earlier.  
  
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.469 loncom/homework/structuretags.pm:1.470
--- loncom/homework/structuretags.pm:1.469	Sat Jun  5 19:36:57 2010
+++ loncom/homework/structuretags.pm	Thu Jul 29 18:00:06 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.469 2010/06/05 19:36:57 www Exp $
+# $Id: structuretags.pm,v 1.470 2010/07/29 18:00:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -629,9 +629,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');
@@ -661,23 +659,42 @@
         }
     }
     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')) {
+            $aggregate{$symb."\0".$part."\0anonymous"} = 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 '') {
+                    &update_courseenv($needsrelease,$cdomain,$cname);
+                } else {
+                    my ($currmajor,$currminor) = split(/\./,$curr_required);
+                    my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
+                    if (($currmajor < $needsmajor) || ($currmajor == $needsmajor && $currminor < $needsminor)) {
+                        &update_courseenv($needsrelease,$cdomain,$cname);
+                    }
                 }
             }
         }
-        $aggregate{$symb."\0".$part."\0attempts"} = 1;
     }
     if (keys (%aggregate) > 0) {
 	&Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
@@ -685,6 +702,24 @@
     }
 }
 
+sub update_courseenv {
+    my ($needsrelease,$cdom,$cnum) = @_;
+    my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
+    my %needshash = (
+                      'internal.releaserequired' => $needsrelease,
+                    );
+    my $putresult = &put('environment',\%needshash,$cdom,$cnum);
+    if ($putresult eq 'ok') {
+        &appenv({'course.'.$env{'request.course.id'}.'.internal.releaserequired' => $needsrelease});
+        my %crsinfo =
+            &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
+        if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
+            $crsinfo{$env{'request.course.id'}}{'releaserequired'} = $needsrelease;
+        }
+        &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
+    }
+}
+
 sub checkout_msg {
     my %lt=&Apache::lonlocal::texthash( 
 		'resource'=>'The resource needs to be checked out',