summaryrefslogtreecommitdiff
path: root/lib/RHRD/rddb.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/RHRD/rddb.pm')
-rwxr-xr-xlib/RHRD/rddb.pm61
1 files changed, 60 insertions, 1 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index 6e83a5e..a052080 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -41,6 +41,7 @@ use constant {
RHRD_SHOW_MACROS_GROUP => 'SHOWS',
RHRD_ALLSHOWS_GROUP => 'ALL_SHOWS',
RHRD_ALLMUSICPOOLS_GROUP => 'ALL_POOLS',
+ RHRD_ALLJINGLES_GROUP => 'ALL_JINGLE',
};
########################### connection handling ###########################
@@ -107,6 +108,38 @@ sub get_cart_range
return ($low_cart, $high_cart, $chunk_size);
}
+sub get_next_free_slot
+{
+ my ($dbh, $groupname) = @_;
+
+ my ($group_low_cart, $group_high_cart, $group_chunksize) = get_cart_range($dbh, $groupname);
+
+ my $sql = qq{select NAME, DEFAULT_LOW_CART, DEFAULT_HIGH_CART from GROUPS where NAME != ? and DEFAULT_LOW_CART >= ? and DEFAULT_HIGH_CART <= ? order by DEFAULT_LOW_CART;};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ $sth->execute($groupname, $group_low_cart, $group_high_cart)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my ($low_cart, $high_cart) = ($group_low_cart, $group_low_cart + $group_chunksize - 1);
+ while(my ($slot_name, $slot_low_cart, $slot_high_cart) = $sth->fetchrow_array) {
+ my $slot_chunksize = $slot_high_cart - $slot_low_cart + 1;
+ # print " --> " . $slot_name . ": " . $slot_low_cart . " - " . $slot_high_cart . " (" . $slot_chunksize . ")\n";;
+ if($slot_chunksize != $group_chunksize) {
+ $sth->finish();
+ return (undef, 'ERROR', "show group " . $slot_name . " has wrong chunksize " . $slot_chunksize . " != " . $group_chunksize);
+ }
+
+ if($high_cart < $slot_low_cart) {
+ last; # found a hole...
+ }
+ ($low_cart, $high_cart) = ($slot_high_cart + 1, $slot_high_cart + $group_chunksize);
+ }
+ $sth->finish();
+
+ return ($low_cart, $high_cart);
+}
+
########################### TOKEN handling ###########################
sub get_token
@@ -635,12 +668,38 @@ sub get_shows_cart_range
return get_cart_range($dbh, RHRD_ALLSHOWS_GROUP)
}
+sub get_shows_next_free_slot
+{
+ my ($dbh) = @_;
+ return get_next_free_slot($dbh, RHRD_ALLSHOWS_GROUP)
+}
+
########################### MUSICPOOL handling ###########################
-sub get_musicpool_cart_range
+sub get_musicpools_cart_range
{
my ($dbh) = @_;
return get_cart_range($dbh, RHRD_ALLMUSICPOOLS_GROUP)
}
+sub get_musicpools_next_free_slot
+{
+ my ($dbh) = @_;
+ return get_next_free_slot($dbh, RHRD_ALLMUSICPOOLS_GROUP)
+}
+
+########################### JINGLES handling ###########################
+
+sub get_jingles_cart_range
+{
+ my ($dbh) = @_;
+ return get_cart_range($dbh, RHRD_ALLJINGLES_GROUP)
+}
+
+sub get_jingles_next_free_slot
+{
+ my ($dbh) = @_;
+ return get_next_free_slot($dbh, RHRD_ALLJINGLES_GROUP)
+}
+
################################# END ####################################