[LON-CAPA-cvs] cvs: loncom /homework grades.pm /interface loncommon.pm loncoursedata.pm /interface/spreadsheet assesscalc.pm studentcalc.pm /lonnet/perl lonnet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 02 Nov 2004 20:48:03 -0000


This is a MIME encoded message

--albertel1099428483
Content-Type: text/plain

albertel		Tue Nov  2 15:48:03 2004 EDT

  Modified files:              
    /loncom/interface	loncommon.pm loncoursedata.pm 
    /loncom/homework	grades.pm 
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/interface/spreadsheet	assesscalc.pm studentcalc.pm 
  Log:
  consolidate some of the multitude of functions out there that try to format and display the student's 'fullname'
  
  
--albertel1099428483
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20041102154803.txt"

Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.225 loncom/interface/loncommon.pm:1.226
--- loncom/interface/loncommon.pm:1.225	Tue Nov  2 14:01:12 2004
+++ loncom/interface/loncommon.pm	Tue Nov  2 15:48:02 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.225 2004/11/02 19:01:12 matthew Exp $
+# $Id: loncommon.pm,v 1.226 2004/11/02 20:48:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -59,7 +59,6 @@
 use GDBM_File;
 use POSIX qw(strftime mktime);
 use Apache::Constants qw(:common :http :methods);
-use Apache::lonmsg();
 use Apache::lonmenu();
 use Apache::lonlocal;
 use HTML::Entities;
@@ -1741,21 +1740,26 @@
 
 =over 4
 
-=item * plainname($uname,$udom)
+=item * plainname($uname,$udom,$first)
 
 Takes a users logon name and returns it as a string in
