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

albertel lon-capa-cvs-allow@mail.lon-capa.org
Fri, 10 Aug 2007 23:20:10 -0000


albertel		Fri Aug 10 19:20:10 2007 EDT

  Modified files:              
    /loncom/interface	lonpickstudent.pm 
  Log:
  - BUG#5344, when picking from role assigned to users, collapse multiple roles assigned into one line with multiple roless associated
  
  
Index: loncom/interface/lonpickstudent.pm
diff -u loncom/interface/lonpickstudent.pm:1.22 loncom/interface/lonpickstudent.pm:1.23
--- loncom/interface/lonpickstudent.pm:1.22	Wed Aug  1 21:39:26 2007
+++ loncom/interface/lonpickstudent.pm	Fri Aug 10 19:20:09 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a student from the classlist
 #
-# $Id: lonpickstudent.pm,v 1.22 2007/08/02 01:39:26 albertel Exp $
+# $Id: lonpickstudent.pm,v 1.23 2007/08/10 23:20:09 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -122,8 +122,8 @@
 	    &Apache::lonnet::get_course_adv_roles();
 	$r->print(&Apache::loncommon::start_data_table());
 	foreach my $role (sort(keys(%coursepersonnel))) {
-	    foreach (split(/\,/,$coursepersonnel{$role})) {
-		my ($puname,$pudom)=split(/\:/,$_);
+	    foreach my $user (split(/\,/,$coursepersonnel{$role})) {
+		my ($puname,$pudom)=split(/\:/,$user);
 		$role = &Apache::lonnet::plaintext($role,
 						   &Apache::loncommon::course_type());
 		$r->print(&Apache::loncommon::start_data_table_row().
@@ -201,28 +201,35 @@
 	$r->print($filtermsg);
 
 	$r->print('<p>'.&Apache::loncommon::start_data_table());
-	my %users=&Apache::lonnet::get_my_roles();
-	foreach my $user (sort(keys(%users))) {
-	    if ($user =~
-		/^($LONCAPA::username_re)\:($LONCAPA::domain_re)\:(\w+)$/) {
-		my ($uname,$udom,$urole)=($1,$2,$3);
-		my $fullname=&Apache::loncommon::plainname($uname,$udom);
-		if (($uname=~/^$filter/) || 
-		    ($fullname=~/^$filter/i)) {
-		    $r->print(&Apache::loncommon::start_data_table_row().
-			      '<td>'.
-			      '<input type="button" value="Select" onClick="gochoose('.
-			      "'".$uname."','".$udom."')".'" /></td>'.
-			      '<td><tt>'.$uname.'</tt></td><td><tt>'.$udom.
-			      '</tt></td><td>'.
-			      &Apache::loncommon::aboutmewrapper(
-								 $fullname,
-								 $uname,$udom).'</td><td><td>'.
-			      &Apache::lonnet::plaintext($urole).
-			      '</td>'.
-			      &Apache::loncommon::end_data_table_row());
-		}
+	my %user_role=&Apache::lonnet::get_my_roles();
+	my %users;
+	foreach my $user_role (keys(%user_role)) {
+	    next if ($user_role !~
+		     /^($LONCAPA::username_re):($LONCAPA::domain_re):(\w+)$/);
+	    my ($uname,$udom,$urole)=($1,$2,$3);
+	    my $fullname=&Apache::loncommon::plainname($uname,$udom);
+	    next if (($uname!~/^$filter/i) && ($fullname=~/^$filter/i));
+	    
+	    if (!exists($users{"$uname:$udom"})) {
+		$users{"$uname:$udom"} = {'fullname' => $fullname };
 	    }
+	    push(@{$users{"$uname:$udom"}{'roles'}},$urole);
+	}
+	foreach my $user (sort {lc($a) cmp lc($b)} (keys(%users))) {
+	    my ($uname,$udom) = split(':',$user);
+	    $r->print(&Apache::loncommon::start_data_table_row().
+		      '<td>'.
+		      '<input type="button" value="Select" onClick="gochoose('.
+		      "'".$uname."','".$udom."')".'" /></td>'.
+		      '<td><tt>'.$uname.'</tt></td>'.
+		      '<td><tt>'.$udom.'</tt></td><td>'.
+		      &Apache::loncommon::aboutmewrapper($users{$user}{'fullname'},
+							 $uname,$udom).'</td>'.
+		      '<td>'.
+		      join(', ',sort(map {&Apache::lonnet::plaintext($_)}
+				         (@{$users{$user}{'roles'}}))).
+		      '</td>'.
+		      &Apache::loncommon::end_data_table_row());
 	}
 	$r->print(&Apache::loncommon::end_data_table().'</p>');
     }