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

foxr foxr at source.lon-capa.org
Fri Oct 21 06:13:57 EDT 2011


foxr		Fri Oct 21 10:13:57 2011 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm lonnavmaps.pm 
  Log:
  BZ 6454 - make randompick work... randomly order still to go.
  
  
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.599 loncom/interface/lonprintout.pm:1.600
--- loncom/interface/lonprintout.pm:1.599	Mon Oct 10 15:34:32 2011
+++ loncom/interface/lonprintout.pm	Fri Oct 21 10:13:57 2011
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.599 2011/10/10 15:34:32 raeburn Exp $
+# $Id: lonprintout.pm,v 1.600 2011/10/21 10:13:57 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -471,7 +471,7 @@
 #   $helper - The helper we need $helper->{'VARS'}->{'symb'}
 #            to construct the navmap and the iteration.
 #   $seq   - The original set of resources to print 
-#            (really an array of resource names
+#            (really an array of resource names (array of symb's).
 #   $who   - Student/domain for whome the sequence will be generated.
 #
 # Implicit inputs:
@@ -486,6 +486,7 @@
 
     my ($username, $userdomain, $usersection) = split(/:/, $who);
 
+
     # Toss the sequence up into a hash so that we have O(1) lookup time.
     # on the items that come out of the user's list of resources.
     #
