8 my $id = $cgi->param('id');
10 my $dbh = ccbs::db_connect();
12 my $tournament = $dbh->selectrow_hashref('SELECT * FROM tournaments WHERE tournament=?', undef, $id);
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,nick,title,chosen,score FROM scores NATURAL JOIN players NATURAL JOIN songs NATURAL JOIN roundparticipation WHERE tournament=? ORDER BY round,parallel,position,songnumber',
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 => [] };
29 my $p = $rounds[$#rounds]->{'parallels'};
30 if ($score->{'parallel'} != $parallel) {
31 $parallel = $score->{'parallel'};
32 push @$p, { parallel => $parallel, players => [] };
35 my $pl = $p->[$#$p]->{'players'};
36 if ($score->{'nick'} ne $player) {
37 $player = $score->{'nick'};
38 push @$pl, { nick => $player, songs => [] };
41 push @{$pl->[$#$pl]->{'songs'}}, {
42 title => $score->{'title'},
43 chosen => $score->{'chosen'},
44 score => $score->{'score'}
49 ccbs::process_template('show-tournament.tmpl', 'Turnering', { tournament => $tournament, rounds => \@rounds });