/**
  * Attempts to save new course and redirect to the newly created course.
  */
 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;
     $params['url'] = self::fix_url($params['url']);
     $params['mapLink'] = self::fix_url($params['mapLink']);
     $attributes = array('name' => $params['name'], 'description' => $params['description'], 'address' => $params['address'], 'mapLink' => $params['mapLink'], 'url' => $params['url']);
     $course = new Course($attributes);
     $errors = $course->errors();
     if (count($errors) == 0) {
         $course->save();
         Hole::create_holes($params['holes'], $course->id);
         Moderator::add_as_moderator($course->id, $player->id);
         Redirect::to('/course/' . $course->id . '/edit', array('message' => 'Rata lisätty, täydennä vielä väylien tiedot.'));
     } else {
         View::make('course/new.html', array('errors' => $errors, 'attributes' => $attributes));
     }
 }