]> git.sesse.net Git - ccbs/blobdiff - html/do-start-round.pl
Make it possible to enter NULL values by leaving fields blank.
[ccbs] / html / do-start-round.pl
index 2e503bbb8f5ca1cb3a20527221d21724633ad951..2637076503eddb76584864307c6f6555323f4a92 100755 (executable)
@@ -49,12 +49,29 @@ for my $p (@$people) {
        }
 }
 
-# Pick random songs for the groups (FIXME: add state to the random generator later)
+# Pick random songs for the groups
 for my $g (1..$num_groups) {
        for my $s (1..$num_random) {
-               my $ref = $dbh->selectrow_hashref('SELECT * FROM songs ORDER BY random() LIMIT 1');
+               my $ref = $dbh->selectrow_hashref('SELECT * FROM machinesongs WHERE song NOT IN ( SELECT song FROM randomsongsused ) AND machine=( SELECT machine FROM tournaments WHERE tournament=? ) ORDER BY random() LIMIT 1',
+                       undef, $tournament);
+               if (!defined($ref)) {
+                       ccbs::user_error('Det er ikke flere sanger igjen i sangvelgeren!');
+               }
+               $dbh->do('INSERT INTO randomsongsused (song) VALUES (?)',
+                       undef, $ref->{'song'});
                $dbh->do('INSERT INTO roundrandomsongs (tournament, round, parallel, song) VALUES (?,?,?,?)',
                        undef, $tournament, $round, $g, $ref->{'song'});
+
+               $dbh->do('INSERT INTO scores SELECT tournament,round,parallel,player,?,?,NULL,NULL,\'f\',NULL FROM roundparticipation WHERE tournament=? AND round=? AND parallel=?', undef,
+                       $s, $ref->{'song'}, $tournament, $round, $g);
+       }
+}
+
+# Add empty "score" records for the chosen songs.
+for my $g (1..$num_groups) {
+       for my $s (1..$num_chosen) {
+               $dbh->do('INSERT INTO scores SELECT tournament,round,parallel,player,?,NULL,NULL,NULL,\'t\',NULL FROM roundparticipation WHERE tournament=? AND round=? AND parallel=?', undef,
+                       $s + $num_random, $tournament, $round, $g);
        }
 }