Example #1
0
 /**
  * @param League $tournament
  *
  * @return array
  */
 protected function handleLeague(League $tournament)
 {
     $year = $this->params()->fromRoute('year');
     $month = $this->params()->fromRoute('month');
     $leaguePeriod = new LeaguePeriod($tournament->getStart(), $year, $month);
     if ($leaguePeriod->isOutOfBounds()) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $matches = $this->matchRepository->findForPeriod($tournament, $leaguePeriod);
     $players = $tournament->getPlayers();
     $activePlayers = $this->matchRepository->getActivePlayers($tournament, $leaguePeriod);
     if (!$leaguePeriod->inCurrentMonth()) {
         $players = $activePlayers;
     }
     $ranking = new Ranking($matches);
     $infoMaxPoints = (count($players) - 1) * 2;
     $infoMaxMatches = count($players) - 1;
     $tournamentPotential = $ranking->getPotential(count($players) - 1);
     $infoMaxPoints = $infoMaxPoints >= 0 ? $infoMaxPoints : 0;
     $infoMaxMatches = $infoMaxMatches >= 0 ? $infoMaxMatches : 0;
     $viewData = array('period' => $leaguePeriod, 'players' => $players, 'activePlayers' => $activePlayers, 'matches' => $matches, 'ranking' => $ranking, 'tournament' => $tournament, 'infoMaxPoints' => $infoMaxPoints, 'infoMaxMatches' => $infoMaxMatches, 'tournamentPotential' => $tournamentPotential);
     $viewModel = new ViewModel($viewData);
     $viewModel->setTemplate('application/tournament/show-league');
     return $viewModel;
 }
Example #2
0
 public function testAllGamesAreUsedForRankingCalculation()
 {
     $player1 = $this->getPlayer(1);
     $player2 = $this->getPlayer(2);
     $games = array(array(5, 10), array(10, 5), array(10, 5), array(10, 5));
     $match = $this->getMatch($player1, $player2, $games);
     $ranking = new Ranking(array($match));
     $playerRankings = $ranking->getRanking(2);
     $this->assertEquals(1, $playerRankings[0]->getPlayer()->getId());
 }