Esempio n. 1
0
File: Match.php Progetto: 0ida/fussi
 /**
  * @param LeaguePeriod  $period
  * @param League    $tournament
  * @param SingleMatch[] $matches
  * @param Player        $player1
  * @param Player        $player2
  *
  * @return string
  */
 public function __invoke(LeaguePeriod $period, League $tournament, array $matches, Player $player1, Player $player2)
 {
     $allow = $period->inCurrentMonth();
     $out = '';
     if ($player1 != $player2) {
         $ok = false;
         foreach ($matches as $match) {
             $url = $this->getView()->url('match/edit', array('mid' => $match->getId()));
             if ($match->isPlayedBy($player1, $player2)) {
                 $title = $player1->getName() . " vs. " . $player2->getName();
                 $results = array();
                 $counter = 1;
                 foreach ($match->getGames() as $game) {
                     $results[] = "Game " . $counter . ": " . $game->getGoalsTeamOne() . ' / ' . $game->getGoalsTeamTwo();
                     $counter++;
                 }
                 $content = implode("<br>", $results);
                 if ($allow) {
                     $content .= "<br><br><a href='" . $url . "' class='btn btn-small'>Edit</a>";
                 }
                 $out .= '<span title="' . $title . '" data-content="' . $content . '" class="match btn result">';
                 $out .= $match->getScore();
                 $out .= '</span>';
                 $ok = true;
             }
         }
         if (!$ok && $allow) {
             $url = $this->getView()->url('match/new', array('tid' => $tournament->getId(), 'player1' => $player1->getId(), 'player2' => $player2->getId()));
             $out .= '<a href="' . $url . '" class="btn btn-small">Edit</a>';
         }
     }
     return $out;
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 public function __invoke(League $tournament, LeaguePeriod $period)
 {
     $html = '<ul class="pager">';
     $html .= '<li class="previous ' . ($period->hasPrevious() ? '' : 'disabled') . '">';
     $html .= '<a href="' . ($period->hasPrevious() ? $this->getUrl($tournament, $period->getPrevious()) : '#') . '">&larr; Older</a>';
     $html .= '</li>';
     $html .= '<li class="next ' . ($period->inCurrentMonth() ? 'disabled' : '') . '">';
     $html .= '<a href="' . ($period->inCurrentMonth() ? '#' : $this->getUrl($tournament, $period->getNext())) . '">Newer &rarr;</a>';
     $html .= '</li>';
     $html .= '</ul>';
     return $html;
 }
Esempio n. 4
0
 /**
  * Get all players who have played a match (yet) in the tournament
  *
  * @param int          $tournament Tournament Id
  * @param LeaguePeriod $period
  *
  * @return ArrayCollection List of players that have already done a match
  */
 public function getActivePlayers($tournament, $period)
 {
     $query = $this->_em->createQuery('SELECT m FROM Application\\Model\\Entity\\SingleMatch m
         WHERE m.date >= :start AND m.date <= :end
         AND m.tournament = :tournament');
     $query->setParameters(array('start' => $period->getStart()->format('Y-m-d H:i:s'), 'end' => $period->getEnd()->format('Y-m-d H:i:s'), 'tournament' => $tournament));
     $participants = array();
     /** @var $results \Application\Model\Entity\SingleMatch[] */
     $results = $query->getResult();
     foreach ($results as $result) {
         $participants[$result->getPlayer1()->getId()] = $result->getPlayer1();
         $participants[$result->getPlayer2()->getId()] = $result->getPlayer2();
     }
     $participantCollection = new ArrayCollection(array_values($participants));
     return $participantCollection;
 }
Esempio n. 5
0
 public function testGetNext()
 {
     $start = new \DateTime('2013-01-01');
     $period = new LeaguePeriod($start, 2013, 02);
     $this->assertEquals("2013-03-01", $period->getNext()->format('Y-m-d'));
 }