@@ -515,7 +516,8 @@
     my $curres;
     while ($curres = $iterator->next()) {
 	#
-	#  Only process resources..that re not removed by randomout...
+	#  Only process resources..that are not removed by randomout...
+	#  and are selected for printint as well.
 	#
 	if (! exists $nonResourceItems{$curres} && ! $curres->randomout()) {
 	    my $symb = $curres->symb();
@@ -2047,7 +2049,7 @@
 #    A reference to a page break hash.
 #
 #
-# use Data::Dumper;
+use Data::Dumper;
 # sub dump_helper_vars {
 #    my ($helper) = @_;
 #    my $helpervars = Dumper($helper->{'VARS'});
@@ -3265,6 +3267,7 @@
     my ($username,$userdomain,$usersection) = split /:/,$person;
     my $fullname = &get_name($username,$userdomain);
     my $namepostfix = "\\\\";	# Both anon and not anon should get the same vspace.
+
     #
     # Figure out if we need to filter the output by
     # the incomplete problems for that person
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.464 loncom/interface/lonnavmaps.pm:1.465
--- loncom/interface/lonnavmaps.pm:1.464	Thu Sep 22 12:48:40 2011
+++ loncom/interface/lonnavmaps.pm	Fri Oct 21 10:13:57 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.464 2011/09/22 12:48:40 raeburn Exp $
+# $Id: lonnavmaps.pm,v 1.465 2011/10/21 10:13:57 foxr Exp $
 
 #
 # Copyright Michigan State University Board of Trustees
@@ -478,12 +478,18 @@
 use Apache::lonenc();
 use Apache::lonlocal;
 use Apache::lonnet;
+use Apache::lonmap;
 
 use POSIX qw (floor strftime);
 use Time::HiRes qw( gettimeofday tv_interval );
 use LONCAPA;
 use DateTime();
+
+# For debugging
+
 use Data::Dumper;
+
+
 # symbolic constants
 sub SYMB { return 1; }
 sub URL { return 2; }
@@ -1961,10 +1967,13 @@
     my $proto = shift;
     my $class = ref($proto) || $proto;
     my $self = {};
+    bless($self);		# So we can call change_user if neceesary
 
     $self->{USERNAME} = shift || $env{'user.name'};
     $self->{DOMAIN}   = shift || $env{'user.domain'};
 
+
+
     # Resource cache stores navmap resources as we reference them. We generate
     # them on-demand so we don't pay for creating resources unless we use them.
     $self->{RESOURCE_CACHE} = {};
@@ -1973,31 +1982,90 @@
     # failed
     $self->{NETWORK_FAILURE} = 0;
 
-    # tie the nav hash
+    # We can only tie the nav hash as done below if the username/domain
+    # match the env one. Otherwise change_user does everything we need...since we can't
+    # assume there are course hashes for the specific requested user at domamin:
+    #
 
-    my %navmaphash;
-    my %parmhash;
-    my $courseFn = $env{"request.course.fn"};
-    if (!(tie(%navmaphash, 'GDBM_File', "${courseFn}.db",
-              &GDBM_READER(), 0640))) {
-        return undef;
+    if (($self->{USERNAME} eq $env{'user.name'}) && ($self->{DOMAIN} eq $env{'user.domain'})) {
+	
+	# tie the nav hash
+	
+	my %navmaphash;
+	my %parmhash;
+	my $courseFn = $env{"request.course.fn"};
+	if (!(tie(%navmaphash, 'GDBM_File', "${courseFn}.db",
+		  &GDBM_READER(), 0640))) {
+	    return undef;
+	}
+	
+	if (!(tie(%parmhash, 'GDBM_File', "${courseFn}_parms.db",
+		  &GDBM_READER(), 0640)))
+	{
+	    untie %{$self->{PARM_HASH}};
+	    return undef;
+	}
+	
+	$self->{NAV_HASH} = \%navmaphash;
+	$self->{PARM_HASH} = \%parmhash;
+	$self->{PARM_CACHE} = {};
+    } else {
+	$self->change_user($self->{USERNAME}, $self->{DOMAIN});
     }
+        
+    return $self;
+}
+
+#
+#  In some instances it is useful to be able to dynamically change the
+# username/domain associated with a navmap (e.g. to navigate for someone
+# else besides the current user...if sufficiently privileged.
+# Parameters:
+#    user  - New user.
+#    domain- Domain the user belongs to.
+# Implicit inputs:
+#   
+sub change_user {
+    my $self = shift;
+    $self->{USERNAME} = shift;
+    $self->{DOMAIN}   = shift;
+
+    # If the hashes are already tied make sure to break that bond:
+
+    untie %{$self->{NAV_HASH}}; 
+    untie %{$self->{PARM_HASH}};
+
+    # The assumption is that we have to
+    # use lonmap here to re-read the hash and from it reconstruct
+    # new big and parameter hashes.  An implicit assumption at this time
+    # is that the course file is probably not created locally yet
+    # an that we will therefore just read without tying.
+
+    my ($cdom, $cnum) = split(/\_/, $env{'request.course.id'});
+
+    my %big_hash;
+    &Apache::lonmap::loadmap($cnum, $cdom, $self->{USERNAME}, $self->{DOMAIN}, \%big_hash);
+    $self->{NAV_HASH} = \%big_hash;
+
+    # Now clear the parm cache and reconstruct the parm hash fromt he big_hash
+    # param.xxxx keys.
+
+    $self->{PARM_CACHE} = {};
     
-    if (!(tie(%parmhash, 'GDBM_File', "${courseFn}_parms.db",
-              &GDBM_READER(), 0640)))
-    {
-        untie %{$self->{PARM_HASH}};
-        return undef;
+    my %parm_hash = {};
+    foreach my $key (keys %big_hash) {
+	if ($key =~ /^param\./) {
+	    my $param_key = $key;
+	    $param_key =~ s/^param\.//;
+	    $parm_hash{$param_key} = $big_hash{$key};
+	}
     }
 
-    $self->{NAV_HASH} = \%navmaphash;
-    $self->{PARM_HASH} = \%parmhash;
-    $self->{PARM_CACHE} = {};
+    $self->{PARM_HASH} = \%parm_hash;
 
-    bless($self);
-        
-    return $self;
-}
+
+    
+} 
 
 sub generate_course_user_opt {
     my $self = shift;




More information about the LON-CAPA-cvs mailing list