-"first middle last generation" form
+"first middle last generation" form 
+if $first is set to 'lastname' then it returns it as
+'lastname generation, firstname middlename' if their is a lastname
 
 =cut
 
 ###############################################################
 sub plainname {
-    my ($uname,$udom)=@_;
+    my ($uname,$udom,$first)=@_;
     my %names=&Apache::lonnet::get('environment',
                     ['firstname','middlename','lastname','generation'],
 					 $udom,$uname);
-    my $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
-	$names{'lastname'}.' '.$names{'generation'};
+    my $name=&Apache::lonnet::format_name($names{'firstname'},
+					  $names{'middlename'},
+					  $names{'lastname'},
+					  $names{'generation'},$first);
+    $name=~s/^\s+//;
     $name=~s/\s+$//;
     $name=~s/\s+/ /g;
     if ($name !~ /\S/) { $name=$uname.'@'.$udom; }
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.140 loncom/interface/loncoursedata.pm:1.141
--- loncom/interface/loncoursedata.pm:1.140	Thu Oct  7 18:12:47 2004
+++ loncom/interface/loncoursedata.pm	Tue Nov  2 15:48:02 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursedata.pm,v 1.140 2004/10/07 22:12:47 albertel Exp $
+# $Id: loncoursedata.pm,v 1.141 2004/11/02 20:48:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -240,76 +240,6 @@
 
 =pod
 
-=item &GetUserName(username,userdomain)
-
-Returns a hash with the following entries:
-   'firstname', 'middlename', 'lastname', 'generation', and 'fullname'
-
-   'fullname' is the result of &Apache::loncoursedata::ProcessFullName.
-
-=cut
-
-################################################
-################################################
-sub GetUserName {
-    my ($username,$userdomain) = @_;
-    $username = $ENV{'user.name'} if (! defined($username));
-    $userdomain = $ENV{'user.domain'} if (! defined($username));
-    my %userenv = &Apache::lonnet::get('environment',
-                           ['firstname','middlename','lastname','generation'],
-                                       $userdomain,$username);
-    $userenv{'fullname'} = &ProcessFullName($userenv{'lastname'},
-                                            $userenv{'generation'},
-                                            $userenv{'firstname'},
-                                            $userenv{'middlename'});
-    return %userenv;
-}
-
-################################################
-################################################
-
-=pod
-
-=item &ProcessFullName()
-
-Takes lastname, generation, firstname, and middlename (or some partial
-set of this data) and returns the full name version as a string.  Format
-is Lastname generation, firstname middlename or a subset of this.
-
-=cut
-
-################################################
-################################################
-sub ProcessFullName {
-    my ($lastname, $generation, $firstname, $middlename)=@_;
-    my $Str = '';
-
-    # Strip whitespace preceeding & following name components.
-    $lastname   =~ s/(\s+$|^\s+)//g;
-    $generation =~ s/(\s+$|^\s+)//g;
-    $firstname  =~ s/(\s+$|^\s+)//g;
-    $middlename =~ s/(\s+$|^\s+)//g;
-
-    if($lastname ne '') {
-	$Str .= $lastname;
-	$Str .= ' '.$generation if ($generation ne '');
-	$Str .= ',';
-        $Str .= ' '.$firstname  if ($firstname ne '');
-        $Str .= ' '.$middlename if ($middlename ne '');
-    } else {
-        $Str .= $firstname      if ($firstname ne '');
-        $Str .= ' '.$middlename if ($middlename ne '');
-        $Str .= ' '.$generation if ($generation ne '');
-    }
-
-    return $Str;
-}
-
-################################################
-################################################
-
-=pod
-
 =item &make_into_hash($values);
 
 Returns a reference to a hash as described by $values.  $values is
@@ -2946,14 +2876,13 @@
                 &Apache::lonnet::logthis('unable to retrieve environment '.
                                          'for '.$sname.':'.$sdom);
             } else {
-                $fullname = &ProcessFullName(@info{qw/lastname generation 
-                                                       firstname middlename/});
+                $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
                 $id = $info{'id'};
             }
             # Update the classlist with this students information
             if ($fullname ne 'not available') {
-                my $enrolldata = join(':',$end,$start,$id,$section,$fullname);
-                my $reply=&Apache::lonnet::cput('classlist',
+		my $enrolldata = join(':',$end,$start,$id,$section,$fullname);
+		my $reply=&Apache::lonnet::cput('classlist',
                                                 {$student => $enrolldata},
                                                 $cdom,$cnum);
                 if ($reply !~ /^(ok|delayed)/) {
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.222 loncom/homework/grades.pm:1.223
--- loncom/homework/grades.pm:1.222	Mon Oct 18 15:37:10 2004
+++ loncom/homework/grades.pm	Tue Nov  2 15:48:02 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.222 2004/10/18 19:37:10 albertel Exp $
+# $Id: grades.pm,v 1.223 2004/11/02 20:48:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -91,25 +91,6 @@
     return ($symb,$url);
 }
 
-# --- Retrieve the fullname for a user. Return lastname, first middle ---
-# --- Generation is attached next to the lastname if it exists. ---
-sub get_fullname {
-    my ($uname,$udom) = @_;
-    my %name=&Apache::lonnet::get('environment', ['lastname','generation',
-						  'firstname','middlename'],
-                                  $udom,$uname);
-    my $fullname;
-    my ($tmp) = keys(%name);
-    if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
-        $fullname = &Apache::loncoursedata::ProcessFullName
-            (@name{qw/lastname generation firstname middlename/});
-    } else {
-        &Apache::lonnet::logthis('grades.pm: no name data for '.$uname.
-                                 '@'.$udom.':'.$tmp);
-    }
-    return $fullname;
-}
-
 #--- Format fullname, username:domain if different for display
 #--- Use anywhere where the student names are listed
 sub nameUserString {
@@ -1404,7 +1385,7 @@
     my ($uname,$udom)     = ($ENV{'form.student'},$ENV{'form.userdom'});
     $udom = ($udom eq '' ? $ENV{'user.domain'} : $udom); #has form.userdom changed for a student?
     my $usec = &Apache::lonnet::getsection($udom,$uname,$ENV{'request.course.id'});
-    $ENV{'form.fullname'} = &get_fullname ($uname,$udom) if $ENV{'form.fullname'} eq '';
+    $ENV{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $ENV{'form.fullname'} eq '';
 
     my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
     if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.555 loncom/lonnet/perl/lonnet.pm:1.556
--- loncom/lonnet/perl/lonnet.pm:1.555	Wed Oct 27 14:23:08 2004
+++ loncom/lonnet/perl/lonnet.pm	Tue Nov  2 15:48:02 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.555 2004/10/27 18:23:08 albertel Exp $
+# $Id: lonnet.pm,v 1.556 2004/11/02 20:48:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -47,7 +47,6 @@
 use Apache::Constants qw(:common :http);
 use HTML::LCParser;
 use Fcntl qw(:flock);
-use Apache::loncoursedata;
 use Apache::lonlocal;
 use Storable qw(lock_store lock_nstore lock_retrieve freeze thaw);
 use Time::HiRes qw( gettimeofday tv_interval );
@@ -3628,8 +3627,7 @@
         $gene   = $tmp{'generation'} if (!defined($gene)   || $gene eq '');
         $uid    = $tmp{'id'}         if (!defined($uid)    || $uid  eq '');
     }
-    my $fullname = &Apache::loncoursedata::ProcessFullName($last,$gene,
-                                                           $first,$middle);
+    my $fullname = &format_name($first,$middle,$last,$gene,'lastname');
     my $reply=cput('classlist',
 		   {"$uname:$udom" => 
 			join(':',$end,$start,$uid,$usec,$fullname,$type,$locktype) },
@@ -3646,6 +3644,25 @@
     return &assignrole($udom,$uname,$uurl,'st',$end,$start);
 }
 
+sub format_name {
+    my ($firstname,$middlename,$lastname,$generation,$first)=@_;
+    my $name;
+    if ($first ne 'lastname') {
+	$name=$firstname.' '.$middlename.' '.$lastname.' '.$generation;
+    } else {
+	if ($lastname=~/\S/) {
+	    $name.= $lastname.' '.$generation.', '.$firstname.' '.$middlename;
+	    $name=~s/\s+,/,/;
+	} else {
+	    $name.= $firstname.' '.$middlename.' '.$generation;
+	}
+    }
+    $name=~s/^\s+//;
+    $name=~s/\s+$//;
+    $name=~s/\s+/ /g;
+    return $name;
+}
+
 # ------------------------------------------------- Write to course preferences
 
 sub writecoursepref {
Index: loncom/interface/spreadsheet/assesscalc.pm
diff -u loncom/interface/spreadsheet/assesscalc.pm:1.33 loncom/interface/spreadsheet/assesscalc.pm:1.34
--- loncom/interface/spreadsheet/assesscalc.pm:1.33	Tue Feb 24 15:47:14 2004
+++ loncom/interface/spreadsheet/assesscalc.pm	Tue Nov  2 15:48:02 2004
@@ -1,5 +1,5 @@
 #
-# $Id: assesscalc.pm,v 1.33 2004/02/24 20:47:14 matthew Exp $
+# $Id: assesscalc.pm,v 1.34 2004/11/02 20:48:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -397,11 +397,8 @@
     my @title = ($self->get_title());
     # Look up the users identifying information
     # Get the users information
-    my %userenv = &Apache::loncoursedata::GetUserName($self->{'name'},
-                                                      $self->{'domain'});
-    my $name = 
-        join(' ',@userenv{'firstname','middlename','lastname','generation'});
-    $name =~ s/\s+$//;
+    my $name = &Apache::loncommon::plainname($self->{'name'},
+					     $self->{'domain'});
     push (@title,$name);
     push (@title,&Apache::lonlocal::locallocaltime(time));
     return @title;
Index: loncom/interface/spreadsheet/studentcalc.pm
diff -u loncom/interface/spreadsheet/studentcalc.pm:1.25 loncom/interface/spreadsheet/studentcalc.pm:1.26
--- loncom/interface/spreadsheet/studentcalc.pm:1.25	Mon Dec  8 14:58:39 2003
+++ loncom/interface/spreadsheet/studentcalc.pm	Tue Nov  2 15:48:02 2004
@@ -1,5 +1,5 @@
 #
-# $Id: studentcalc.pm,v 1.25 2003/12/08 19:58:39 matthew Exp $
+# $Id: studentcalc.pm,v 1.26 2004/11/02 20:48:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -111,12 +111,8 @@
     my @title = ();
     #
     # Determine the students name
-    my %userenv = &Apache::loncoursedata::GetUserName($self->{'name'},
-                                                      $self->{'domain'});
-    my $name = join(' ',
-                 @userenv{'firstname','middlename','lastname','generation'});
-    $name =~ s/\s+$//;
-
+    my $name = &Apache::loncommon::plainname($self->{'name'},
+					     $self->{'domain'});
     push (@title,$name);
     push (@title,$self->{'coursedesc'});
     push (@title,&Apache::lonlocal::locallocaltime(time));

--albertel1099428483--