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

www lon-capa-cvs@mail.lon-capa.org
Mon, 06 Jun 2005 17:38:10 -0000


www		Mon Jun  6 13:38:10 2005 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  Bug #2497: list order in overview (now configurable)
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.213 loncom/interface/lonparmset.pm:1.214
--- loncom/interface/lonparmset.pm:1.213	Mon Jun  6 11:46:02 2005
+++ loncom/interface/lonparmset.pm	Mon Jun  6 13:38:07 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.213 2005/06/06 15:46:02 www Exp $
+# $Id: lonparmset.pm,v 1.214 2005/06/06 17:38:07 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -972,6 +972,20 @@
     } (keys %{$name});
 }
 
+sub sortmenu {
+    my ($r,$sortorder)=@_;
+    $r->print('<br /><input type="radio" name="sortorder" value="realmstudent"');
+    if ($sortorder eq 'realmstudent') {
+       $r->print(' checked="on"');
+    }
+    $r->print(' />'.&mt('Sort by realm first, then student (group/section)'));
+    $r->print('<br /><input type="radio" name="sortorder" value="studentrealm"');
+    if ($sortorder eq 'studentrealm') {
+       $r->print(' checked="on"');
+    }
+    $r->print(' />'.&mt('Sort by student (group/section) first, then realm'));
+}
+
 sub standardkeyorder {
     return ('parameter_0_opendate' => 1,
 	    'parameter_0_duedate' => 2,
@@ -2036,7 +2050,7 @@
 }
 
 sub listdata {
-    my ($r,$resourcedata,$listdata)=@_;
+    my ($r,$resourcedata,$listdata,$sortorder)=@_;
 # Start list output
 
     my $oldsection='';
@@ -2045,7 +2059,15 @@
     my $pointer=0;
     $tableopen=0;
     my $foundkeys=0;
-    foreach my $thiskey (sort keys %{$listdata}) {
+    foreach my $thiskey (sort {
+	if ($sortorder eq 'realmstudent') {
+	    my ($astudent,$arealm)=($a=~/^$env{'request.course.id'}\.([^\.]+)\.(.+)\.[^\.]+$/);
+	    my ($bstudent,$brealm)=($b=~/^$env{'request.course.id'}\.([^\.]+)\.(.+)\.[^\.]+$/);
+            ($arealm cmp $brealm) || ($astudent cmp $bstudent);
+	} else {
+	    $a cmp $b;
+	}
+    } keys %{$listdata}) {
 	if ($$listdata{$thiskey.'.type'}) {
             my $thistype=$$listdata{$thiskey.'.type'};
             if ($$resourcedata{$thiskey.'.type'}) {
@@ -2072,19 +2094,32 @@
 		my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
 		$realm='<font color="orange">'.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).' <br /><font color="#aaaaaa" size="-2">('.$url.' in '.$map.' id: '.$id.')</font></font>';
 	    }
-	    if ($section ne $oldsection) {
-		$r->print(&tableend()."\n<hr /><h1>$section</h1>");
-		$oldsection=$section;
-		$oldrealm='';
-	    }
-	    if ($realm ne $oldrealm) {
-		$r->print(&tableend()."\n<h2>$realm</h2>");
-		$oldrealm=$realm;
-		$oldpart='';
+	    if ($sortorder eq 'realmstudent') {
+		if ($realm ne $oldrealm) {
+		    $r->print(&tableend()."\n<hr /><h1>$realm</h1>");
+		    $oldrealm=$realm;
+		    $oldsection='';
+		}
+		if ($section ne $oldsection) {
+		    $r->print(&tableend()."\n<h2>$section</h2>");
+		    $oldsection=$section;
+		    $oldpart='';
+		}
+	    } else {
+		if ($section ne $oldsection) {
+		    $r->print(&tableend()."\n<hr /><h1>$section</h1>");
+		    $oldsection=$section;
+		    $oldrealm='';
+		}
+		if ($realm ne $oldrealm) {
+		    $r->print(&tableend()."\n<h2>$realm</h2>");
+		    $oldrealm=$realm;
+		    $oldpart='';
+		}
 	    }
 	    if ($part ne $oldpart) {
 		$r->print(&tableend().
-			  "\n<h3><font color='blue'>".&mt('Part').": $part</font></h3>");
+			  "\n<font color='blue'>".&mt('Part').": $part</font>");
 		$oldpart=$part;
 	    }
 #
@@ -2196,8 +2231,14 @@
     &partmenu($r,\%allparts,\@psprt);
     $r->print('</td><td>');
     &sectionmenu($r,\@selected_sections);
-    $r->print('</td></tr></table>'.
-	      '<p><input type="submit" name="dis" value="'.&mt('Display').'" /></p>');
+
+    $r->print('</td></tr></table>');
+ 
+    my $sortorder=$env{'form.sortorder'};
+    unless ($sortorder) { $sortorder='realmstudent'; }
+    &sortmenu($r,$sortorder);
+
+    $r->print('<p><input type="submit" name="dis" value="'.&mt('Display').'" /></p>');
 
 # Build the list data hash from the specified parms
 
@@ -2248,7 +2289,7 @@
 
 # List data
 
-	&listdata($r,$resourcedata,$listdata);
+	&listdata($r,$resourcedata,$listdata,$sortorder);
     }
     $r->print(&tableend().
 	     ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Store').'" /></p>':'').
@@ -2280,9 +2321,14 @@
 
     my $resourcedata=&readdata($crs,$dom);
 
+
+    my $sortorder=$env{'form.sortorder'};
+    unless ($sortorder) { $sortorder='realmstudent'; }
+    &sortmenu($r,$sortorder);
+
 # List data
 
-    my $foundkeys=&listdata($r,$resourcedata,$resourcedata);
+    my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder);
 
     $r->print(&tableend().'<p>'.
 	($foundkeys?'<input type="submit" value="'.&mt('Modify Parameters').'" />':&mt('There are no parameters.')).'</p></form></body></html>');