--- loncom/interface/lonparmset.pm 2005/06/01 21:44:00 1.197 +++ loncom/interface/lonparmset.pm 2005/06/02 16:35:32 1.200 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.197 2005/06/01 21:44:00 www Exp $ +# $Id: lonparmset.pm,v 1.200 2005/06/02 16:35:32 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -64,10 +64,16 @@ use Apache::lonxml; use Apache::lonlocal; use Apache::lonnavmaps; -my %courseopt; -my %useropt; +# --- Caches local to lonparmset + +my $parmhashid; my %parmhash; +# --- end local caches + +# +# FIXME: get rid of items below +# my @ids; my %symbp; my %mapp; @@ -109,6 +115,16 @@ Returns: A list, the first item is the ################################################## sub parmval { my ($what,$id,$def,$uname,$udom,$csec)=@_; +# load caches + + &cacheparmhash(); + + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $useropt=&Apache::lonnet::get_userresdata($uname,$udom); + my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom); + + my $result=''; my @outpar=(); # ----------------------------------------------------- Cascading lookup scheme @@ -128,13 +144,13 @@ sub parmval { # --------------------------------------------------------- first, check course - if (defined($courseopt{$courselevel})) { - $outpar[11]=$courseopt{$courselevel}; + if (defined($$courseopt{$courselevel})) { + $outpar[11]=$$courseopt{$courselevel}; $result=11; } - if (defined($courseopt{$courselevelm})) { - $outpar[10]=$courseopt{$courselevelm}; + if (defined($$courseopt{$courselevelm})) { + $outpar[10]=$$courseopt{$courselevelm}; $result=10; } @@ -147,24 +163,25 @@ sub parmval { my $thisparm=$parmhash{$symbparm}; if (defined($thisparm)) { $outpar[8]=$thisparm; $result=8; } - if (defined($courseopt{$courselevelr})) { - $outpar[7]=$courseopt{$courselevelr}; + if (defined($$courseopt{$courselevelr})) { + $outpar[7]=$$courseopt{$courselevelr}; $result=7; } # ------------------------------------------------------ fourth, back to course if (defined($csec)) { - if (defined($courseopt{$seclevel})) { - $outpar[6]=$courseopt{$seclevel}; + if (defined($$courseopt{$seclevel})) { + $outpar[6]=$$courseopt{$seclevel}; $result=6; } - if (defined($courseopt{$seclevelm})) { - $outpar[5]=$courseopt{$seclevelm}; + if (defined($$courseopt{$seclevelm})) { + $outpar[5]=$$courseopt{$seclevelm}; $result=5; } - if (defined($courseopt{$seclevelr})) { - $outpar[4]=$courseopt{$seclevelr}; + if (defined($$courseopt{$seclevelr})) { + $outpar[4]=$$courseopt +{$seclevelr}; $result=4; } } @@ -172,24 +189,38 @@ sub parmval { # ---------------------------------------------------------- fifth, check user if (defined($uname)) { - if (defined($useropt{$courselevel})) { - $outpar[3]=$useropt{$courselevel}; + if (defined($$useropt{$courselevel})) { + $outpar[3]=$$useropt{$courselevel}; $result=3; } - if (defined($useropt{$courselevelm})) { - $outpar[2]=$useropt{$courselevelm}; + if (defined($$useropt{$courselevelm})) { + $outpar[2]=$$useropt{$courselevelm}; $result=2; } - if (defined($useropt{$courselevelr})) { - $outpar[1]=$useropt{$courselevelr}; + if (defined($$useropt{$courselevelr})) { + $outpar[1]=$$useropt{$courselevelr}; $result=1; } } return ($result,@outpar); } +sub resetparmhash { + $parmhashid=''; +} + +sub cacheparmhash { + if ($parmhashid eq $env{'request.course.fn'}) { return; } + my %parmhashfile; + if (tie(%parmhashfile,'GDBM_File', + $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) { + %parmhash=%parmhashfile; + untie %parmhashfile; + $parmhashid=$env{'request.course.fn'}; + } +} ################################################## ################################################## @@ -262,6 +293,8 @@ sub storeparm_by_symb { if ($snum>3) { # ---------------------------------------------------------------- Store Course # + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; # Expire sheets &Apache::lonnet::expirespread('','','studentcalc'); if (($snum==7) || ($snum==4)) { @@ -274,15 +307,12 @@ sub storeparm_by_symb { # Store parameter if ($delete) { $reply=&Apache::lonnet::del - ('resourcedata',[keys(%storecontent)], - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); + ('resourcedata',[keys(%storecontent)],$cdom,$cnum); } else { $reply=&Apache::lonnet::cput - ('resourcedata',\%storecontent, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); + ('resourcedata',\%storecontent,$cdom,$cnum); } + &Apache::lonnet::devalidatecourseresdata($cnum,$cdom); } else { # ------------------------------------------------------------------ Store User # @@ -825,8 +855,6 @@ sub assessparms { my %allparts; my %defp; - %courseopt=(); - %useropt=(); @ids=(); %symbp=(); @@ -928,14 +956,6 @@ sub assessparms { my $fcat=$env{'form.fcat'}; unless ($fcat) { $fcat=''; } -# ------------------------------------------------------------------- Tie hashs - - if (!(tie(%parmhash,'GDBM_File', - $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640))) { - $r->print("Unable to access parameter data. (File $env{'request.course.fn'}_parms.db not tieable)"); - return ; - } - # --------------------------------------------------------- Get all assessments &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allkeys, \%allmaps, $fcat, \%defp, \%mapp, \%symbp,\%maptitles,\%uris); @@ -951,21 +971,6 @@ sub assessparms { # ---------------------------------------------------------------- Done storing $message.='