public function postCreate($tournament)
 {
     if ($tournament->user() != Auth::user()) {
         return Redirect::to('tournaments');
     }
     $round = new Round();
     $round->number = Input::get('number');
     $round->tournament = $tournament->id;
     $round->save();
     App::make('GamesController')->createMultiple($round);
     return Redirect::to('rounds/' . $round->id . '/update');
 }
 /**
  * Checks if round is ready to be saved. If not, displays new round creation page with information already inputted. If yes, attempts to store new round and related scores.
  */
 public static function store()
 {
     $player = self::get_user_logged_in();
     if (!$player) {
         View::make('player/login.html', array('error' => 'Vain kirjautuneet käyttäjät voivat lisätä ratoja.'));
     }
     $params = $_POST;
     if ($params['numberOfPlayers'] != $params['numberOfPlayers_orig'] or $params['course'] != $params['course_orig']) {
         // If course or number of players selection has changed we need to display create page again with new information.
         $playerScores = array();
         $numberOfHoles = Hole::count_holes($params['course_orig']);
         for ($i = 1; $i <= $params['numberOfPlayers_orig']; $i++) {
             $holeScores = array();
             for ($j = 1; $j <= $numberOfHoles; $j++) {
                 $holeScores[] = $params['p' . $i . '_h' . $j];
             }
             $playerScores[] = array('player' => Player::find($params['player_' . $i]), 'holes' => $holeScores);
         }
         $players = Player::all();
         $course = Course::find($params['course']);
         $courses = Course::all();
         $holes = Hole::find_by_course($course->id);
         $played = $params['played'];
         View::make('round/new_continued.html', array('numberOfPlayers' => $params['numberOfPlayers'], 'players' => $players, 'course' => $course, 'holes' => $holes, 'courses' => $courses, 'playerScores' => $playerScores, 'played' => $played));
     } else {
         $attributes = array('courseId' => $params['course'], 'played' => $params['played'], 'addedBy' => self::get_user_logged_in()->id);
         $playerScores = array();
         $numberOfHoles = Hole::count_holes($params['course_orig']);
         $round = new Round($attributes);
         $errors = $round->errors();
         if (count($errors) == 0) {
             $round->save();
             for ($i = 1; $i <= $params['numberOfPlayers_orig']; $i++) {
                 $holeScores = array();
                 for ($j = 1; $j <= $numberOfHoles; $j++) {
                     $hole = Hole::find_by_course_and_holenumber($params['course_orig'], $j);
                     $holeScores[] = array('throws' => $params['p' . $i . '_h' . $j], 'holeId' => $hole->id);
                 }
                 $score = new Score(array('playerId' => $params['player_' . $i], 'roundId' => $round->id, 'scores' => $holeScores));
                 $score->save();
             }
             Redirect::to('/round/' . $round->id, array('message' => 'Kierros lisätty.'));
         } else {
             View::make('round/new.html', array('errors' => $errors, 'attributes' => $attributes));
         }
     }
 }