From 9f5c6162a22670ffd23b71ff28b4600a249d317b Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 16 Dec 2015 18:12:06 +0100 Subject: added musicpools grid handling functions (not yet finished) diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index c5e0a1a..f70a87a 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -1441,13 +1441,85 @@ sub remove_show sub get_musicpools_cart_range { my ($ctx) = @_; - return get_cart_range($ctx, $ctx->{'config'}{'specialgroups'}{'allpools'}) + return get_cart_range($ctx, $ctx->{'config'}{'specialgroups'}{'allpools'}); } sub get_musicpools_next_free_slot { my ($ctx) = @_; - return get_next_free_slot($ctx, $ctx->{'config'}{'specialgroups'}{'allpools'}) + return get_next_free_slot($ctx, $ctx->{'config'}{'specialgroups'}{'allpools'}); +} + +sub is_musicpools_user +{ + my ($ctx, $username) = @_; + + return 0 if $username = ''; + + for my $groupuser (@{$ctx->{'config'}{'specialusers'}{'allpools'}}) { + if ($username eq $groupuser) { + return 1; + } + } + return 0; +} + +sub get_musicpools_clocks +{ + my ($ctx) = @_; + + my @reqs; + for my $day (0 .. 6){ + for my $hour (0 .. 23){ + my $dow = $day + 1; + $dow = 0 if $dow >=7; + push @reqs, 'select ' . $dow . ' as DOW ,' . $hour . ' as HOUR,CLOCK' . (($day*24) + $hour) . + ' as CLOCK from SERVICES where NAME=' . $ctx->{'dbh'}->quote($ctx->{'config'}{'shows'}{'service'}); + } + } + + my $sql = 'select GRID.DOW,GRID.HOUR,CLOCKS.NAME,CLOCKS.SHORT_NAME,CLOCKS.COLOR from CLOCKS,(' . join(' UNION ' , @reqs) . ") as GRID where GRID.CLOCK = CLOCKS.NAME;"; + print $sql; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + my $cnt = $sth->execute() + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my @clocks; + while(my ($dow, $hour, $name, $color) = $sth->fetchrow_array()) { + my $clock = {}; + $clock->{'DOW'} = $dow; + $clock->{'HOUR'} = $hour; + $clock->{'NAME'} = $name; + $clock->{'COLOR'} = $color; + $clock->{'TITLE'} = "unknown title"; # TODO: fetch title from Group Description + push @clocks, $clock; + } + + $sth->finish(); + + return @clocks; +} + +sub set_musicpools_clock +{ + my ($ctx, $dow, $hour, $name) = @_; + + my $day = $dow - 1; + $day = 6 if $dow == 0; + my $idx = (($day*24) + $hour); + + my $sql = 'update SERVICES set CLOCK' . $idx . ' = (select NAME from CLOCKS where SHORT_NAME = ?) where NAME = ?'; # TODO: only set if CLOCKS.NAME is not null + + my $rows = $ctx->{'dbh'}->do($sql, $name, $ctx->{'config'}{'shows'}{'service'}) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + unless($rows == 1) { + return (undef, 'ERROR', "clock does not exist") + } + return (1, 'OK', 'success'); } ########################### JINGLES handling ########################### @@ -1455,13 +1527,13 @@ sub get_musicpools_next_free_slot sub get_jingles_cart_range { my ($ctx) = @_; - return get_cart_range($ctx, $ctx->{'config'}{'specialgroups'}{'alljingles'}) + return get_cart_range($ctx, $ctx->{'config'}{'specialgroups'}{'alljingles'}); } sub get_jingles_next_free_slot { my ($ctx) = @_; - return get_next_free_slot($ctx, $ctx->{'config'}{'specialgroups'}{'alljingles'}) + return get_next_free_slot($ctx, $ctx->{'config'}{'specialgroups'}{'alljingles'}); } ################################# END #################################### diff --git a/test/get-music-clocks b/test/get-music-clocks new file mode 100755 index 0000000..ca0a9f4 --- /dev/null +++ b/test/get-music-clocks @@ -0,0 +1,48 @@ +#!/usr/bin/perl -w +# +# rhrdlibs +# +# Copyright (C) 2015 Christian Pointner +# +# This file is part of rhrdlibs. +# +# rhrdlibs is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# rhrdlibs is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with rhrdlibs. If not, see . +# + +use strict; +use POSIX; +use lib "../lib/"; +use RHRD::rddb; + + +my @clocks = (); +my ($ctx, $status, $errorstring) = RHRD::rddb::init(); +if(defined $ctx) { + @clocks = RHRD::rddb::get_musicpools_clocks($ctx); + if(!defined $clocks[0] && defined $clocks[1]) { + print STDERR "$clocks[1]: $clocks[2]"; + RHRD::rddb::destroy($ctx); + exit 1; + } + RHRD::rddb::destroy($ctx); +} else { + print STDERR "$errorstring\n"; + exit 1; +} + + +print "Clocks:\n"; +for my $href (@clocks) { + print " * " . $href->{'DOW'} . "/" . $href->{'HOUR'} . ": " . $href->{'NAME'} . ", " . $href->{'COLOR'} . "\n"; +} -- cgit v0.10.2