public static function sandbox()
 {
     // Testaa koodiasi täällä
     $course = new Course(array('name' => '', 'city' => ''));
     $errors = $course->errors();
     Kint::dump($errors);
     $hole = new Hole(array('hole_num' => 'yksi', 'par' => 'kolme'));
     $errors = $hole->errors();
     Kint::dump($errors);
     echo Course::next_courseid();
 }
 public static function update($courseid)
 {
     $params = $_POST;
     $params['courseid'] = $courseid;
     $course_params = array('courseid' => $courseid, 'name' => $params['name'], 'city' => $params['city']);
     $course = new Course($course_params);
     $errors = $course->errors();
     // Check hole validity before saving anything
     $holes = Hole::course_holes($courseid);
     foreach ($holes as $hole) {
         $hole->par = $params['hole' . $hole->hole_num];
         $errors = array_merge($errors, $hole->errors());
     }
     if (count($errors) == 0) {
         // Course and holes were all valid
         $course->update();
         foreach ($holes as $hole) {
             $hole->update();
         }
         Redirect::to('/course/' . $courseid, array('message' => 'Rata ja sen väylät päivitetty.'));
     } else {
         View::make('course/edit.html', array('errors' => $errors, 'attributes' => $params, 'hole_count' => $params['hole_count']));
     }
 }
 /**
  * Attempts to update edited course information and displays the edited course.
  *
  * @param int $id Id of course to be updated.
  */
 public static function update($id)
 {
     $player = self::get_user_logged_in();
     if (!$player) {
         View::make('player/login.html', array('error' => 'Vain kirjautuneet käyttäjät voivat muokata 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'], 'id' => $id);
     $course = new Course($attributes);
     $errors = $course->errors();
     if (count($errors) == 0) {
         $course->update();
         for ($i = 1; $i <= Hole::count_holes($course->id); $i++) {
             $hole = Hole::find_by_course_and_holenumber($course->id, $i);
             $hole->name = $params[$i . '_name'];
             $hole->par = $params[$i . '_par'];
             $hole->update();
         }
         Redirect::to('/course/' . $course->id, array('message' => 'Radan tietoja muutettu.'));
     } else {
         View::make('course/edit.html', array('errors' => $errors, 'attributes' => $attributes));
     }
 }