[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm /lonnet/perl lonnet.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Tue, 20 Nov 2007 00:26:39 -0000


This is a MIME encoded message

--albertel1195518399
Content-Type: text/plain

albertel		Mon Nov 19 19:26:39 2007 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - BUG#5513 adding ability for EXT (and navmaps equivalent) to get the 
    level that a parameter is set at 
  
  
--albertel1195518399
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20071119192639.txt"

Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.404 loncom/interface/lonnavmaps.pm:1.405
--- loncom/interface/lonnavmaps.pm:1.404	Fri Nov  9 19:11:13 2007
+++ loncom/interface/lonnavmaps.pm	Mon Nov 19 19:26:17 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.404 2007/11/10 00:11:13 albertel Exp $
+# $Id: lonnavmaps.pm,v 1.405 2007/11/20 00:26:17 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2295,12 +2295,19 @@
     my $hashkey = $what."|||".$symb;
 
     if (defined($self->{PARM_CACHE}->{$hashkey})) {
-        return $self->{PARM_CACHE}->{$hashkey};
+       if (wantarray) {
+           return @{$self->{PARM_CACHE}->{$hashkey}};
+       } else {
+           return $self->{PARM_CACHE}->{$hashkey}->[0];
+       }
     }
 
     my $result = $self->parmval_real($what, $symb, $recurse);
     $self->{PARM_CACHE}->{$hashkey} = $result;
-    return $result;
+    if (wantarray) {
+       return @{$result};
+    }
+    return $result->[0];
 }
 
 sub parmval_real {
@@ -2321,7 +2328,7 @@
     my $uname=$env{'user.name'};
     my $udom=$env{'user.domain'};
 
-    unless ($symb) { return ''; }
+    unless ($symb) { return ['']; }
     my $result='';
 
     my ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
@@ -2353,48 +2360,49 @@
 
 # ---------------------------------------------------------- first, check user
     if ($uname and defined($useropt)) {
-        if (defined($$useropt{$courselevelr})) { return $$useropt{$courselevelr}; }
-        if (defined($$useropt{$courselevelm})) { return $$useropt{$courselevelm}; }
-        if (defined($$useropt{$courselevel})) { return $$useropt{$courselevel}; }
+        if (defined($$useropt{$courselevelr})) { return [$$useropt{$courselevelr},'resource']; }
+        if (defined($$useropt{$courselevelm})) { return [$$useropt{$courselevelm},'map']; }
+        if (defined($$useropt{$courselevel})) { return [$$useropt{$courselevel},'course']; }
     }
 
 # ------------------------------------------------------- second, check course
     if ($cgroup ne '' and defined($courseopt)) {
-        if (defined($$courseopt{$grplevelr})) { return $$courseopt{$grplevelr}; }
-        if (defined($$courseopt{$grplevelm})) { return $$courseopt{$grplevelm}; }
-        if (defined($$courseopt{$grplevel})) { return $$courseopt{$grplevel}; }
+        if (defined($$courseopt{$grplevelr})) { return [$$courseopt{$grplevelr},'resource']; }
+        if (defined($$courseopt{$grplevelm})) { return [$$courseopt{$grplevelm},'map']; }
+        if (defined($$courseopt{$grplevel})) { return [$$courseopt{$grplevel},'course']; }
     }
 
     if ($csec and defined($courseopt)) {
-        if (defined($$courseopt{$seclevelr})) { return $$courseopt{$seclevelr}; }
-        if (defined($$courseopt{$seclevelm})) { return $$courseopt{$seclevelm}; }
-        if (defined($$courseopt{$seclevel})) { return $$courseopt{$seclevel}; }
+        if (defined($$courseopt{$seclevelr})) { return [$$courseopt{$seclevelr},'resource']; }
+        if (defined($$courseopt{$seclevelm})) { return [$$courseopt{$seclevelm},'map']; }
+        if (defined($$courseopt{$seclevel})) { return [$$courseopt{$seclevel},'course']; }
     }
 
     if (defined($courseopt)) {
-        if (defined($$courseopt{$courselevelr})) { return $$courseopt{$courselevelr}; }
+        if (defined($$courseopt{$courselevelr})) { return [$$courseopt{$courselevelr},'resource']; }
     }
 
 # ----------------------------------------------------- third, check map parms
 
     my $thisparm=$$parmhash{$symbparm};
-    if (defined($thisparm)) { return $thisparm; }
+    if (defined($thisparm)) { return [$thisparm,'map']; }
 
 # ----------------------------------------------------- fourth , check default
 
     my $meta_rwhat=$rwhat;
     $meta_rwhat=~s/\./_/g;
     my $default=&Apache::lonnet::metadata($fn,$meta_rwhat);
-    if (defined($default)) { return $default}
+    if (defined($default)) { return [$default,'resource']}
     $default=&Apache::lonnet::metadata($fn,'parameter_'.$meta_rwhat);
-    if (defined($default)) { return $default}
-
+    if (defined($default)) { return [$default,'resource']}
 # --------------------------------------------------- fifth, check more course
     if (defined($courseopt)) {
-        if (defined($$courseopt{$courselevelm})) { return $$courseopt{$courselevelm}; }
-        if (defined($$courseopt{$courselevel})) { return $$courseopt{$courselevel}; }
+        if (defined($$courseopt{$courselevelm})) { return [$$courseopt{$courselevelm},'map']; }
+        if (defined($$courseopt{$courselevel})) {
+           my $ret = [$$courseopt{$courselevel},'course'];
+           return $ret;
+       }
     }
-
 # --------------------------------------------------- sixth , cascade up parts
 
     my ($space,@qualifier)=split(/\./,$rwhat);
@@ -2404,13 +2412,13 @@
 	my $id=pop(@parts);
 	my $part=join('_',@parts);
 	if ($part eq '') { $part='0'; }
-	my $partgeneral=$self->parmval($part.".$qualifier",$symb,1);
-	if (defined($partgeneral)) { return $partgeneral; }
+       my @partgeneral=$self->parmval($part.".$qualifier",$symb,1);
+       if (defined($partgeneral[0])) { return \@partgeneral; }
     }
