/** * Displays a listing of a user's list of all played rounds. * * @param int $id Id of player to be displayed. */ public static function show($id) { $player = Player::find($id); $moderatorOf = Course::find_by_moderator($id); $course = Course::find($player->course); $scores = Score::find_by_player($player->id); foreach ($scores as $score) { $score->round = Round::find($score->roundId); } // $rounds = Round::find_by_player($player->id); // Kint::dump($rounds); View::make('player/show.html', array('player' => $player, 'scores' => $scores, 'moderatorOf' => $moderatorOf, 'course' => $course)); }
/** * Checks if round is ready to be saved. If not, displays round edit page with information already inputted. If yes, attempts to update selected round and related scores. * * @param int $id Id of selected round. */ 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; $players = Player::all(); $course = Course::find($params['course']); $courses = Course::all(); $played = $params['played']; $round = Round::find($id); $holes = Hole::find_by_course($course->id); $scores = Score::find_by_round($id); $numberOfPlayers = sizeof($scores); if ($params['course'] != $params['course_orig']) { // If course selection has changed we need to display edit page again with new information. $playerScores = array(); $numberOfHoles = Hole::count_holes($params['course_orig']); for ($i = 1; $i <= $numberOfPlayers; $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); } View::make('round/edit.html', array('numberOfPlayers' => $numberOfPlayers, 'players' => $players, 'course' => $course, 'holes' => $holes, 'courses' => $courses, 'playerScores' => $playerScores, 'round' => $round, 'scores' => $scores, 'played' => $played)); } else { $attributes = array('courseId' => $params['course'], 'played' => $params['played']); $playerScores = array(); $numberOfHoles = Hole::count_holes($params['course_orig']); $round = new Round(array_merge(array("id" => $round->id), $attributes)); $errors = $round->errors(); if (count($errors) == 0) { $round->update(); for ($i = 1; $i <= $numberOfPlayers; $i++) { $holeScores = array(); $scoreId = $params['score_' . $i]; 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, 'holenumber' => $j); } $score = new Score(array('id' => $scoreId, 'playerId' => $params['player_' . $i], 'roundId' => $round->id, 'scores' => $holeScores)); $score->update(); } Redirect::to('/round/' . $round->id, array('message' => 'Kierrosta muokattu.')); } else { View::make('round/new.html', array('errors' => $errors, 'attributes' => $attributes)); } } }
| | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the Closure to execute when that URI is requested. | */ Route::bind('tournament', function ($key, $route) { $tournament = Tournament::find($key); if ($tournament == null) { App::abort(404); } else { return $tournament; } }); Route::bind('round', function ($key, $route) { $round = Round::find($key); if ($round == null) { App::abort(404); } else { return $round; } }); Route::bind('map', function ($key, $route) { $round = Map::find($key); if ($round == null) { App::abort(404); } else { return $round; } }); Route::bind('scenario', function ($key, $route) {
/** * Deletes orphaned rows from score_hole table. */ public function clean() { $courseId = Round::find($this->roundId)->courseId; $query = DB::connection()->prepare('DELETE FROM score_hole WHERE holeid IN (SELECT sh.holeid FROM score_hole sh JOIN score s ON s.id = sh.scoreid JOIN hole h ON h.id = sh.holeid WHERE s.id = 1 AND NOT h.courseid = :courseid) AND scoreid IN (SELECT sh.scoreid FROM score_hole sh JOIN score s ON s.id = sh.scoreid JOIN hole h ON h.id = sh.holeid WHERE s.id = 1 AND NOT h.courseid = :courseid)'); $query->execute(array('courseid' => $courseId)); }