Diff for /loncom/interface/loncoursedata.pm between versions 1.30 and 1.40

version 1.30, 2002/09/03 12:27:05 version 1.40, 2002/12/11 21:41:02
Line 139  sub DownloadClasslist { Line 139  sub DownloadClasslist {
     %classlist=&Apache::lonnet::dump('classlist',$courseDomain, $courseNumber);      %classlist=&Apache::lonnet::dump('classlist',$courseDomain, $courseNumber);
     foreach(keys (%classlist)) {      foreach(keys (%classlist)) {
         if(/^(con_lost|error|no_such_host)/i) {          if(/^(con_lost|error|no_such_host)/i) {
             return \%classlist;      return;
         }          }
     }      }
   
Line 310  sub ProcessTopResourceMap { Line 310  sub ProcessTopResourceMap {
     }      }
   
     my $oldkeys;      my $oldkeys;
       delete $cache->{'OptionResponses'};
     if(defined($cache->{'ResourceKeys'})) {      if(defined($cache->{'ResourceKeys'})) {
         $oldkeys = $cache->{'ResourceKeys'};          $oldkeys = $cache->{'ResourceKeys'};
         foreach (split(':::', $cache->{'ResourceKeys'})) {          foreach (split(':::', $cache->{'ResourceKeys'})) {
Line 322  sub ProcessTopResourceMap { Line 323  sub ProcessTopResourceMap {
     my (@sequences, @currentResource, @finishResource);      my (@sequences, @currentResource, @finishResource);
     my ($currentSequence, $currentResourceID, $lastResourceID);      my ($currentSequence, $currentResourceID, $lastResourceID);
   
     $currentResourceID=$hash{'ids_/res/'.$ENV{'request.course.uri'}};      $currentResourceID=$hash{'ids_'.
         &Apache::lonnet::clutter($ENV{'request.course.uri'})};
     push(@currentResource, $currentResourceID);      push(@currentResource, $currentResourceID);
     $lastResourceID=-1;      $lastResourceID=-1;
     $currentSequence=-1;      $currentSequence=-1;
Line 486  sub ProcessTopResourceMap { Line 488  sub ProcessTopResourceMap {
                 }                  }
  my @titleLength=split(//,$cache->{$currentSequence.   my @titleLength=split(//,$cache->{$currentSequence.
                                                     ':title'});                                                      ':title'});
                 # $extra is 3 for problems correct and 3 for space                  # $extra is 5 for problems correct and 3 for space
                 # between problems correct and problem output                  # between problems correct and problem output
                 my $extra = 6;                  my $extra = 8;
  if(($totalProblems + $extra) > (scalar @titleLength)) {   if(($totalProblems + $extra) > (scalar @titleLength)) {
     $cache->{$currentSequence.':columnWidth'}=      $cache->{$currentSequence.':columnWidth'}=
                         $totalProblems + $extra;                          $totalProblems + $extra;
Line 585  browser Line 587  browser
 Output: @names  Output: @names
   
 @names:  An array of students whose information has been processed, and are to   @names:  An array of students whose information has been processed, and are to 
 be considered in an arbitrary order.  be considered in an arbitrary order.  The entries in @names are of the form
   username:domain.
   
   The values in $cache are as follows:
   
    *NOTE: for the following $name implies username:domain
    $name.':error'                  only defined if an error occured.  Value
                                    contains the error message
    $name.':lastDownloadTime'       unconverted time of the last update of a
                                    student\'s course data
    $name.'updateTime'              coverted time of the last update of a 
                                    student\'s course data
    $name.':username'               username of a student
    $name.':domain'                 domain of a student
    $name.':fullname'               full name of a student
    $name.':id'                     PID of a student
    $name.':Status'                 active/expired status of a student
    $name.':section'                section of a student
   
 =back  =back
   
Line 608  sub ProcessClasslist { Line 627  sub ProcessClasslist {
         if($c->aborted()) {          if($c->aborted()) {
             return ();              return ();
         }          }
         my $studentInformation = $classlist->{$name.':studentInformation'},          my $studentInformation = $classlist->{$name.':studentInformation'};
         my $sectionData = $classlist->{$name.':sections'},          my $date = $classlist->{$name};
         my $date = $classlist->{$name},  
         my ($studentName,$studentDomain) = split(/\:/,$name);          my ($studentName,$studentDomain) = split(/\:/,$name);
   
         $cache->{$name.':username'}=$studentName;          $cache->{$name.':username'}=$studentName;
Line 645  sub ProcessClasslist { Line 663  sub ProcessClasslist {
         $courseID=~s/^(\w)/\/$1/;          $courseID=~s/^(\w)/\/$1/;
   
         my $sec='';          my $sec='';
           my $sectionData = $classlist->{$name.':sections'};
         foreach my $key (keys (%$sectionData)) {          foreach my $key (keys (%$sectionData)) {
             my $value = $sectionData->{$key};              my $value = $sectionData->{$key};
             if ($key=~/^$courseID(?:\/)*(\w+)*\_st$/) {              if ($key=~/^$courseID(?:\/)*(\w+)*\_st$/) {
Line 652  sub ProcessClasslist { Line 671  sub ProcessClasslist {
                 if($key eq $courseID.'_st') {                  if($key eq $courseID.'_st') {
                     $tempsection='';                      $tempsection='';
                 }                  }
                 my ($dummy,$roleend,$rolestart)=split(/\_/,$value);                  my (undef,$roleend,$rolestart)=split(/\_/,$value);
                 if($roleend eq $end && $rolestart eq $start) {                  if($roleend eq $end && $rolestart eq $start) {
                     $sec = $tempsection;                      $sec = $tempsection;
                     last;                      last;
Line 1066  sub ProcessFullName { Line 1085  sub ProcessFullName {
     my ($lastname, $generation, $firstname, $middlename)=@_;      my ($lastname, $generation, $firstname, $middlename)=@_;
     my $Str = '';      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 '') {      if($lastname ne '') {
  $Str .= $lastname.' ';   $Str .= $lastname;
  if($generation ne '') {   $Str .= ' '.$generation if ($generation ne '');
     $Str .= $generation;   $Str .= ',';
  } else {          $Str .= ' '.$firstname  if ($firstname ne '');
     chop($Str);          $Str .= ' '.$middlename if ($middlename ne '');
  }  
  $Str .= ', ';  
  if($firstname ne '') {  
     $Str .= $firstname.' ';  
  }  
  if($middlename ne '') {  
     $Str .= $middlename;  
  } else {  
     chop($Str);  
     if($firstname eq '') {  
  chop($Str);  
     }  
  }  
     } else {      } else {
  if($firstname ne '') {          $Str .= $firstname      if ($firstname ne '');
     $Str .= $firstname.' ';          $Str .= ' '.$middlename if ($middlename ne '');
  }          $Str .= ' '.$generation if ($generation ne '');
  if($middlename ne '') {  
     $Str .= $middlename.' ';  
  }  
  if($generation ne '') {  
     $Str .= $generation;  
  } else {  
     chop($Str);  
  }  
     }      }
   
     return $Str;      return $Str;
Line 1384  sub CheckForResidualDownload { Line 1388  sub CheckForResidualDownload {
     return 'OK';      return 'OK';
 }  }
   
   ################################################
   ################################################
   
   =pod
   
   =item &get_classlist();
   
   Retrieve the classist of a given class or of the current class.  Student
   information is returned from the classlist.db file and, if needed,
   from the students environment.
   
   Optional arguments are $cid, $cdom, and $cnum (course id, course domain,
   and course number, respectively).  Any omitted arguments will be taken 
   from the current environment ($ENV{'request.course.id'},
   $ENV{'course.'.$cid.'.domain'}, and $ENV{'course.'.$cid.'.num'}).
   
   Returns a reference to a hash which contains:
    keys    '$sname:$sdom'
    values  [$end,$start,$id,$section,$fullname]
   
   =cut
   
   ################################################
   ################################################
   
   sub get_classlist {
       my ($cid,$cdom,$cnum) = @_;
       $cid = $cid || $ENV{'request.course.id'};
       $cdom = $cdom || $ENV{'course.'.$cid.'.domain'};
       $cnum = $cnum || $ENV{'course.'.$cid.'.num'};
      my $now = time;
       #
       my %classlist=&Apache::lonnet::dump('classlist',$cdom,$cnum);
       while (my ($student,$info) = each(%classlist)) {
           return undef if ($student =~ /^(con_lost|error|no_such_host)/i);
           my ($sname,$sdom) = split(/:/,$student);
           my @Values = split(/:/,$info);
           my ($end,$start,$id,$section,$fullname);
           if (@Values > 2) {
               ($end,$start,$id,$section,$fullname) = @Values;
           } else { # We have to get the data ourselves
               ($end,$start) = @Values;
               $section = &Apache::lonnet::getsection($sdom,$sname,$cid);
               my %info=&Apache::lonnet::get('environment',
                                             ['firstname','middlename',
                                              'lastname','generation','id'],
                                             $sdom, $sname);
               my ($tmp) = keys(%info);
               if ($tmp =~/^(con_lost|error|no_such_host)/i) {
                   $fullname = 'not available';
                   $id = 'not available';
                   &Apache::lonnet::logthis('unable to retrieve environment '.
                                            'for '.$sname.':'.$sdom);
               } else {
                   $fullname = &ProcessFullName(@info{qw/lastname generation 
                                                          firstname middlename/});
                   $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',
                                                   {$student => $enrolldata},
                                                   $cdom,$cnum);
                   if ($reply !~ /^(ok|delayed)/) {
                       &Apache::lonnet::logthis('Unable to update classlist for '.
                                                'student '.$sname.':'.$sdom.
                                                ' error:'.$reply);
                   }
               }
           }
           my $status='Expired';
           if(((!$end) || $now < $end) && ((!$start) || ($now > $start))) {
               $status='Active';
           }
           $classlist{$student} = 
               [$sdom,$sname,$end,$start,$id,$section,$fullname,$status];
       }
       if (wantarray()) {
           return (\%classlist,['domain','username','end','start','id',
                                'section','fullname','status']);
       } else {
           return \%classlist;
       }
   }
   
 # ----- END HELPER FUNCTIONS --------------------------------------------  # ----- END HELPER FUNCTIONS --------------------------------------------
   
 1;  1;
 __END__  __END__
   
   

Removed from v.1.30  
changed lines
  Added in v.1.40


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>