-    if ($recurse) { return undef; }
+    if ($recurse) { return []; }
     my $pack_def=&Apache::lonnet::packages_tab_default($fn,'resource.'.$rwhat);
-    if (defined($pack_def)) { return $pack_def; }
-    return '';
+    if (defined($pack_def)) { return [$pack_def,'resource']; }
+    return [''];
 }
 
 =pod
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.926 loncom/lonnet/perl/lonnet.pm:1.927
--- loncom/lonnet/perl/lonnet.pm:1.926	Mon Nov 19 19:13:56 2007
+++ loncom/lonnet/perl/lonnet.pm	Mon Nov 19 19:26:38 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.926 2007/11/20 00:13:56 albertel Exp $
+# $Id: lonnet.pm,v 1.927 2007/11/20 00:26:38 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -6394,8 +6394,8 @@
     }
     if (!ref($result)) { return $result; }    
     foreach my $item (@which) {
-	if (defined($result->{$item})) {
-	    return $result->{$item};
+	if (defined($result->{$item->[0]})) {
+	    return [$result->{$item->[0]},$item->[1]];
 	}
     }
     return undef;
@@ -6607,8 +6607,9 @@
 # ----------------------------------------------------------- first, check user
 
 	    my $userreply=&resdata($uname,$udom,'user',
-				       ($courselevelr,$courselevelm,
-					$courselevel));
+				       ([$courselevelr,'resource'],
+					[$courselevelm,'map'     ],
+					[$courselevel, 'course'  ]));
 	    if (defined($userreply)) { return $userreply; }
 
 # ------------------------------------------------ second, check some of course
