[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
raeburn
raeburn@source.lon-capa.org
Fri, 27 Mar 2009 02:14:43 -0000
raeburn Fri Mar 27 02:14:43 2009 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
- Add &sorted_slots() to sort slots by start time (earliest first).
- code moved from slotrequest.pm.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.779 loncom/interface/loncommon.pm:1.780
--- loncom/interface/loncommon.pm:1.779 Thu Mar 26 14:59:10 2009
+++ loncom/interface/loncommon.pm Fri Mar 27 02:14:43 2009
@@ -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 @@
the largest default quota which applies to the user determines the
default quota returned.
+=back
+
=cut
###############################################
@@ -7565,8 +7567,57 @@
=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