예제 #1
0
 /**
  * Live Scoreboard
  * @param  integer $id Server ID
  * @return array
  */
 public function population()
 {
     // Get active servers only
     $servers = Server::active()->get();
     // Sum the used slots
     $usedSlots = $servers->sum('usedSlots');
     // Sum the max slots
     $totalSlots = $servers->sum('maxSlots');
     // Init array
     $newCollection = [];
     foreach ($servers as $server) {
         // Convert the game name to lowercase
         $gameKey = strtolower($server->game->Name);
         // Add the server to the collection
         $newCollection[$gameKey]['servers'][] = $server;
     }
     foreach ($newCollection as $key => $collection) {
         $online = 0;
         $total = 0;
         foreach ($collection['servers'] as $server) {
             $online += $server->usedSlots;
             $total += $server->maxSlots;
         }
         $newCollection[$key]['stats'] = ['online' => $online, 'totalSlots' => $total, 'percentage' => MainHelper::percent($online, $total)];
     }
     return MainHelper::response(['online' => $usedSlots, 'totalSlots' => $totalSlots, 'percentage' => MainHelper::percent($usedSlots, $totalSlots), 'games' => $newCollection] + Lang::get('dashboard.population'), null, null, null, false, true);
 }