]> git.sesse.net Git - ccbs/blob - html/show-tournament.pl
Add some spacing around the score tables.
[ccbs] / html / show-tournament.pl
1 #! /usr/bin/perl
2
3 use ccbs;
4 use strict;
5 use warnings;
6
7 my $cgi = new CGI;
8 my $id = $cgi->param('id');
9
10 my $dbh = ccbs::db_connect();
11
12 my $tournament = $dbh->selectrow_hashref('SELECT * FROM tournaments WHERE tournament=?', undef, $id);
13
14 # Swoop all the data in in a big join, then order it over to quasi-sane Perl objects.
15 # (round -> parallel -> player -> songs -> title,chosen,score)
16 my $scores = ccbs::db_fetch_all($dbh,
17         'SELECT round,parallel,position,nick,title,chosen,score FROM scores NATURAL JOIN players NATURAL JOIN songs NATURAL JOIN roundparticipation WHERE tournament=? ORDER BY round,parallel,position,songnumber',
18         $id);
19
20 my @rounds = ();
21
22 my ($round, $parallel, $player) = (-1,-1,'');
23 for my $score (@$scores) {
24         if ($score->{'round'} != $round) {
25                 $round = $score->{'round'};
26                 push @rounds, { round => $round, parallels => [] };
27                 $parallel = -1;
28         }
29         my $p = $rounds[$#rounds]->{'parallels'};
30         if ($score->{'parallel'} != $parallel) {
31                 $parallel = $score->{'parallel'};
32                 push @$p, { parallel => $parallel, players => [], songs => [] };
33                 $player = '';
34
35                 # Information on songs is not selected from roundrandomsongs etc.,
36                 # but is filled in the first time the song is seen for this round
37                 # (ie. below)
38         }
39         if ($score->{'position'} == 1) {
40                 if ($score->{'chosen'}) {
41                         push @{$p->[$#$p]->{'songs'}}, '';
42                 } else {
43                         push @{$p->[$#$p]->{'songs'}}, $score->{'title'};
44                 }
45         }
46         
47         my $pl = $p->[$#$p]->{'players'};
48         if ($score->{'nick'} ne $player) {
49                 $player = $score->{'nick'};
50                 push @$pl, { nick => $player, songs => [] };
51
52         }
53         
54         push @{$pl->[$#$pl]->{'songs'}}, {
55                 title => $score->{'title'},
56                 chosen => $score->{'chosen'},
57                 score => $score->{'score'}
58         };
59 }
60
61 ccbs::print_header();
62 ccbs::process_template('show-tournament.tmpl', 'Turnering', { tournament => $tournament, rounds => \@rounds });
63 $dbh->disconnect;