[LON-CAPA-cvs] cvs: loncom / lonmap.pm

foxr foxr at source.lon-capa.org
Tue Nov 29 06:50:53 EST 2011


foxr		Tue Nov 29 11:50:53 2011 EDT

  Modified files:              
    /loncom	lonmap.pm 
  Log:
  BZ 6454 - Get random ordering to 1. Know when to randomize 2. generate random seeds consistent with lonuserstate.pm
  
  
  
Index: loncom/lonmap.pm
diff -u loncom/lonmap.pm:1.5 loncom/lonmap.pm:1.6
--- loncom/lonmap.pm:1.5	Fri Oct 21 10:10:07 2011
+++ loncom/lonmap.pm	Tue Nov 29 11:50:53 2011
@@ -2,7 +2,7 @@
 #
 #  Read maps into a 'big hash'.
 #
-# $Id: lonmap.pm,v 1.5 2011/10/21 10:10:07 foxr Exp $
+# $Id: lonmap.pm,v 1.6 2011/11/29 11:50:53 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -40,6 +40,8 @@
 
 use LONCAPA;
 use Apache::lonnet;
+use Apache::lonlocal;
+
 use Data::Dumper;
 
 
@@ -68,6 +70,7 @@
 
 my $username;			# User for whom the map is being read.
 my $userdomain;  		# Domain the user lives in.
+my $short_name;			# Course shortname.
 my %mapalias_cache;		# Keeps track of map aliases -> resources detects duplicates.
 my %cenv;			# Course environment.
 
@@ -371,6 +374,32 @@
     return $uri;
 
 }
+#------------------------------------------------------------------------------
+#
+#  Misc. utilities that don't fit into the other classifications.
+
+# Determine if the specified user has an 'advanced' role in a course.
+# Parameters:
+#   cenv       - reference to a course environment.
+#   username   - Name of the user we care about.
+#   domain     - Domain in which the user is defined.
+# Returns:
+#    0  - User does not have an advanced role in the course.
+#    1  - User does have an advanced role in the course.
+#
+sub has_advanced_role {
+    my ($username, $domain) = @_;
+
+    my %adv_roles = &Apache::lonnet::get_course_adv_roles($short_name);
+    my $merged_username = $username . ':' . $domain;
+    foreach my $user (values %adv_roles) {
+	if ($merged_username eq $user) {
+	    return 1;
+	}
+    }
+    return 0;
+}
+
 #--------------------------------------------------------------------------------
 # Post processing subs:
 sub hiddenurls {
@@ -1205,6 +1234,7 @@
 
     my $ispage = ($filename =~/\.page$/);
     unless ($ispage || ($filename =~ /\.sequence$/)) {
+	&Apache::lonnet::logthis("invalid: $filename : $uri");
 	throw Error::Simple(&mt("<br />Invalid map: <tt>[_1]</tt>", $filename));
     }
 
@@ -1283,7 +1313,7 @@
     # 
 
     if ($randomize) {
-	if (!$env{'request.role.adv'}) {
+	if (!&has_advanced_role($username, $userdomain) ) {
 	    my $seed;
 
 	    # In the advanced role, the map's random seed
@@ -1305,7 +1335,11 @@
 	    }
 
 
-	    my $rndseed=&Apache::lonnet::rndseed($seed, $username, $userdomain);
+	    my $rndseed=&Apache::lonnet::rndseed($seed, '', 
+						 $userdomain, $username,
+						 \%cenv);
+						 
+
 	    &Apache::lonnet::setup_random_from_rndseed($rndseed);
 
 	    # Take the set of map ids we have decoded and permute them to a
@@ -1313,10 +1347,8 @@
 	    # processing the randomorder parameter if it is set, not
 	    # randompick.
 
-	    @map_ids=&math::Random::random_permutation(@map_ids); 
+	    @map_ids=&Math::Random::random_permutation(@map_ids); 
 	}
-
-
 	my $from = shift(@map_ids);
 	my $from_rid = $lmap_no.'.'.$from;
 	$hash->{'map_start_'.$uri} = $from_rid;
@@ -1338,6 +1370,7 @@
 	$hash->{'type_'.$from_rid}='finish';
     }
 
+
     #  The last parsing pass parses the <mapalias> tags that associate a name
     #  with resource ids.
 
@@ -1397,29 +1430,29 @@
     $username   = $uname;
     $userdomain = $udom;
 
-    my $short_name = $cdom .'/' . $cnum;
+    $short_name = $cdom .'/' . $cnum;
     my $retfurl;
 
     try {
 
 	
 	# Get the information we need about the course.
-	# Return without filling in anything if we can't get any info:
-	
-	%cenv = &Apache::lonnet::coursedescription($short_name,
-						     {'freshen_cache' => 1,
-						      'user'          => $uname}); 
-
-	unless ($cenv{'url'}) { 
-	    &Apache::lonnet::logthis("lonmap::loadmap failed: $cnum/$cdom - did not get url");
-	    return; 
-	}
-
-	$course_id = $cdom . '_' . $cnum; # Long course id.
-
-	# Load the version information into the hash
-
-	
+ 	# Return without filling in anything if we can't get any info:
+ 	
+ 	%cenv = &Apache::lonnet::coursedescription($short_name,
+ 						     {'freshen_cache' => 1,
+ 						      'user'          => $uname}); 
+ 
+ 	unless ($cenv{'url'}) { 
+ 	    &Apache::lonnet::logthis("lonmap::loadmap failed: $cnum/$cdom - did not get url");
+ 	    return; 
+ 	}
+ 
+ 	$course_id = $cdom . '_' . $cnum; # Long course id.
+ 
+ 	# Load the version information into the hash
+ 
+ 	
 	&process_versions(\%cenv, $target_hash);
 	
 	
@@ -1443,6 +1476,7 @@
 	$target_hash->{'context.userdom'}  = $userdomain;
 	$target_hash->{'context.courseid'} = $course_id;
 
+
         &read_map($course_uri, '0.0', $target_hash);
 
 	# 




More information about the LON-CAPA-cvs mailing list