--- loncom/interface/loncommon.pm 2009/03/26 14:59:10 1.779 +++ loncom/interface/loncommon.pm 2009/03/27 02:14:43 1.780 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.779 2009/03/26 14:59:10 bisitz Exp $ +# $Id: loncommon.pm,v 1.780 2009/03/27 02:14:43 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -7017,6 +7017,8 @@ If the user's status includes multiple t the largest default quota which applies to the user determines the default quota returned. +=back + =cut ############################################### @@ -7565,8 +7567,57 @@ sub get_institutional_codes { =pod +=head1 Slot Helpers + +=over 4 + +=item * sorted_slots() + +Sorts an array of slot names in order of slot start time (earliest first). + +Inputs: + +=over 4 + +slotsarr - Reference to array of unsorted slot names. + +slots - Reference to hash of hash, where outer hash keys are slot names. + =back +Returns: + +=over 4 + +sorted - An array of slot names sorted by the start time of the slot. + +=back + +=back + +=cut + + +sub sorted_slots { + my ($slotsarr,$slots) = @_; + my @sorted; + if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) { + @sorted = + sort { + if (ref($slots->{$a}) && ref($slots->{$b})) { + return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'} + } + if (ref($slots->{$a})) { return -1;} + if (ref($slots->{$b})) { return 1;} + return 0; + } @{$slotsarr}; + } + return @sorted; +} + + +=pod + =head1 HTTP Helpers =over 4