Exemple #1
0
     foreach ($stationRounds as $sr) {
         $teamsAdded[] = $sr->team->id;
     }
     foreach ($teams as $team) {
         if (!in_array($team->id, $teamsAdded)) {
             $teamslist[$team->id] = $team->name;
         }
     }
     if (empty($teamslist)) {
         return Redirect::to($slug);
     }
     return View::make('round.new', array('station' => $station, 'teams' => $teamslist));
 });
 // POST Create round for a team and station
 Route::post('(:any)/nyttlag', function ($slug) {
     Round::create(Input::all());
     return Redirect::to($slug);
 });
 // GET Form for editing a round
 Route::get('(:any)/(:num)', function ($slug, $team_id) {
     $station_id = Station::where('slug', '=', $slug)->only('id');
     $round = Round::where_team_id_and_station_id($team_id, $station_id)->first();
     return View::make('round.edit', array('round' => $round, 'station' => $round->station, 'team' => $round->team));
 });
 // GET Form for editing a round
 Route::put('(:any)/(:num)', function ($slug, $team_id) {
     $id = Round::where_station_id_and_team_id(Input::get('station_id'), Input::get('team_id'))->only('id');
     Round::update($id, Input::all());
     return Redirect::to($slug);
 });
 // GET One station
Exemple #2
0
 /**
  * buildBracket 
  * Create the bracket for the tournament.
  * This will add and associate all other fields / tables
  * 
  */
 public function buildBracket()
 {
     /*
     	Calculate the number of matches for the first round.
     	All we need is the first round, every round after that is half the amount of matches as the previous. (for single elim)
     */
     $matchesThisRound = $this->firstRoundMatches();
     $teams = $this->bracket->teams;
     // We're building a new bracket.
     // Let's delete the existing rounds and matches.
     // This will also remove matches and relationship through foreign key cascades.
     $this->bracket->rounds()->delete();
     // assign matches for all rounds.
     for ($r = 1; $r <= $this->getRoundCount(); $r++) {
         // INSERT the round data into the database and associate it with the bracket.
         $round = Round::create(array('name' => $this->getRoundName($r), 'index' => $r));
         // associate the new round with the existing bracket.
         $this->bracket->rounds()->insert($round);
         // If this is the first round let's make it the "current_round", in the bracket table.
         if ($r === 1) {
             $this->bracket->current_round = $round->id;
             $this->bracket->save();
         }
         for ($i = 0; $i < $matchesThisRound; $i++) {
             // Create the match.
             $match = Match::create(array('status' => $r === 1 ? 'Ready to play' : 'Waiting for team assignment'));
             // Associate the new match with the round.
             $round->matches()->insert($match);
             // Also associate the match with the current bracket.
             $this->bracket->matches()->attach($match);
             // If this is the first round then we can assign teams to the match.
             if ($r === 1) {
                 // Add two teams to the match.
                 for ($c = 0; $c < 2; $c++) {
                     if (current($teams)) {
                         $match->teams()->attach(current($teams));
                         next($teams);
                     }
                 }
             }
         }
         $matchesThisRound = $matchesThisRound / 2;
         //  Half the people lost...
     }
     return count($this->bracket->matches);
 }