@@ -6616,15 +6617,17 @@
             if (@groups > 0) {
                 $coursereply = &check_group_parms($courseid,\@groups,$symbparm,
                                        $mapparm,$spacequalifierrest);
-                if (defined($coursereply)) { return $coursereply; }
+                if (defined($coursereply)) { return &get_reply($coursereply); }
             }
 
 	    $coursereply=&resdata($env{'course.'.$courseid.'.num'},
-				     $env{'course.'.$courseid.'.domain'},
-				     'course',
-				     ($seclevelr,$seclevelm,$seclevel,
-				      $courselevelr));
-	    if (defined($coursereply)) { return $coursereply; }
+				  $env{'course.'.$courseid.'.domain'},
+				  'course',
+				  ([$seclevelr,   'resource'],
+				   [$seclevelm,   'map'     ],
+				   [$seclevel,    'course'  ],
+				   [$courselevelr,'resource']));
+	    if (defined($coursereply)) { return &get_reply($coursereply); }
 
 # ------------------------------------------------------ third, check map parms
 	    my %parmhash=();
@@ -6635,7 +6638,7 @@
 		$thisparm=$parmhash{$symbparm};
 		untie(%parmhash);
 	    }
-	    if ($thisparm) { return $thisparm; }
+	    if ($thisparm) { return &get_reply([$thisparm,'resource']); }
 	}
 # ------------------------------------------ fourth, look in resource metadata
 
@@ -6648,18 +6651,19 @@
 	    $filename=$env{'request.filename'};
 	}
 	my $metadata=&metadata($filename,$spacequalifierrest);
-	if (defined($metadata)) { return $metadata; }
+	if (defined($metadata)) { return &get_reply([$metadata,'resource']); }
 	$metadata=&metadata($filename,'parameter_'.$spacequalifierrest);
-	if (defined($metadata)) { return $metadata; }
+	if (defined($metadata)) { return &get_reply([$metadata,'resource']); }
 
-# ---------------------------------------------- fourth, look in rest pf course
+# ---------------------------------------------- fourth, look in rest of course
 	if ($symbparm && defined($courseid) && 
 	    $courseid eq $env{'request.course.id'}) {
 	    my $coursereply=&resdata($env{'course.'.$courseid.'.num'},
 				     $env{'course.'.$courseid.'.domain'},
 				     'course',
-				     ($courselevelm,$courselevel));
-	    if (defined($coursereply)) { return $coursereply; }
+				     ([$courselevelm,'map'   ],
+				      [$courselevel, 'course']));
+	    if (defined($coursereply)) { return &get_reply($coursereply); }
 	}
 # ------------------------------------------------------------------ Cascade up
 	unless ($space eq '0') {
@@ -6667,14 +6671,13 @@
 	    my $id=pop(@parts);
 	    my $part=join('_',@parts);
 	    if ($part eq '') { $part='0'; }
-	    my $partgeneral=&EXT('resource.'.$part.'.'.$qualifierrest,
+	    my @partgeneral=&EXT('resource.'.$part.'.'.$qualifierrest,
 				 $symbparm,$udom,$uname,$section,1);
-	    if (defined($partgeneral)) { return $partgeneral; }
+	    if (@partgeneral) { return &get_reply(\@partgeneral); }
 	}
 	if ($recurse) { return undef; }
 	my $pack_def=&packages_tab_default($filename,$varname);
-	if (defined($pack_def)) { return $pack_def; }
-
+	if (defined($pack_def)) { return &get_reply([$pack_def,'resource']); }
 # ---------------------------------------------------- Any other user namespace
     } elsif ($realm eq 'environment') {
 # ----------------------------------------------------------------- environment
@@ -6702,15 +6705,23 @@
     return '';
 }
 
+sub get_reply {
+    my ($reply_value) = @_;
+    if (wantarray) {
+	return @$reply_value;
+    }
+    return $reply_value->[0];
+}
+
 sub check_group_parms {
     my ($courseid,$groups,$symbparm,$mapparm,$what) = @_;
     my @groupitems = ();
     my $resultitem;
-    my @levels = ($symbparm,$mapparm,$what);
+    my @levels = ([$symbparm,'resource'],[$mapparm,'map'],[$what,'course']);
     foreach my $group (@{$groups}) {
         foreach my $level (@levels) {
-             my $item = $courseid.'.['.$group.'].'.$level;
-             push(@groupitems,$item);
+             my $item = $courseid.'.['.$group.'].'.$level->[0];
+             push(@groupitems,[$item,$level->[1]]);
         }
     }
     my $coursereply = &resdata($env{'course.'.$courseid.'.num'},

--albertel1195518399--