Example #1
0
 public function getGame($instanceId, $all = false)
 {
     try {
         $game = Game::with(['comments.player' => function ($query) use($instanceId) {
             $query->where('game_id', $instanceId);
         }, 'players.gameChar', 'players.account.destiny', 'comments.account'])->where('instanceId', $instanceId)->firstOrFail();
         // cache of hashes
         Hashes::cacheSingleGameHashes($game);
         $gts = '';
         $revives = false;
         $game->players->each(function ($player) use(&$gts, &$revives) {
             $player->kd = $player->kdr();
             $gts .= $player->account->gamertag . ", ";
             if ($player->revives_given != 0) {
                 $revives = true;
             }
         });
         // shared views
         \View::share('game', $game);
         \View::share('showAll', boolval($all));
         \View::share('description', $game->type()->title . " with players: " . rtrim($gts, ", "));
         \View::share('title', 'PandaLove: ' . $game->type()->title);
         \View::share('revives', $revives);
         if ($game->type == "PVP") {
             // This is a f*****g mess, but we don't have KD in the table so can't leverage the DB
             // We append score (1501) to KD (multiplied by 100 to remove decimal)
             // Thus 1501 w/ KD of .44 becomes 1501.00000044 (padded 8 times)
             $game->players = $game->players->sortBy(function ($player) {
                 return sprintf('%08d.%08d', $player->getOriginal('score'), $player->kd * 100);
             }, SORT_REGULAR, true);
             return view('destiny.games.pvp');
         } else {
             $game->players = $game->players->sortByDesc('kd');
             return view('destiny.games.game');
         }
     } catch (ModelNotFoundException $e) {
         \App::abort(404);
     }
 }