activelamp/drupal-tourney — pull request #75 by delphian (2014-05-22 22:19:19+00:00)
Title: Programmatic creation of tournaments

Creating tournaments through the UI should still work as normal, but now creating a tournament programmatically works via something like:

$name = 'test tournament';
$games = 3;
$players = 'node.1,node.2,node.3,node.4';
foreach(explode(',', $players) as $player) {
$contestants[$player] = $player;
$seed_positions[$player] = [];
}
$tournament = new TourneyTournamentEntity(['is_new' => TRUE], 'tourney_tournament');
$tournament->contestants = $contestants;
$tournament->format = 'SingleEliminationController';
$tournament->is_new = TRUE;
$tournament->name = $name;
$tournament->label = $name;
$tournament->players = count($contestants);
$tournament->config = [
'match_bundle' => 'match',
'game_bundle' => 'game',
'default_games' => $games,
'truncate' => 12,
'SingleEliminationController' => [
'players' => count($contestants),
'third_place' => 0,
'num_winners' => 1,
'seed_positions' => $seed_positions,
],
];
$tournament->save(FALSE);