[LON-CAPA-cvs] cvs: loncom /interface lonparmset.pm

www lon-capa-cvs@mail.lon-capa.org
Wed, 01 Jun 2005 21:44:03 -0000


www		Wed Jun  1 17:44:03 2005 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  Making store_parameter routine self-sufficient (hopefully)
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.196 loncom/interface/lonparmset.pm:1.197
--- loncom/interface/lonparmset.pm:1.196	Tue May 31 22:02:41 2005
+++ loncom/interface/lonparmset.pm	Wed Jun  1 17:44:00 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.196 2005/06/01 02:02:41 www Exp $
+# $Id: lonparmset.pm,v 1.197 2005/06/01 21:44:00 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -62,6 +62,7 @@
 use Apache::lonhomework;
 use Apache::lonxml;
 use Apache::lonlocal;
+use Apache::lonnavmaps;
 
 my %courseopt;
 my %useropt;
@@ -193,7 +194,7 @@
 ##################################################
 ##################################################
 #
-# Store a parameter
+# Store a parameter by ID
 #
 # Takes
 # - resource id
@@ -206,12 +207,37 @@
 
 sub storeparm {
     my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;
-    $spnam=~s/\_([^\_]+)$/\.$1/;
+    my $navmap = Apache::lonnavmaps::navmap->new();
+    if ($sresid=~/\./) {
+	my $resource=$navmap->getById($sresid);
+	&storeparm_by_symb($resource->symb(),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec);
+    } else {
+        my $resource=$navmap->getByMapPc($sresid);
+	&storeparm_by_symb(&Apache::lonnet::declutter($resource->src()),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec);
+    }
+}
+
+#
+# Store a parameter by symb
+#
+# Takes
+# - symb
+# - name of parameter
+# - level
+# - new value
+# - new type
+# - username
+# - userdomain
+
+sub storeparm_by_symb {
+# ---------------------------------------------------------- Get symb, map, etc
+    my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;
 # ---------------------------------------------------------- Construct prefixes
-    
-    my $symbparm=$symbp{$sresid}.'.'.$spnam;
-    my $mapparm=$mapp{$sresid}.'___(all).'.$spnam;
-    
+    $spnam=~s/\_([^\_]+)$/\.$1/;
+    my $map=(&Apache::lonnet::decode_symb($symb))[0];    
+    my $symbparm=$symb.'.'.$spnam;
+    my $mapparm=$map.'___(all).'.$spnam;
+
     my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$spnam;
     my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
     my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
@@ -239,9 +265,9 @@
 # Expire sheets
 	&Apache::lonnet::expirespread('','','studentcalc');
 	if (($snum==7) || ($snum==4)) {
-	    &Apache::lonnet::expirespread('','','assesscalc',$symbp{$sresid});
+	    &Apache::lonnet::expirespread('','','assesscalc',$symb);
 	} elsif (($snum==8) || ($snum==5)) {
-	    &Apache::lonnet::expirespread('','','assesscalc',$mapp{$sresid});
+	    &Apache::lonnet::expirespread('','','assesscalc',$map);
 	} else {
 	    &Apache::lonnet::expirespread('','','assesscalc');
 	}
@@ -264,10 +290,10 @@
 	&Apache::lonnet::expirespread($uname,$udom,'studentcalc');
 	if ($snum==1) {
 	    &Apache::lonnet::expirespread
-		($uname,$udom,'assesscalc',$symbp{$sresid});
+		($uname,$udom,'assesscalc',$symb);
 	} elsif ($snum==2) {
 	    &Apache::lonnet::expirespread
-		($uname,$udom,'assesscalc',$mapp{$sresid});
+		($uname,$udom,'assesscalc',$map);
 	} else {
 	    &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
 	}