Diff for /loncom/interface/loncoursedata.pm between versions 1.28 and 1.44

version 1.28, 2002/09/01 06:23:19 version 1.44, 2003/02/05 01:39:32
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 218  sub DownloadCourseInformation { Line 218  sub DownloadCourseInformation {
                                       $courseID.'.db',                                         $courseID.'.db', 
                                       $Apache::lonnet::perlvar{'lonUsersDir'});                                        $Apache::lonnet::perlvar{'lonUsersDir'});
   
     if($lastDownloadTime >= $modifiedTime && $modifiedTime >= 0) {      if($lastDownloadTime ne 'Not downloaded' && 
          $lastDownloadTime >= $modifiedTime && $modifiedTime >= 0) {
         # Data is not gathered so return UpToDate as true.  This          # Data is not gathered so return UpToDate as true.  This
         # will be interpreted in ProcessClasslist          # will be interpreted in ProcessClasslist
         $courseData{$namedata.':lastDownloadTime'}=time;          $courseData{$namedata.':lastDownloadTime'}=time;
Line 310  sub ProcessTopResourceMap { Line 311  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 324  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 489  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 517  sub ProcessTopResourceMap { Line 520  sub ProcessTopResourceMap {
     # big problem, need to handle.  Next is probably wrong      # big problem, need to handle.  Next is probably wrong
             my $errorMessage = 'Big problem in ';              my $errorMessage = 'Big problem in ';
             $errorMessage .= 'loncoursedata::ProcessTopLevelMap.';              $errorMessage .= 'loncoursedata::ProcessTopLevelMap.';
             $errorMessage .= '  bighash to_$currentResourceID not defined!';              $errorMessage .= "  bighash to_$currentResourceID not defined!";
             &Apache::lonnet::logthis($errorMessage);              &Apache::lonnet::logthis($errorMessage);
     last;      if (!defined($currentResourceID)) {last;}
  }   }
  my @nextResources=();   my @nextResources=();
  foreach (split(/\,/,$hash{'to_'.$currentResourceID})) {   foreach (split(/\,/,$hash{'to_'.$currentResourceID})) {
Line 585  browser Line 588  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 628  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 664  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 672  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 737  sub ProcessStudentData { Line 757  sub ProcessStudentData {
     my %courseKeys;      my %courseKeys;
     # user name:domain was prepended earlier in DownloadCourseInformation      # user name:domain was prepended earlier in DownloadCourseInformation
     foreach (keys %$courseData) {      foreach (keys %$courseData) {
  my $currentKey =~ s/^$name//;   my $currentKey = $_;
    $currentKey =~ s/^$name//;
  $courseKeys{$currentKey}++;   $courseKeys{$currentKey}++;
         $cache->{$_}=$courseData->{$_};          $cache->{$_}=$courseData->{$_};
     }      }
Line 1065  sub ProcessFullName { Line 1086  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 1175  sub DownloadStudentCourseData { Line 1181  sub DownloadStudentCourseData {
     my $WhatIWant;      my $WhatIWant;
     $WhatIWant = '(^version:|';      $WhatIWant = '(^version:|';
     $WhatIWant .= '^\d+:.+?:(resource\.\d+\.';      $WhatIWant .= '^\d+:.+?:(resource\.\d+\.';
     $WhatIWant .= '(solved|tries|previous|awarded|(\d+\.submission))\s*$';      $WhatIWant .= '(solved|tries|previous|awarded|(\d+\.submission))\s*$';#'
     $WhatIWant .= '|timestamp)';      $WhatIWant .= '|timestamp)';
     $WhatIWant .= ')';      $WhatIWant .= ')';
 #    $WhatIWant = '.';  #    $WhatIWant = '.';
Line 1249  sub DownloadStudentCourseDataSeparate { Line 1255  sub DownloadStudentCourseDataSeparate {
     $WhatIWant .= '|timestamp)';      $WhatIWant .= '|timestamp)';
     $WhatIWant .= ')';      $WhatIWant .= ')';
   
     &CheckForResidualDownload($courseID, $cacheDB, $students, $c);      &CheckForResidualDownload($cacheDB, 'true', 'true', $courseID, $r, $c);
   
     my $studentCount = scalar(@$students);      my $studentCount = scalar(@$students);
     if($status eq 'true') {      if($status eq 'true') {
Line 1383  sub CheckForResidualDownload { Line 1389  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.28  
changed lines
  Added in v.1.44


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