Diff for /loncom/interface/loncommon.pm between versions 1.1039 and 1.1040

version 1.1039, 2011/12/19 18:18:28 version 1.1040, 2011/12/20 22:43:34
Line 8448  sub get_standard_codeitems { Line 8448  sub get_standard_codeitems {
   
 =item * sorted_slots()  =item * sorted_slots()
   
 Sorts an array of slot names in order of slot start time (earliest first).   Sorts an array of slot names in order of an optional sort key,
   default sort is by slot start time (earliest first). 
   
 Inputs:  Inputs:
   
Line 8458  slotsarr  - Reference to array of unsort Line 8459  slotsarr  - Reference to array of unsort
   
 slots     - Reference to hash of hash, where outer hash keys are slot names.  slots     - Reference to hash of hash, where outer hash keys are slot names.
   
   sortkey   - Name of key in inner hash to be sorted on (e.g., starttime).
   
 =back  =back
   
 Returns:  Returns:
   
 =over 4  =over 4
   
 sorted   - An array of slot names sorted by the start time of the slot.  sorted   - An array of slot names sorted by a specified sort key 
              (default sort key is start time of the slot).
 =back  
   
 =back  =back
   
Line 8474  sorted   - An array of slot names sorted Line 8476  sorted   - An array of slot names sorted
   
   
 sub sorted_slots {  sub sorted_slots {
     my ($slotsarr,$slots) = @_;      my ($slotsarr,$slots,$sortkey) = @_;
       if ($sortkey eq '') {
           $sortkey = 'starttime';
       }
     my @sorted;      my @sorted;
     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {      if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
         @sorted =          @sorted =
             sort {              sort {
                      if (ref($slots->{$a}) && ref($slots->{$b})) {                       if (ref($slots->{$a}) && ref($slots->{$b})) {
                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}                           return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
                      }                       }
                      if (ref($slots->{$a})) { return -1;}                       if (ref($slots->{$a})) { return -1;}
                      if (ref($slots->{$b})) { return 1;}                       if (ref($slots->{$b})) { return 1;}
Line 8490  sub sorted_slots { Line 8495  sub sorted_slots {
     return @sorted;      return @sorted;
 }  }
   
   =pod
   
   =item * get_future_slots()
   
   Inputs:
   
   =over 4
   
   cnum - course number
   
   cdom - course domain
   
   now - current UNIX time
   
   symb - optional symb
   
   =back
   
   Returns:
   
   =over 4
   
   sorted_reservable - ref to array of student_schedulable slots currently 
                       reservable, ordered by end date of reservation period.
   
   reservable_now - ref to hash of student_schedulable slots currently
                    reservable.
   
       Keys in inner hash are:
       (a) symb: either blank or symb to which slot use is restricted.
       (b) endreserve: end date of reservation period. 
   
   sorted_future - ref to array of student_schedulable slots reservable in
                   the future, ordered by start date of reservation period.
   
   future_reservable - ref to hash of student_schedulable slots reservable
                       in the future.
   
       Keys in inner hash are:
       (a) symb: either blank or symb to which slot use is restricted.
       (b) startreserve:  start date of reservation period.
   
   =back
   
   =cut
   
   sub get_future_slots {
       my ($cnum,$cdom,$now,$symb) = @_;
       my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
       my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
       foreach my $slot (keys(%slots)) {
           next unless($slots{$slot}->{'type'} eq 'schedulable_student');
           if ($symb) {
               next if (($slots{$slot}->{'symb'} ne '') && 
                        ($slots{$slot}->{'symb'} ne $symb));
           }
           if (($slots{$slot}->{'starttime'} > $now) &&
               ($slots{$slot}->{'endtime'} > $now)) {
               if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
                   my $userallowed = 0;
                   if ($slots{$slot}->{'allowedsections'}) {
                       my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
                       if (!defined($env{'request.role.sec'})
                           && grep(/^No section assigned$/,@allowed_sec)) {
                           $userallowed=1;
                       } else {
                           if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
                               $userallowed=1;
                           }
                       }
                       unless ($userallowed) {
                           if (defined($env{'request.course.groups'})) {
                               my @groups = split(/:/,$env{'request.course.groups'});
                               foreach my $group (@groups) {
                                   if (grep(/^\Q$group\E$/,@allowed_sec)) {
                                       $userallowed=1;
                                       last;
                                   }
                               }
                           }
                       }
                   }
                   if ($slots{$slot}->{'allowedusers'}) {
                       my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
                       my $user = $env{'user.name'}.':'.$env{'user.domain'};
                       if (grep(/^\Q$user\E$/,@allowed_users)) {
                           $userallowed = 1;
                       }
                   }
                   next unless($userallowed);
               }
               my $startreserve = $slots{$slot}->{'startreserve'};
               my $endreserve = $slots{$slot}->{'endreserve'};
               my $symb = $slots{$slot}->{'symb'};
               if (($startreserve < $now) &&
                   (!$endreserve || $endreserve > $now)) {
                   my $lastres = $endreserve;
                   if (!$lastres) {
                       $lastres = $slots{$slot}->{'starttime'};
                   }
                   $reservable_now{$slot} = {
                                              symb       => $symb,
                                              endreserve => $lastres
                                            };
               } elsif (($startreserve > $now) &&
                        (!$endreserve || $endreserve > $startreserve)) {
                   $future_reservable{$slot} = {
                                                 symb         => $symb,
                                                 startreserve => $startreserve
                                               };
               }
           }
       }
       my @unsorted_reservable = keys(%reservable_now);
       if (@unsorted_reservable > 0) {
           @sorted_reservable = 
               &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
       }
       my @unsorted_future = keys(%future_reservable);
       if (@unsorted_future > 0) {
           @sorted_future =
               &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
       }
       return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
   }
   
 =pod  =pod
   

Removed from v.1.1039  
changed lines
  Added in v.1.1040


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