public static function stats() { $player = self::get_user_logged_in(); $url = $_SERVER['REQUEST_URI']; $stripped_url = preg_replace("/[^A-Za-z0-9 ]/", '', $url); if ($player) { $stripped_url .= $player->playerid; } // Fetch page from cache $cached_page = Cache::getPage($stripped_url); if ($cached_page != null && Cache::on()) { // Use cached page (which is up to date because outdated pages are deleted) echo $cached_page; } else { // Make page from scratch $high_scores = null; if ($player) { $high_scores = Game::player_high_scores($player->playerid); } $game_count = Game::count_all(); $throw_count = Score::count_all(); $latest_game = Game::latest_game(); $popular_courses = Course::popular_courses_all_players(); $page_html = View::make("stats/stats.html", array('game_count' => $game_count, 'throw_count' => $throw_count, 'latest_game' => $latest_game, 'popular_courses' => $popular_courses, 'player' => $player, 'high_scores' => $high_scores)); if (Cache::on()) { // Don't include the page message in the cached file $page_html = Cache::strip_tags_content($page_html, "message-success"); Cache::store($stripped_url, $page_html); } } }
public static function stats() { $game_count = Game::count_all(); $throw_count = Score::count_all(); $latest_game = Game::latest_game(); $player_game_count = null; $player_throw_count = null; $player_latest_game = null; $high_scores = null; if (isset($_SESSION['user'])) { $playerid = $_SESSION['user']; $player_game_count = Game::count_all_player_games($playerid); $player_throw_count = Score::count_all_player_scores($playerid); $player_latest_game = Game::latest_player_game($playerid); $high_scores = Game::player_high_scores($playerid); } View::make("stats/stats.html", array('game_count' => $game_count, 'throw_count' => $throw_count, 'latest_game' => $latest_game, 'player_game_count' => $player_game_count, 'player_throw_count' => $player_throw_count, 'player_latest_game' => $player_latest_game, 'high_scores' => $high_scores)); }
public static function index() { $page = isset($_GET['page']) && $_GET['page'] ? $_GET['page'] : 1; $page_size = 10; $games = array(); $playerid = null; $courseid = null; $url = $_SERVER['REQUEST_URI']; $stripped_url = preg_replace("/[^A-Za-z0-9 ]/", '', $url); // Fetch page from cache $cached_page = Cache::getPage($stripped_url); if ($cached_page != null && Cache::on()) { // Use cached page (which is up to date because outdated pages are deleted) echo $cached_page; } else { if (Game::count_all() > 0) { // Make page from scratch $game_years = Game::game_years(); if (isset($_GET['year'])) { $year = $_GET['year']; } else { $year = $game_years[count($game_years) - 1]; } // GET-parameters determine what games are shown: if (isset($_GET['player']) && isset($_GET['course'])) { // Show this player's games on this course $playerid = $_GET['player']; $courseid = $_GET['course']; $games_count = Game::count_all_player_games_on_course($playerid, $courseid, $year); $games = Game::all(array('page' => $page, 'page_size' => $page_size, 'playerid' => $playerid, 'courseid' => $courseid, 'year' => $year)); } else { if (isset($_GET['player'])) { // Show this player's games $playerid = $_GET['player']; $games_count = Game::count_all_player_games_by_year($playerid, $year); $games = Game::all(array('page' => $page, 'page_size' => $page_size, 'playerid' => $playerid, 'year' => $year)); } else { if (isset($_GET['course'])) { // Show games on this course $courseid = $_GET['course']; $games_count = Game::count_all_course_games_by_year($courseid, $year); $games = Game::all(array('page' => $page, 'page_size' => $page_size, 'courseid' => $courseid, 'year' => $year)); } else { // Show all games $games_count = Game::count_all_by_year($year); $games = Game::all(array('page' => $page, 'page_size' => $page_size, 'year' => $year)); } } } $pages = ceil($games_count / $page_size); if ($page > 1) { $prev_page = (int) $page - 1; } else { $prev_page = null; } if ($pages > $page) { $next_page = (int) $page + 1; } else { $next_page = null; } $page_html = View::make('game/index.html', array('games' => $games, 'prev_page' => $prev_page, 'curr_page' => $page, 'next_page' => $next_page, 'pages' => $pages, 'courses' => Course::all(), 'courses_order_by_id' => Course::all_order_by_id(), 'players' => Player::all(), 'playerid_param' => $playerid, 'courseid_param' => $courseid, 'game_years' => $game_years, 'current_year' => $year)); if (Cache::on()) { // Don't include the page message in the cached file $page_html = Cache::strip_tags_content($page_html, "message-success"); Cache::store($stripped_url, $page_html); } } else { // No games in the database View::make('game/index.html', array('courses' => Course::all(), 'players' => Player::all())); } } }