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

www lon-capa-cvs@mail.lon-capa.org
Thu, 02 Jun 2005 19:17:17 -0000


www		Thu Jun  2 15:17:17 2005 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  Removed globals except caches
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.200 loncom/interface/lonparmset.pm:1.201
--- loncom/interface/lonparmset.pm:1.200	Thu Jun  2 12:35:32 2005
+++ loncom/interface/lonparmset.pm	Thu Jun  2 15:17:12 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.200 2005/06/02 16:35:32 www Exp $
+# $Id: lonparmset.pm,v 1.201 2005/06/02 19:17:12 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -68,20 +68,11 @@
 
 my $parmhashid;
 my %parmhash;
+my $symbsid;
+my %symbs;
 
 # --- end local caches
 
-#
-# FIXME: get rid of items below
-#
-my @ids;
-my %symbp;
-my %mapp;
-my %typep;
-my %keyp;
-my %uris;
-my %maptitles;
-
 ##################################################
 ##################################################
 
@@ -112,9 +103,13 @@
 =cut
 
 ##################################################
-##################################################
 sub parmval {
     my ($what,$id,$def,$uname,$udom,$csec)=@_;
+    return &parmval_by_symb($what,&symbcache($id),$def,$uname,$udom,$csec);
+}
+
+sub parmval_by_symb {
+    my ($what,$symb,$def,$uname,$udom,$csec)=@_;
 # load caches
 
     &cacheparmhash();
@@ -128,9 +123,10 @@
     my $result='';
     my @outpar=();
 # ----------------------------------------------------- Cascading lookup scheme
+    my $map=(&Apache::lonnet::decode_symb($symb))[0];    
 
-    my $symbparm=$symbp{$id}.'.'.$what;
-    my $mapparm=$mapp{$id}.'___(all).'.$what;
+    my $symbparm=$symb.'.'.$what;
+    my $mapparm=$map.'___(all).'.$what;
 
     my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$what;
     my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
@@ -180,8 +176,7 @@
 	}
 
         if (defined($$courseopt{$seclevelr})) {
-	    $outpar[4]=$$courseopt
-{$seclevelr};
+	    $outpar[4]=$$courseopt{$seclevelr};
 	    $result=4;
 	}
     }
@@ -222,6 +217,25 @@
     }
 }
 
+sub symbcache {
+    my $id=shift;
+    if ($symbsid ne $env{'request.course.id'}) {
+	%symbs=();
+    }
+    unless ($symbs{$id}) {
+	my $navmap = Apache::lonnavmaps::navmap->new();
+	if ($id=~/\./) {
+	    my $resource=$navmap->getById($id);
+	    $symbs{$id}=$resource->symb();
+	} else {
+	    my $resource=$navmap->getByMapPc($id);
+	    $symbs{$id}=&Apache::lonnet::declutter($resource->src());
+	}
+	$symbsid=$env{'request.course.id'};
+    }
+    return $symbs{$id};
+}
+
 ##################################################
 ##################################################
 #
@@ -238,14 +252,7 @@
 
 sub storeparm {
     my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;
-    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);
-    }
+    &storeparm_by_symb(&symbcache($sresid),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec);
 }
 
 #
@@ -574,7 +581,7 @@
 }
 
 sub print_row {
-    my ($r,$which,$part,$name,$rid,$default,$defaulttype,$display,$defbgone,
+    my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone,
 	$defbgtwo,$parmlev,$uname,$udom,$csec)=@_;
 # get the values for the parameter in cascading order
 # empty levels will remain empty
@@ -666,7 +673,7 @@
 
     if ($parmlev eq 'full' || $parmlev eq 'brief') {
         my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
-                                        '.'.$$name{$which},$symbp{$rid});
+                                        '.'.$$name{$which},$$symbp{$rid});
 
 # this doesn't seem to work, and I don't think is correct
 #    my $sessionvaltype=&Apache::lonnet::EXT('resource.'.$$part{$which}.
@@ -696,6 +703,7 @@
     $r->print('</td>'."\n");
 }
 
+
 =pod
 
 =item B<extractResourceInformation>: Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes.
@@ -835,6 +843,15 @@
 sub assessparms {
 
     my $r=shift;
+
+    my @ids=();
+    my %symbp=();
+    my %mapp=();
+    my %typep=();
+    my %keyp=();
+    my %uris=();
+    my %maptitles=();
+
 # -------------------------------------------------------- Variable declaration
     my %allkeys=();
     my %allmaps=();
@@ -1310,7 +1327,7 @@
                                 undef $firstrow;
                             }
 
-                            &print_row($r,$_,\%part,\%name,$rid,\%default,
+                            &print_row($r,$_,\%part,\%name,\%symbp,$rid,\%default,
                                        \%type,\%display,$defbgone,$defbgtwo,
                                        $parmlev,$uname,$udom,$csec);
                         }
@@ -1418,7 +1435,7 @@
 
 	        foreach (sort keys %name) {
                     $r->print('<tr>');
-                    &print_row($r,$_,\%part,\%name,$mapid,\%default,
+                    &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
                            \%type,\%display,$defbgone,$defbgtwo,
                            $parmlev,$uname,$udom,$csec);
 #                    $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
@@ -1496,7 +1513,7 @@
 
 	    foreach (sort keys %name) {
                 $r->print('<tr>');
-                &print_row($r,$_,\%part,\%name,$mapid,\%default,
+                &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
                        \%type,\%display,$defbgone,$defbgtwo,$parmlev,$uname,$udom,$csec);
 #                    $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
             }
@@ -2184,16 +2201,6 @@
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 					    ['action','state']);
 
-# ----------------------------------------------------------- Clear out garbage
-
-
-    @ids=();
-    %symbp=();
-    %mapp=();
-    %typep=();
-    %keyp=();
-
-    %maptitles=();
 
     &Apache::lonhtmlcommon::clear_breadcrumbs();
     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",